Skip to content

Commit 89ef81b

Browse files
author
Wouter van Heijst
committed
Parse (non-DisplayName) .ks headers in one general way
1 parent 76c032a commit 89ef81b

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/img_web/app/forms.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,24 +265,25 @@ class ImageJobForm(forms.Form):
265265
def __init__(self, *args, **kwargs):
266266
super(ImageJobForm, self).__init__(*args, **kwargs)
267267
self.fields['template'].choices = []
268+
suggested_re = re.compile(
269+
r'^#.*?Suggested(Architecture|ImageType|Features):(.*)$'
270+
)
271+
device_re = re.compile(
272+
r'^#.*?(DeviceModel|DeviceVariant):(.*)$'
273+
)
268274
for template in glob.glob(os.path.join(settings.TEMPLATESDIR, '*.ks')):
269275
name = os.path.basename(template)
270276
templatename = os.path.basename(template)
271277
attrs = {}
272278
with open(template, 'r') as tf:
273279
for line in tf:
274-
if re.match(r'^#.*?DisplayName:.+$', line):
280+
match = suggested_re.match(line) or device_re.match(line)
281+
if match:
282+
key = 'data-' + match.group(1).lower()
283+
val = match.group(2).strip()
284+
attrs[key] = val
285+
elif re.match(r'^#.*?DisplayName:.+$', line):
275286
name = line.split(":")[1].strip()
276-
if re.match(r'^#.*?SuggestedFeatures:.+$', line):
277-
attrs["data-features"] = line.split(":")[1].strip()
278-
if re.match(r'^#.*?SuggestedArchitecture:.+$', line):
279-
attrs["data-architecture"] = line.split(":")[1].strip()
280-
if re.match(r'^#.*?SuggestedImageType:.+$', line):
281-
attrs["data-imagetype"] = line.split(":")[1].strip()
282-
if re.match(r'^#.*?DeviceModel:.+$', line):
283-
attrs['data-devicemodel'] = line.split(":")[1].strip()
284-
if re.match(r'^#.*?DeviceVariant:.+$', line):
285-
attrs['data-devicevariant'] = line.split(":")[1].strip()
286287

287288
self.fields['template'].choices.append((templatename , name, attrs))
288289

0 commit comments

Comments
 (0)