1
0
Fork 0

Alcuni miglioramenti di ricerca delle build in path specifici.

This commit is contained in:
Emiliano Vavassori 2022-03-30 00:07:43 +02:00
parent 6fe41c6e76
commit 8d8f2b6dc4
3 changed files with 65 additions and 31 deletions

View File

@ -3,7 +3,7 @@
import urllib.request import urllib.request
import loaih.versions as versions import loaih.versions as versions
from lxml import etree from lxml import etree
import tempfile, os, sys, glob, subprocess, shutil import tempfile, os, sys, glob, subprocess, shutil, re
class Build(object): class Build(object):
LANGSTD = [ 'ar', 'de', 'en-GB', 'es', 'fr', 'it', 'ja', 'ko', 'pt', 'pt-BR', 'ru', 'zh-CN', 'zh-TW' ] 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.appname = 'LibreOffice' if not self.query == 'daily' and not self.query == 'prerelease' else 'LibreOfficeDev'
self.version = v.version self.version = v.version
self.url = v.basedirurl 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): def check(self, storage_path):
"""Checking if the requested AppImage has been already built.""" """Checking if the requested AppImage has been already built."""
self.storage_path = storage_path # Mandate to the private function to calculate the full_path available
self.storage_path += ('/daily' if self.query == 'daily' else '') # for the storage and the checks.
self.storage_path += ('/prerelease' if self.query == 'prerelease' else '') self.__calculate_full_path__()
self.storage_path += ('/portable' if self.portable else '')
# Incompatibilities - if portable and updatable are asked together, # Incompatibilities - if portable and updatable are asked together,
# only portable will be built. # only portable will be built.
if self.portable and self.updatable: if self.portable and self.updatable:
@ -78,32 +85,53 @@ class Build(object):
# and it contains the specific version found. # and it contains the specific version found.
print("Debug: searching for {file}".format(file = self.genappimagefilename[arch] + '.ver')) print("Debug: searching for {file}".format(file = self.genappimagefilename[arch] + '.ver'))
res = subprocess.run("find {path} -name {appimage}'".format( res = subprocess.run("find {path} -name {appimage}'".format(
path = self.storage_path, path = self.full_path,
appimage = self.genappimagefilename[arch] + '.ver' 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: if res.stdout:
# All good, the command was executed fine. # All good, the command was executed fine.
for file in res.stdout.decode('utf-8').strip('\n').split('\n'): for file in res.stdout.decode('utf-8').strip('\n').split('\n'):
if self.version in open(file, 'r').read(): 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])) print("Debug: searching for {file}".format(file = self.appimagefilename[arch]))
res = subprocess.run("find {path} -name '{appimage}'".format( res = subprocess.run("find {path} -name '{appimage}'".format(
path = self.storage_path, path = self.full_path,
appimage = self.appimagefilename[arch] appimage = self.appimagefilename[arch]
), shell=True, capture_output=True) ), shell=True, capture_output=True)
if res.stdout: if res.stdout:
if len(res.stdout.decode('utf-8').strip('\n')) > 1: if len(res.stdout.decode('utf-8').strip('\n')) > 1:
self.built = True self.built[arch] = True
if self.built: if self.built[arch]:
print("The requested AppImage already exists on storage. I'll skip downloading, building and moving the results.") 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): def download(self, download_path):
"""Downloads the contents of the URL as it was a folder.""" """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 start with defining which files are to be downloaded.
# Let's explore the remote folder. # Let's explore the remote folder.
self.download_path = download_path self.download_path = download_path
@ -112,6 +140,12 @@ class Build(object):
# Checking if a valid path has been provided # Checking if a valid path has been provided
if self.url[arch] == '-': if self.url[arch] == '-':
print("No build has been provided for the requested AppImage for {arch}. Continue with other options.".format(arch = 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 continue
contents = etree.HTML(urllib.request.urlopen(self.url[arch]).read()).xpath("//td/a") contents = etree.HTML(urllib.request.urlopen(self.url[arch]).read()).xpath("//td/a")
@ -137,22 +171,15 @@ class Build(object):
def build(self): def build(self):
"""Building all the versions.""" """Building all the versions."""
if self.built:
return
# We have 4 builds to do: # We have 4 builds to do:
# * standard languages, no help # * standard languages, no help
# * standard languages + offline help # * standard languages + offline help
# * all languages, no help # * all languages, no help
# * all languages + offline help # * all languages + offline help
if self.portable and not 'portable' in self.storage_path:
self.storage_path += "/portable"
for arch in self.arch: for arch in self.arch:
# Checking if a valid path has been provided if self.built[arch]:
if self.url[arch] == '-': # Already built for arch or path not available. User has already been warned.
# User has been warned in download step.
continue continue
# Preparation tasks # Preparation tasks
@ -261,9 +288,13 @@ class Build(object):
def checksums(self): def checksums(self):
"""Create checksums of the built versions.""" """Create checksums of the built versions."""
if self.built: if all(self.built.values()):
# All checksums are already created.
return return
# On the contrary, checksums will be in any case overwritten if
# existent, but generated only for built packages anyways
os.chdir(self.appnamedir) os.chdir(self.appnamedir)
for appimage in glob.glob('*.AppImage*'): for appimage in glob.glob('*.AppImage*'):
# See if a checksum already exist # See if a checksum already exist
@ -271,13 +302,16 @@ class Build(object):
subprocess.run("md5sum {appimage} > {appimage}.md5".format(appimage = appimage), shell=True) subprocess.run("md5sum {appimage} > {appimage}.md5".format(appimage = appimage), shell=True)
def move(self): def publish(self):
"""Moves built versions to definitive storage.""" """Moves built versions to definitive storage."""
if self.built: if all(self.built.values()):
# All files are already present in the full_path
return return
os.chdir(self.appnamedir) 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): def __del__(self):
"""Destructor""" """Destructor"""

View File

@ -37,7 +37,7 @@ def build(arch, language, offline, portable, updatable, download, storage, check
obj.download(download) obj.download(download)
obj.build() obj.build()
obj.checksums() obj.checksums()
obj.move() obj.publish()
del obj del obj
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -6,7 +6,7 @@ from setuptools import setup,find_packages
setup( setup(
name="loaih", name="loaih",
version="1.0.0", version="1.0.1",
description="LOAIH - LibreOffice AppImage Helpers, help build a LibreOffice AppImage", description="LOAIH - LibreOffice AppImage Helpers, help build a LibreOffice AppImage",
author="Emiliano Vavassori", author="Emiliano Vavassori",
author_email="syntaxerrormmm@libreoffice.org", author_email="syntaxerrormmm@libreoffice.org",