From 3422c5e93138f0e1df3fa9cd036da6f0ece0fde1 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Mon, 21 Mar 2022 01:10:17 +0100 Subject: [PATCH] Alcune pesanti correzioni ai meccanismi di download e alla raccolta dei tarball. --- loaih/__init__.py | 79 +++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/loaih/__init__.py b/loaih/__init__.py index 2c1c1f2..be281dc 100644 --- a/loaih/__init__.py +++ b/loaih/__init__.py @@ -13,7 +13,7 @@ class Build(object): """Build all versions that can be found in the indicated repo.""" self.query = query self.arch = arch - self.url = '' + self.url = {} self.language = 'basic' self.offline_help = False self.portable = False @@ -25,6 +25,14 @@ class Build(object): # Getting versions and so on v = versions.BuildVersion(self.query) + # Creating a tempfile + self.builddir = tempfile.mkdtemp() + self.tarballs = {} + self.appname = 'LibreOffice' if not self.query == 'daily' else 'LibreOfficeDev' + self.version = v.version + self.url = v.basedirurl + self.built = False + # Building expected AppImageName languagepart = "." if ',' in self.language: @@ -32,24 +40,19 @@ class Build(object): else: languagepart += self.language - self.appimagefilename[u'x86'] = ('LibreOffice' if not self.query == 'daily' else 'LibreOfficeDev') + '-' + v.version + languagepart + ('.help' if self.offline_help else '') + '-x86.AppImage' - self.appimagefilename[u'x86_64'] = ('LibreOffice' if not self.query == 'daily' else 'LibreOfficeDev') + '-' + v.version + languagepart + ('.help' if self.offline_help else '') + '-x86_64.AppImage' + self.appimagefilename[u'x86'] = self.appname + '-' + self.version + languagepart + ('.help' if self.offline_help else '') + '-x86.AppImage' + self.appimagefilename[u'x86_64'] = self.appname + '-' + v.version + languagepart + ('.help' if self.offline_help else '') + '-x86_64.AppImage' - # Creating a tempfile - self.builddir = tempfile.mkdtemp() - self.tarballs = [] - self.appname = 'LibreOffice' if not self.query == 'daily' else 'LibreOfficeDev' - self.version = v.version - self.url = v.basedirurl - self.built = False def check(self, storage_path): """Checking if the requested AppImage has been already built.""" self.storage_path = storage_path + ('/portable' if self.portable else '') for arch in self.arch: - print("DEBUG: {appimage}".format(appimage = self.appimagefilename[arch])) - res = subprocess.check_output("find {path} -name '{appimage}'".format(path = self.storage_path, appimage = self.appimagefilename[arch] + ('.zsync' if self.updatable else '')), shell=True).decode('utf-8').strip('\n') + res = subprocess.check_output("find {path} -name '{appimage}'".format( + path = self.storage_path, + appimage = self.appimagefilename[arch] + ('.zsync' if self.updatable else '') + ), shell=True).decode('utf-8').strip('\n') if len(res) > 1: self.built = True @@ -65,25 +68,28 @@ class Build(object): # Let's explore the remote folder. self.download_path = download_path - for a in self.arch: - contents = etree.HTML(urllib.request.urlopen(self.url[a]).read()).xpath("//td/a") - self.tarballs = [ x.text for x in contents if x.text.endswith('tar.gz') ] - maintarball = self.tarballs[0] - mainarr = maintarball.split('') - self.appname = mainarr[0] - self.version = mainarr[1] + for arch in self.arch: + # Checking if a valid path has been provided + if self.url[arch] == '-': + print("No build has been provided for the requested AppImage for {arch}. Continue with other options.".format(arch = arch)) + continue - os.makedirs(self.downloaddir, existok = True) - os.chdir(self.downloaddir) - for archive in self.tarballs: + contents = etree.HTML(urllib.request.urlopen(self.url[arch]).read()).xpath("//td/a") + self.tarballs[arch] = [ x.text for x in contents if x.text.endswith('tar.gz') ] + tarballs = self.tarballs[arch] + maintarball = tarballs[0] + + os.makedirs(self.download_path, existok = True) + os.chdir(self.download_path) + for archive in tarballs: # If the archive is already there, do not do anything. - if os.path.exists(os.path.join(self.downloaddir, archive)): + if os.path.exists(os.path.join(self.download_path, archive)): print("Archive %s is already there! Sweet" % archive) continue # Download the archive try: - urllib.request.urlretrieve(self.url + archive, archive) + urllib.request.urlretrieve(self.url[arch] + archive, archive) except: print("Failed to download {archive}.".format(archive = archive)) @@ -110,6 +116,11 @@ class Build(object): self.updatable = False for arch in self.arch: + # Checking if a valid path has been provided + if self.url[arch] == '-': + # User has been warned in download step. + continue + # Preparation tasks self.appnamedir = os.path.join(self.builddir, self.appname) self.appimagedir = os.path.join(self.builddir, self.appname, self.appname + '.AppDir') @@ -122,31 +133,31 @@ class Build(object): os.chmod('appimagetool', 0o755) # Build the requested version. - self.__unpackbuild__() + self.__unpackbuild__(arch) - def __unpackbuild__(self): + def __unpackbuild__(self, arch): # We start by filtering out tarballs from the list - buildtarballs = [ self.__tarballs__[0] ] + buildtarballs = [ self.tarballs[arch][0] ] # Let's process standard languages and append results to the # buildtarball if self.language == 'basic': - buildtarballs.extend([ x for x in self.tarballs if 'langpack_en-GB' in x]) + buildtarballs.extend([ x for x in self.tarballs[arch] if 'langpack_en-GB' in x]) if self.offline_help: - buildtarballs.extend([ x for x in self.tarballs if 'helppack_en-GB' in x ]) + buildtarballs.extend([ x for x in self.tarballs[arch] if 'helppack_en-GB' in x ]) if self.language == 'standard': for lang in Build.LANGSTD: - buildtarballs.extend([ x for x in self.tarballs if ('langpack' + lang) in x ]) + buildtarballs.extend([ x for x in self.tarballs[arch] if ('langpack' + lang) in x ]) if self.offlinehelp: - buildtarballs.extend([ x for x in self.tarballs if ('helppack' + lang) in x ]) + buildtarballs.extend([ x for x in self.tarballs[arch] if ('helppack' + lang) in x ]) else: # In any other cases, we build with all languages if not self.offlinehelp: - buildtarballs.extend([ x for x in self.tarballs if 'langpack' in x ]) + buildtarballs.extend([ x for x in self.tarballs[arch] if 'langpack' in x ]) else: # We need also all help. Let's replace buildtarball with the # whole bunch - buildtarballs = self.tarballs + buildtarballs = self.tarballs[arch] # Unpacking the tarballs for archive in buildtarballs: @@ -177,7 +188,7 @@ class Build(object): os.chmod(dest, 0o755) # Setting app version - appversion = self.version + '.' + self.language if not ',' in self.language else self.language.replace(',', '-') + appversion = self.version + '.' + (self.language if not ',' in self.language else self.language.replace(',', '-')) if self.offline_help: appversion += '.help'