Skip to content

Commit f33f422

Browse files
author
Dmitriy Nikiforov
committed
[app] Add feature specific variables handling. Contributes to JB#46680
1 parent c7dd064 commit f33f422

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/img_web/app/forms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ def expand_feature(name):
6161
if features.has_option(name, "repos"):
6262
for repo in features.get(name, "repos").split(","):
6363
for section in repo_sections:
64+
if isinstance(feat[section], set):
65+
feat[section] = {}
6466
if features.has_option(section, repo):
65-
feat[section].add(features.get(section, repo))
67+
feat[section][repo] = features.get(section, repo)
6668
return dict(feat)
6769

6870
class extraReposForm(forms.Form):

src/img_web/app/views.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,25 @@ def submit(request):
9292

9393
imgjob.kickstart = "".join(ks)
9494

95+
vars_re = re.compile(r'^# Var@([\S]+)@([\S]+):(.*)$')
96+
features_vars = {}
97+
9598
for line in ks:
96-
if re.match(r'^#.*?KickstartType:.+$', line):
97-
ks_type = line.split(":", 1)[1].strip()
99+
if not line.startswith('#'):
98100
break
99101

102+
vars_match = vars_re.match(line)
103+
if vars_match:
104+
feature = vars_match.group(1)
105+
var = vars_match.group(2)
106+
val = vars_match.group(3).strip()
107+
if feature in features_vars:
108+
features_vars[feature][var] = val
109+
else:
110+
features_vars[feature] = {var: val}
111+
elif re.match(r'^#.*?KickstartType:.+$', line):
112+
ks_type = line.split(":", 1)[1].strip()
113+
100114
if ksname.endswith('.ks'):
101115
ksname = ksname[0:-3]
102116

@@ -117,7 +131,13 @@ def submit(request):
117131
if not ks_type or not repos_type in feat:
118132
repos_type = 'repositories'
119133

120-
extra_repos.update(feat.get(repos_type, set()))
134+
feat_repos = feat.get(repos_type, dict())
135+
for name, url in feat_repos.items():
136+
if name in features_vars:
137+
for var, val in features_vars[name].items():
138+
url = url.replace('@%s@' % var, val)
139+
extra_repos.add(url)
140+
121141
overlay.update(feat.get('pattern', ''))
122142
overlay.update(feat.get('packages', set()))
123143

0 commit comments

Comments
 (0)