diff --git a/fresh.yml b/fresh.yml index 1f8735a..8678b0f 100644 --- a/fresh.yml +++ b/fresh.yml @@ -1,7 +1,9 @@ --- data: - storage: /srv/http/appimage.sys42.eu + repo: /srv/http/appimage.sys42.eu download: /var/tmp/downloads + force: no + sign: yes builds: - query: fresh diff --git a/loaih/__init__.py b/loaih/__init__.py index 89f05d1..ea0728a 100644 --- a/loaih/__init__.py +++ b/loaih/__init__.py @@ -8,6 +8,7 @@ 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' ] LANGBASIC = [ 'en-GB' ] + ARCHSTD = [ u'x86', u'x86_64' ] def __init__(self, query, arch): """Build all versions that can be found in the indicated repo.""" @@ -19,11 +20,14 @@ class Build(object): self.offline_help = False self.portable = False self.updatable = True + self.sign = False self.storage_path = '/srv/http/appimage.sys42.eu' self.download_path = '/var/tmp/downloads' + + # Specific build version self.appversion = '' - self.appimagefilename = {} self.genappversion = '' + self.appimagefilename = {} self.genappimagefilename = {} # Getting versions and so on @@ -44,12 +48,8 @@ class Build(object): self.relative_path = [] self.full_path = '' - def check(self, storage_path): - """Checking if the requested AppImage has been already built.""" - # Mandate to the private function to calculate the full_path available - # for the storage and the checks. - self.__calculate_full_path__() - + def calculate(self): + """Calculate exclusions and other variables.""" # Incompatibilities - if portable and updatable are asked together, # only portable will be built. if self.portable and self.updatable: @@ -61,6 +61,10 @@ class Build(object): # to build an updatable version. self.updatable = False + # Mandate to the private function to calculate the full_path available + # for the storage and the checks. + self.__calculate_full_path__() + # Building expected AppImageName self.languagepart = "." if ',' in self.language: @@ -71,14 +75,16 @@ class Build(object): self.helppart = '.help' if self.offline_help else '' # If the build was called by queried name, build from latest release available but build with the most generic name + self.appversion = self.version + self.languagepart + self.helppart myver = str.join('.', self.version.split('.')[0:2]) self.genappversion = myver + self.languagepart + self.helppart - self.genappimagefilename[u'x86'] = self.appname + '-' + self.genappversion + '-x86.AppImage' - self.genappimagefilename[u'x86_64'] = self.appname + '-' + self.genappversion + '-x86_64.AppImage' + for arch in Build.ARCHSTD: + self.appimagefilename[arch] = self.appname + '-' + self.appversion + f'-{arch}.AppImage' + self.genappimagefilename[arch] = self.appname + '-' + self.genappversion + f'-{arch}.AppImage' - self.appversion = self.version + self.languagepart + self.helppart - self.appimagefilename[u'x86'] = self.appname + '-' + self.appversion + '-x86.AppImage' - self.appimagefilename[u'x86_64'] = self.appname + '-' + self.appversion + '-x86_64.AppImage' + + def check(self): + """Checking if the requested AppImage has been already built.""" for arch in self.arch: # For generalized builds, we need to check if there are .ver file @@ -130,12 +136,8 @@ class Build(object): fullpath_arr.extend(self.relative_path) self.full_path = re.sub(r"/+", '/', str.join('/', fullpath_arr)) - def download(self, download_path): + def download(self): """Downloads the contents of the URL as it was a folder.""" - # Let's start with defining which files are to be downloaded. - # Let's explore the remote folder. - self.download_path = download_path - for arch in self.arch: # Checking if a valid path has been provided if self.url[arch] == '-': @@ -195,6 +197,7 @@ class Build(object): # Build the requested version. if self.queried_name and not self.portable: + # If it is portable, do not generate a generalized version self.__unpackbuild__(arch, True) self.__unpackbuild__(arch) @@ -275,22 +278,27 @@ class Build(object): # updatable version. # zsync name was generated already + # Dealing with extra options + buildopts = [] + if self.sign: + buildopts.append('--sign') + # If asked to do a generalized build: if generalize: - subprocess.run("VERSION={version} ./appimagetool -u 'zsync|{zsync}' -v ./{appname}.AppDir/".format(version = self.genappversion, zsync = self.genappimagefilename[arch] + '.zsync', appname = self.appname), shell=True) + subprocess.run("VERSION={version} ./appimagetool {buildopts} -u 'zsync|{zsync}' -v ./{appname}.AppDir/".format(version = self.genappversion, buildopts = str.join(' ', buildopts), zsync = self.genappimagefilename[arch] + '.zsync', appname = self.appname), shell=True) # Build version file management with open(self.genappimagefilename[arch] + '.ver', 'w') as v: v.write(self.version) else: - subprocess.run("VERSION={version} ./appimagetool -u 'zsync|{zsync}' -v ./{appname}.AppDir/".format(version = self.appversion, zsync = self.appimagefilename[arch] + '.zsync', appname = self.appname), shell=True) + subprocess.run("VERSION={version} ./appimagetool {buildopts} -u 'zsync|{zsync}' -v ./{appname}.AppDir/".format(version = self.appversion, buildopts = str.join(' ', buildopts), zsync = self.appimagefilename[arch] + '.zsync', appname = self.appname), shell=True) else: if generalize: - subprocess.run("VERSION={version} ./appimagetool -v ./{appname}.AppDir/".format(version = self.genappversion, appname = self.appname), shell=True) + subprocess.run("VERSION={version} ./appimagetool {buildopts} -v ./{appname}.AppDir/".format(version = self.genappversion, buildopts = str.join(' ', buildopts), appname = self.appname), shell=True) with open(self.genappimagefilename[arch] + '.ver', 'w') as v: v.write(self.version) else: - subprocess.run("VERSION={version} ./appimagetool -v ./{appname}.AppDir/".format(version = self.appversion, appname = self.appname), shell=True) + subprocess.run("VERSION={version} ./appimagetool {buildopts} -v ./{appname}.AppDir/".format(version = self.appversion, buildopts = str.join(' ', buildopts), appname = self.appname), shell=True) print("Built AppImage version {version}".format(version = self.appversion)) diff --git a/scripts/loaih-build b/scripts/loaih-build index 5ff89a2..7a1ead4 100644 --- a/scripts/loaih-build +++ b/scripts/loaih-build @@ -7,22 +7,23 @@ import loaih @click.command() @click.option('-a', '--arch', 'arch', type=click.Choice(['x86', 'x86_64', 'all'], case_sensitive=False), default='all', help="Build the AppImage for a specific architecture. If there is no specific options, the process will build for both architectures (if available). Default: all") +@click.option('-c/-C', '--check/--no-check', 'check', default=True, help="Check in the final storage if the queried version is existent. Default: check") +@click.option('-d', '--download-path', 'download_path', default = '/var/tmp/downloads', type=str, help="Path to the download folder. Default: /var/tmp/downloads") @click.option('-l', '--language', 'language', default = 'basic', type=str, help="Languages to be included. Options: basic, standard, full, a language string (e.g. 'it') or a list of languages comma separated (e.g.: 'en-US,en-GB,it'). Default: basic") @click.option('-o/-O', '--offline-help/--no-offline-help', 'offline', default = False, help="Include or not the offline help for the chosen languages. Default: no offline help") @click.option('-p/-P', '--portable/--no-portable', 'portable', default = False, help="Create a portable version of the AppImage or not. Default: no portable") +@click.option('-r', '--repo-path', 'repo_path', default = '/srv/http/appimage.sys42.eu', type=str, help="Path to the final storage of the AppImage. Default: /srv/http/appimage.sys42.eu") +@click.option('-s/-S', '--sign/--no-sign', 'sign', default=False, help="Wether to sign the build. Default: no-sign") @click.option('-u/-U', '--updatable/--no-updatable', 'updatable', default = True, help="Create an updatable version of the AppImage or not. Default: updatable") -@click.option('-d', '--download-path', 'download', default = '/var/tmp/downloads', type=str, help="Path to the download folder. Default: /var/tmp/downloads") -@click.option('-s', '--storage-path', 'storage', default = '/srv/http/appimage.sys42.eu', type=str, help="Path to the final storage of the AppImage. Default: /srv/http/appimage.sys42.eu") -@click.option('-c/-C', '--check/--no-check', 'check', default=True, help="Check in the final storage if the queried version is existent. Default: check") @click.argument('query') -def build(arch, language, offline, portable, updatable, download, storage, check, query): +def build(arch, language, offline, portable, updatable, download_path, repo_path, check, sign, query): # Parsing options arches = [] if arch.lower() == 'all': # We need to build it twice. arches = [ u'x86', u'x86_64' ] else: - arches = [ arch.lower().decode('utf-8') ] + arches = [ arch.lower() ] if query.endswith('.yml') or query.endswith('.yaml'): # This is a buildfile. So we have to load the file and pass the build options ourselves. @@ -36,17 +37,23 @@ def build(arch, language, offline, portable, updatable, download, storage, check # Loop a run for each build. obj = loaih.Build(build['query'], arches) + # Configuration phase obj.language = build['language'] obj.offline_help = build['offline_help'] obj.portable = build['portable'] obj.updatable = True + obj.storage_path = config['data']['repo'] if 'repo' in config['data'] and config['data']['repo'] else '/srv/http/appimage.sys42.eu' + obj.download_path = config['data']['download'] if 'download' in config['data'] and config['data']['download'] else '/var/tmp/downloads' - if check: - obj.check(config['data']['storage']) - else: - obj.storage_path = config['data']['storage'] + if 'sign' in config['data'] and config['data']['sign']: + obj.sign = True - obj.download(config['data']['download']) + # Build phase + obj.calculate() + if not 'force' in config['data'] or not config['data']['force']: + obj.check() + + obj.download() obj.build() obj.checksums() obj.publish() @@ -55,17 +62,24 @@ def build(arch, language, offline, portable, updatable, download, storage, check else: obj = loaih.Build(query, arches) + # Configuration phase obj.language = language obj.offline_help = offline obj.portable = portable obj.updatable = updatable + obj.storage_path = repo_path + obj.download_path = download_path + + if sign: + obj.sign = True + + # Running phase + obj.calculate() if check: - obj.check(storage) - else: - obj.storage_path = storage + obj.check() - obj.download(download) + obj.download() obj.build() obj.checksums() obj.publish() diff --git a/setup.py b/setup.py index 032157f..4ee9309 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup,find_packages setup( name="loaih", - version="1.0.1", + version="1.1.0", description="LOAIH - LibreOffice AppImage Helpers, help build a LibreOffice AppImage", author="Emiliano Vavassori", author_email="syntaxerrormmm@libreoffice.org", diff --git a/still.yml b/still.yml index 3d86642..2a97d14 100644 --- a/still.yml +++ b/still.yml @@ -1,7 +1,9 @@ --- data: - storage: /srv/http/appimage.sys42.eu + repo: /srv/http/appimage.sys42.eu download: /var/tmp/downloads + force: no + sign: yes builds: - query: still