From d0f73d0f1618b959e846a4f3ecc6f2cccf56f1b2 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Sat, 30 Apr 2022 23:31:06 +0200 Subject: [PATCH] Gestite multiple versioni. Ora anche prerelease e daily sono supportati. --- loaih/__init__.py | 52 ++++++++++++++++------------- loaih/build.py | 24 +++++++------- loaih/script.py | 84 ++++++++++++++++++++++------------------------- 3 files changed, 81 insertions(+), 79 deletions(-) diff --git a/loaih/__init__.py b/loaih/__init__.py index b102568..d15ccc8 100644 --- a/loaih/__init__.py +++ b/loaih/__init__.py @@ -110,9 +110,9 @@ class Base(object): # version. # If the version has only 2 points in it (or splits into three parts by '.'), that's not a full version and we will call the getlatestver() function - fullversion = version - if len(version.split('.')) <= 3: - fullversion = Base.fullversion(version) + fullversion = str(version) + if len(fullversion.split('.')) <= 3: + fullversion = str(Base.fullversion(version)) # So the final URL is the Archive one, plus the full versions, plus a # final '/deb/' - and an arch subfolder @@ -120,7 +120,7 @@ class Base(object): retval = {} # x86 binaries are not anymore offered after 6.3.0. - if parse_version(version) < parse_version('6.3.0'): + if parse_version(fullversion) < parse_version('6.3.0'): retval['x86'] = baseurl + 'x86/' else: retval['x86'] = '-' @@ -131,15 +131,20 @@ class Base(object): @staticmethod def collectedbuilds(query): - """Creates a list of Builds based on each namedver found.""" + """Creates a list of Builds based on each queried version found.""" retval = [] - a = Base.namedver(query) - if isinstance(a, list) and len(a) > 1: - retval = [ Build(query, version) for version in Base.namedver(query) ] - else: + if '.' in query: + # Called with a numeric query. Pass it to RemoteBuild retval.append(RemoteBuild(query)) + else: + # Named query + a = Base.namedver(query) + if isinstance(a, list) and len(a) > 1: + retval.extend([ RemoteBuild(query, version) for version in a ]) + else: + retval.append(RemoteBuild(query)) - return retval + return sorted(retval, key=lambda x: x.version) class RemoteBuild(object): @@ -150,32 +155,33 @@ class RemoteBuild(object): self.version = '' self.basedirurl = { 'x86': '-', 'x86_64': '-' } + if version and isinstance(version, str): + self.version = version + if not '.' in self.query: # Named version. # Let's check if a specific version was requested. - if version: - self.version = version - else: + if self.version == '': # In case it was not requested, we will carry on the generic # namedver() query. # If the results are more than one, we'll take the latest (since we are requested to provide a single build). a = Base.namedver(self.query) - if isinstance(a, list) and len(a) == 0: - # No results from the query - let's return default values - return + if isinstance(a, list): + if len(a) == 1: + # version is a single one. + self.version = a[0] + else: + # In this case, we will select the latest release. + self.version = sorted(a)[-1] - if len(a) == 1: - # version is a single one. - self.version = a[0] - else: - # In this case, we will select the latest release. - self.version = sorted(a)[-1] + # If the version has already a version, as requested by user, + # continue using that version else: # In case of numbered queries, put it as initial version self.version = self.query - if len(self.version.split('.')) < 4: + if len(str(self.version).split('.')) < 4: # If not 4 dotted, let's search for the 4 dotted version self.version = Base.fullversion(self.version) diff --git a/loaih/build.py b/loaih/build.py index 59e648a..fec92d3 100644 --- a/loaih/build.py +++ b/loaih/build.py @@ -5,25 +5,26 @@ import loaih from lxml import etree import tempfile, os, sys, glob, subprocess, shutil, re, shlex -class Build(object): +class Collection(list): + + def __init__(self, query, arch = ['x86', 'x86_64']): + """Build a list of version to check/build for this round.""" + super().__init__() + self.extend([ Build(query, arch, version) for version in loaih.Base.collectedbuilds(query) ]) + +class Build(loaih.RemoteBuild): 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.""" - self.query = query + def __init__(self, query, arch, version = None): + super().__init__(query, version) self.arch = arch - - # Getting versions and so on - v = versions.BuildVersion(self.query) - self.version = v.version - print(f"Debug {self.version}") self.short_version = str.join('.', self.version.split('.')[0:2]) self.branch_version = None if not '.' in self.query: self.branch_version = self.query - self.url = v.basedirurl + self.url = self.basedirurl # Other default values self.language = 'basic' @@ -52,7 +53,6 @@ class Build(object): self.full_path = '' self.baseurl = '' - def calculate(self): """Calculate exclusions and other variables.""" # AppName @@ -89,7 +89,7 @@ class Build(object): if len(self.relative_path) == 0: if self.query == 'daily': self.relative_path.append('daily') - elif self.query == 'primageerelease': + elif self.query == 'prerelease': self.relative_path.append('prerelease') # Not the same check, an additional one diff --git a/loaih/script.py b/loaih/script.py index 30d7bbf..40ddf36 100644 --- a/loaih/script.py +++ b/loaih/script.py @@ -3,7 +3,7 @@ import click import yaml -import loaih +import loaih, loaih.build import re, sys, json @click.group() @@ -22,12 +22,7 @@ def getversion(query, jsonout): queries.append(query) for q in queries: - if '.' in q: - # Numbered version. It is safe to send it to Build. - b.append(loaih.RemoteBuild(q)) - else: - # Named version. For safety, we call a helper method for a collection - b.extend(loaih.Base.collectedbuilds(q)) + b.extend(loaih.Base.collectedbuilds(q)) if len(b) > 0: if jsonout: @@ -66,22 +61,50 @@ def build(arch, language, offline, portable, updatable, download_path, repo_path # generic default. for build in config['builds']: # Loop a run for each build. - obj = loaih.Build(build['query'], arches) + collection = loaih.build.Collection(build['query'], arches) + for obj in collection: + # 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 'sign' in config['data'] and config['data']['sign']: + obj.sign = True + + # 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() + obj.generalize_and_link() + del obj + + else: + collection = loaih.build.Collection(query, arches) + for obj in collection: # 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' + 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' in config['data'] and config['data']['sign']: + if sign: obj.sign = True - # Build phase + # Running phase obj.calculate() - if not 'force' in config['data'] or not config['data']['force']: + + if check: obj.check() obj.download() @@ -90,30 +113,3 @@ def build(arch, language, offline, portable, updatable, download_path, repo_path obj.publish() obj.generalize_and_link() del obj - - 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() - - obj.download() - obj.build() - obj.checksums() - obj.publish() - obj.generalize_and_link() - del obj