1
0

Alcune pesanti correzioni ai meccanismi di download e alla raccolta dei tarball.

This commit is contained in:
Emiliano Vavassori 2022-03-21 01:10:17 +01:00
parent 0df231e450
commit 3422c5e931

View File

@ -13,7 +13,7 @@ class Build(object):
"""Build all versions that can be found in the indicated repo.""" """Build all versions that can be found in the indicated repo."""
self.query = query self.query = query
self.arch = arch self.arch = arch
self.url = '' self.url = {}
self.language = 'basic' self.language = 'basic'
self.offline_help = False self.offline_help = False
self.portable = False self.portable = False
@ -25,6 +25,14 @@ class Build(object):
# Getting versions and so on # Getting versions and so on
v = versions.BuildVersion(self.query) 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 # Building expected AppImageName
languagepart = "." languagepart = "."
if ',' in self.language: if ',' in self.language:
@ -32,24 +40,19 @@ class Build(object):
else: else:
languagepart += self.language 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'] = self.appname + '-' + self.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_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): 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 + ('/portable' if self.portable else '') self.storage_path = storage_path + ('/portable' if self.portable else '')
for arch in self.arch: for arch in self.arch:
print("DEBUG: {appimage}".format(appimage = self.appimagefilename[arch])) res = subprocess.check_output("find {path} -name '{appimage}'".format(
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') path = self.storage_path,
appimage = self.appimagefilename[arch] + ('.zsync' if self.updatable else '')
), shell=True).decode('utf-8').strip('\n')
if len(res) > 1: if len(res) > 1:
self.built = True self.built = True
@ -65,25 +68,28 @@ class Build(object):
# Let's explore the remote folder. # Let's explore the remote folder.
self.download_path = download_path self.download_path = download_path
for a in self.arch: for arch in self.arch:
contents = etree.HTML(urllib.request.urlopen(self.url[a]).read()).xpath("//td/a") # Checking if a valid path has been provided
self.tarballs = [ x.text for x in contents if x.text.endswith('tar.gz') ] if self.url[arch] == '-':
maintarball = self.tarballs[0] print("No build has been provided for the requested AppImage for {arch}. Continue with other options.".format(arch = arch))
mainarr = maintarball.split('') continue
self.appname = mainarr[0]
self.version = mainarr[1]
os.makedirs(self.downloaddir, existok = True) contents = etree.HTML(urllib.request.urlopen(self.url[arch]).read()).xpath("//td/a")
os.chdir(self.downloaddir) self.tarballs[arch] = [ x.text for x in contents if x.text.endswith('tar.gz') ]
for archive in self.tarballs: 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 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) print("Archive %s is already there! Sweet" % archive)
continue continue
# Download the archive # Download the archive
try: try:
urllib.request.urlretrieve(self.url + archive, archive) urllib.request.urlretrieve(self.url[arch] + archive, archive)
except: except:
print("Failed to download {archive}.".format(archive = archive)) print("Failed to download {archive}.".format(archive = archive))
@ -110,6 +116,11 @@ class Build(object):
self.updatable = False self.updatable = False
for arch in self.arch: 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 # Preparation tasks
self.appnamedir = os.path.join(self.builddir, self.appname) self.appnamedir = os.path.join(self.builddir, self.appname)
self.appimagedir = os.path.join(self.builddir, self.appname, self.appname + '.AppDir') self.appimagedir = os.path.join(self.builddir, self.appname, self.appname + '.AppDir')
@ -122,31 +133,31 @@ class Build(object):
os.chmod('appimagetool', 0o755) os.chmod('appimagetool', 0o755)
# Build the requested version. # 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 # 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 # Let's process standard languages and append results to the
# buildtarball # buildtarball
if self.language == 'basic': 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: 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': if self.language == 'standard':
for lang in Build.LANGSTD: 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: 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: else:
# In any other cases, we build with all languages # In any other cases, we build with all languages
if not self.offlinehelp: 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: else:
# We need also all help. Let's replace buildtarball with the # We need also all help. Let's replace buildtarball with the
# whole bunch # whole bunch
buildtarballs = self.tarballs buildtarballs = self.tarballs[arch]
# Unpacking the tarballs # Unpacking the tarballs
for archive in buildtarballs: for archive in buildtarballs:
@ -177,7 +188,7 @@ class Build(object):
os.chmod(dest, 0o755) os.chmod(dest, 0o755)
# Setting app version # 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: if self.offline_help:
appversion += '.help' appversion += '.help'