From bbeca3366441b87a1ca3c2b8cbfa3ea164e38d37 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sun, 31 Jan 2021 11:24:45 +0000 Subject: [PATCH] BUILDBOT: Rework filename parsing --- buildbot-config/list_snapshots/__init__.py | 11 ++++++----- buildbot-config/scummsteps.py | 18 ++++++++++++------ buildbot-config/ui.py | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/buildbot-config/list_snapshots/__init__.py b/buildbot-config/list_snapshots/__init__.py index 5d2f4ca..a6f6c56 100644 --- a/buildbot-config/list_snapshots/__init__.py +++ b/buildbot-config/list_snapshots/__init__.py @@ -15,10 +15,10 @@ from bottle import request, response __all__ = [ 'get_application' ] # PackageInfo is generic and is built at startup -PackageInfo = collections.namedtuple('PackageInfo', ['path', 'base_url']) +PackageInfo = collections.namedtuple('PackageInfo', ['build', 'platform', 'path', 'base_url']) # SnapshotInfo is resolved in real time from a PackageInfo SnapshotInfo = collections.namedtuple('SnaphshotInfo', ['revision', 'url']) -Helpers = collections.namedtuple('Helpers', ['get_names', 'get_revision']) +Helpers = collections.namedtuple('Helpers', ['get_names', 'parse_name']) # Subclass Bottle to have a pretty configuration @implementer(IConfigured) @@ -84,7 +84,7 @@ def get_packaged_data(snapshots_dir, snapshots_url, helpers, def get_package_infos(snapshots_dir, snapshots_url, helpers, build, platform): - _, _, symlink = helpers[0]( + _, _, symlink = helpers.get_names( buildname=build.name, platformname=platform.name, archive_format=platform.archiveext, @@ -93,7 +93,7 @@ def get_package_infos(snapshots_dir, snapshots_url, helpers, base_url = urlp.urljoin(snapshots_url + '/', build.name + '/') - return PackageInfo(path, base_url) + return PackageInfo(build.name, platform.name, path, base_url) # Filter for list_snapshots template # Determine the revision pointed by symlink @@ -109,7 +109,8 @@ def to_snapshot(pkg_info): # Create a revision dependent URL url = urlp.urljoin(pkg_info.base_url, basename) - rev = helpers[1](basename) + parsed = helpers.parse_name(basename, build = pkg_info.build, platform = pkg_info.platform) + rev = parsed['revision'] if parsed else None return SnapshotInfo(rev, url) diff --git a/buildbot-config/scummsteps.py b/buildbot-config/scummsteps.py index 0a9bea5..0562471 100644 --- a/buildbot-config/scummsteps.py +++ b/buildbot-config/scummsteps.py @@ -147,7 +147,7 @@ PACKAGE_FORMAT_COMMANDS = { } # Helper to generate file names -def createNames(buildname, platformname, archive_format, revision): +def create_names(buildname, platformname, archive_format, revision): if archive_format not in PACKAGE_FORMAT_COMMANDS: archive_format = "tar.bz2" if revision is not None: @@ -158,10 +158,16 @@ def createNames(buildname, platformname, archive_format, revision): symlink = "{0}-{1}-latest.{2}".format(platformname, buildname, archive_format) return name, archive, symlink -PACKAGE_NAME_RE = re.compile(r'.+-[^-]+-([0-9a-fA-F]+)\..*') -def getRevisionFromName(name): - mtch = PACKAGE_NAME_RE.match(name) - return mtch.group(1) if mtch else None +# Curly braces here are used by format not re +PACKAGE_NAME_RE = r'(?P{0})-(?P{1})-(?P[0-9a-fA-F]*|latest)\..*' +# When both build and platform are None, detection will be wrong when builds have dashes +def parse_package_name(name, *, build = None, platform = None): + if build is None: + build = '[^-]+' + if platform is None: + platform = '.+' + mtch = re.match(PACKAGE_NAME_RE.format(platform, build), name) + return mtch # Helper function which generates a list of steps that build the package on the worker, # upload it to master and create the symlink for the latest @@ -186,7 +192,7 @@ def get_package_steps(buildname, platformname, srcpath, dstpath, dsturl, files += [ os.path.join(srcpath, f) for f in build_data_files ] def namesFromProps(props): - return createNames(buildname, platformname, archive_format, props["revision"]) + return create_names(buildname, platformname, archive_format, props["revision"]) @util.renderer def generateCommands(props): diff --git a/buildbot-config/ui.py b/buildbot-config/ui.py index a891f44..98b4078 100644 --- a/buildbot-config/ui.py +++ b/buildbot-config/ui.py @@ -117,7 +117,7 @@ if hasattr(config, 'enable_list_snapshots') and config.enable_list_snapshots: 'name': 'snapshots', 'caption': 'Snapshots', 'app': list_snapshots.get_application( - (scummsteps.createNames, scummsteps.getRevisionFromName), + (scummsteps.create_names, scummsteps.parse_package_name), config.snapshots_dir, config.snapshots_url, builds.builds, platforms.platforms, serve_snapshots = serve_snapshots),