From 8d8f2b6dc446d1e5c1e646f08d10080c53b4f188 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Wed, 30 Mar 2022 00:07:43 +0200 Subject: [PATCH] Alcuni miglioramenti di ricerca delle build in path specifici. --- loaih/__init__.py | 92 +++++++++++++++++++++++++++++++-------------- scripts/loaih-build | 2 +- setup.py | 2 +- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/loaih/__init__.py b/loaih/__init__.py index fbcfdf0..55566b9 100644 --- a/loaih/__init__.py +++ b/loaih/__init__.py @@ -3,7 +3,7 @@ import urllib.request import loaih.versions as versions from lxml import etree -import tempfile, os, sys, glob, subprocess, shutil +import tempfile, os, sys, glob, subprocess, shutil, re class Build(object): LANGSTD = [ 'ar', 'de', 'en-GB', 'es', 'fr', 'it', 'ja', 'ko', 'pt', 'pt-BR', 'ru', 'zh-CN', 'zh-TW' ] @@ -35,14 +35,21 @@ class Build(object): self.appname = 'LibreOffice' if not self.query == 'daily' and not self.query == 'prerelease' else 'LibreOfficeDev' self.version = v.version self.url = v.basedirurl - self.built = False + self.built = { u'x86': False, u'x86_64': False } + + # Preparing the default for the relative path on the storage for + # different versions. + # The path will evaluated as part of the check() function, as it is + # understood the storage_path can be changed before that phase. + self.relative_path = [] + self.full_path = '' def check(self, storage_path): """Checking if the requested AppImage has been already built.""" - self.storage_path = storage_path - self.storage_path += ('/daily' if self.query == 'daily' else '') - self.storage_path += ('/prerelease' if self.query == 'prerelease' else '') - self.storage_path += ('/portable' if self.portable else '') + # Mandate to the private function to calculate the full_path available + # for the storage and the checks. + self.__calculate_full_path__() + # Incompatibilities - if portable and updatable are asked together, # only portable will be built. if self.portable and self.updatable: @@ -78,32 +85,53 @@ class Build(object): # and it contains the specific version found. print("Debug: searching for {file}".format(file = self.genappimagefilename[arch] + '.ver')) res = subprocess.run("find {path} -name {appimage}'".format( - path = self.storage_path, + path = self.full_path, appimage = self.genappimagefilename[arch] + '.ver' - ), shell=True, capture_output=True) + ), shell=True, capture_output=True, env={ "LC_ALL": "C" }) + + if "No such file or directory" in res.stderr.decode('utf-8'): + # Folder is not existent: so the version was not built + # Build stays false, and we go to the next arch + continue + if res.stdout: # All good, the command was executed fine. for file in res.stdout.decode('utf-8').strip('\n').split('\n'): if self.version in open(file, 'r').read(): - self.built = True + self.built[arch] = True print("Debug: searching for {file}".format(file = self.appimagefilename[arch])) res = subprocess.run("find {path} -name '{appimage}'".format( - path = self.storage_path, + path = self.full_path, appimage = self.appimagefilename[arch] ), shell=True, capture_output=True) if res.stdout: if len(res.stdout.decode('utf-8').strip('\n')) > 1: - self.built = True + self.built[arch] = True - if self.built: - print("The requested AppImage already exists on storage. I'll skip downloading, building and moving the results.") + if self.built[arch]: + print("The requested AppImage already exists on storage for {arch}. I'll skip downloading, building and moving the results.".format(arch=arch)) + + def __calculate_full_path__(self): + """Calculate relative path of the build, based on internal other variables.""" + if len(self.relative_path) == 0: + if self.query == 'daily': + self.relative_path.append('daily') + elif self.query == 'prerelease': + self.relative_path.append('prerelease') + + # Not the same check, an additional one + if self.portable: + self.relative_path.append('portable') + + fullpath_arr = self.storage_path.split('/') + # Joining relative path only if it is not null + if len(self.relative_path) > 0: + fullpath_arr.expand(self.relative_path) + self.full_path = re.sub(r"/+", '/', str.join('/', fullpath_arr)) def download(self, download_path): """Downloads the contents of the URL as it was a folder.""" - if self.built: - return - # Let's start with defining which files are to be downloaded. # Let's explore the remote folder. self.download_path = download_path @@ -112,6 +140,12 @@ class Build(object): # 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)) + # Faking already built it so to skip other checks. + self.built[arch] = True + continue + + if self.built[arch]: + print("A build for {arch} was already found. Skipping specific packages.".format(arch = arch)) continue contents = etree.HTML(urllib.request.urlopen(self.url[arch]).read()).xpath("//td/a") @@ -137,22 +171,15 @@ class Build(object): def build(self): """Building all the versions.""" - if self.built: - return - # We have 4 builds to do: # * standard languages, no help # * standard languages + offline help # * all languages, no help # * all languages + offline help - if self.portable and not 'portable' in self.storage_path: - self.storage_path += "/portable" - for arch in self.arch: - # Checking if a valid path has been provided - if self.url[arch] == '-': - # User has been warned in download step. + if self.built[arch]: + # Already built for arch or path not available. User has already been warned. continue # Preparation tasks @@ -261,9 +288,13 @@ class Build(object): def checksums(self): """Create checksums of the built versions.""" - if self.built: + if all(self.built.values()): + # All checksums are already created. return + # On the contrary, checksums will be in any case overwritten if + # existent, but generated only for built packages anyways + os.chdir(self.appnamedir) for appimage in glob.glob('*.AppImage*'): # See if a checksum already exist @@ -271,13 +302,16 @@ class Build(object): subprocess.run("md5sum {appimage} > {appimage}.md5".format(appimage = appimage), shell=True) - def move(self): + def publish(self): """Moves built versions to definitive storage.""" - if self.built: + if all(self.built.values()): + # All files are already present in the full_path return os.chdir(self.appnamedir) - subprocess.run("find . -iname '*.AppImage*' -exec cp -f {} %s \;" % self.storage_path, shell=True) + # Forcing creation of subfolders, in case there is a new build + os.makedirs(self.full_path, exist_ok = True) + subprocess.run("find . -iname '*.AppImage*' -exec cp -f {} %s \;" % self.full_path, shell=True) def __del__(self): """Destructor""" diff --git a/scripts/loaih-build b/scripts/loaih-build index 111e64f..69158c9 100644 --- a/scripts/loaih-build +++ b/scripts/loaih-build @@ -37,7 +37,7 @@ def build(arch, language, offline, portable, updatable, download, storage, check obj.download(download) obj.build() obj.checksums() - obj.move() + obj.publish() del obj if __name__ == '__main__': diff --git a/setup.py b/setup.py index 0f9a07d..032157f 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup,find_packages setup( name="loaih", - version="1.0.0", + version="1.0.1", description="LOAIH - LibreOffice AppImage Helpers, help build a LibreOffice AppImage", author="Emiliano Vavassori", author_email="syntaxerrormmm@libreoffice.org",