From ac4fb76b22058bcf30b8852b830c9ccd378f2c26 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Wed, 2 Jun 2021 11:43:20 +0200 Subject: [PATCH] sidetags: configurable naming template Fixes: https://pagure.io/koji/issue/2893 --- plugins/hub/sidetag.conf | 4 ++++ plugins/hub/sidetag_hub.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/hub/sidetag.conf b/plugins/hub/sidetag.conf index fefa32d8..3a2ed0f1 100644 --- a/plugins/hub/sidetag.conf +++ b/plugins/hub/sidetag.conf @@ -3,3 +3,7 @@ remove_empty = off # potential suffixes for sidetag names # allowed_suffixes = +# template for sidetag names. It must contain basetag and tag_id parts +# if allowed_suffixes is not empty and suffix was requested, it will be added +# as {name_template}-{suffix}. (percent-signs need to be escaped) +# name_template = %%(basetag)s-sidetag-%%(tag_id)d diff --git a/plugins/hub/sidetag_hub.py b/plugins/hub/sidetag_hub.py index 4dc82472..4fb96b68 100644 --- a/plugins/hub/sidetag_hub.py +++ b/plugins/hub/sidetag_hub.py @@ -118,7 +118,7 @@ def createSideTag(basetag, debuginfo=False, suffix=None): # ugly, it will waste one number in tag_id_seq, but result will match with # id assigned by _create_tag tag_id = nextval("tag_id_seq") + 1 - sidetag_name = "%s-side-%s" % (basetag["name"], tag_id) + sidetag_name = NAME_TEMPLATE % {'basetag': basetag["name"], 'tag_id': tag_id} if suffix: sidetag_name += '-%s' % suffix extra = { @@ -314,9 +314,14 @@ def handle_sidetag_untag(cbtype, *args, **kws): # read config and register if not CONFIG: CONFIG = koji.read_config_files(CONFIG_FILE) + print(open(CONFIG_FILE).read()) if CONFIG.has_option("sidetag", "remove_empty") and CONFIG.getboolean( "sidetag", "remove_empty" ): handle_sidetag_untag = callback("postUntag")(handle_sidetag_untag) if CONFIG.has_option("sidetag", "allowed_suffixes"): ALLOWED_SUFFIXES = CONFIG.get("sidetag", "allowed_suffixes").split(',') + if CONFIG.has_option("sidetag", "name_template"): + NAME_TEMPLATE = CONFIG.get("sidetag", "name_template") + else: + NAME_TEMPLATE = '%(basetag)s-side-%(tag_id)d'