From f33f4229cc3f6547fdf102d259b80944ca24846a Mon Sep 17 00:00:00 2001 From: Dmitriy Nikiforov Date: Mon, 22 Jul 2019 18:08:23 +0300 Subject: [PATCH] [app] Add feature specific variables handling. Contributes to JB#46680 --- src/img_web/app/forms.py | 4 +++- src/img_web/app/views.py | 26 +++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/img_web/app/forms.py b/src/img_web/app/forms.py index fcdf2a9..5e527d6 100644 --- a/src/img_web/app/forms.py +++ b/src/img_web/app/forms.py @@ -61,8 +61,10 @@ def expand_feature(name): if features.has_option(name, "repos"): for repo in features.get(name, "repos").split(","): for section in repo_sections: + if isinstance(feat[section], set): + feat[section] = {} if features.has_option(section, repo): - feat[section].add(features.get(section, repo)) + feat[section][repo] = features.get(section, repo) return dict(feat) class extraReposForm(forms.Form): diff --git a/src/img_web/app/views.py b/src/img_web/app/views.py index 3e35928..15ab746 100644 --- a/src/img_web/app/views.py +++ b/src/img_web/app/views.py @@ -92,11 +92,25 @@ def submit(request): imgjob.kickstart = "".join(ks) + vars_re = re.compile(r'^# Var@([\S]+)@([\S]+):(.*)$') + features_vars = {} + for line in ks: - if re.match(r'^#.*?KickstartType:.+$', line): - ks_type = line.split(":", 1)[1].strip() + if not line.startswith('#'): break + vars_match = vars_re.match(line) + if vars_match: + feature = vars_match.group(1) + var = vars_match.group(2) + val = vars_match.group(3).strip() + if feature in features_vars: + features_vars[feature][var] = val + else: + features_vars[feature] = {var: val} + elif re.match(r'^#.*?KickstartType:.+$', line): + ks_type = line.split(":", 1)[1].strip() + if ksname.endswith('.ks'): ksname = ksname[0:-3] @@ -117,7 +131,13 @@ def submit(request): if not ks_type or not repos_type in feat: repos_type = 'repositories' - extra_repos.update(feat.get(repos_type, set())) + feat_repos = feat.get(repos_type, dict()) + for name, url in feat_repos.items(): + if name in features_vars: + for var, val in features_vars[name].items(): + url = url.replace('@%s@' % var, val) + extra_repos.add(url) + overlay.update(feat.get('pattern', '')) overlay.update(feat.get('packages', set()))