Append non-existing tweak.override attributes

This commit is contained in:
KV 2021-09-12 23:14:09 +02:00
parent 04a7dab010
commit ba8f8423be
2 changed files with 9 additions and 3 deletions

View File

@ -347,7 +347,8 @@ Alternatively items can be added to just the BOM by putting them in the section
<str>: # leading string of .gv entry
<str> : <str> # attribute and its new value
# Any number of attributes can be overridden
# for each entry
# for each entry. Attributes not already existing
# in the entry will be appended to the entry.
append: <str/list> # string or list of strings to append to the .gv output
```

View File

@ -367,11 +367,16 @@ class Harness:
keyword = match and match[2]
if keyword in self.tweak.override.keys():
for attr, value in self.tweak.override[keyword].items():
# TODO?: If value is None: delete attr?
if len(value) == 0 or ' ' in value:
value = value.replace('"', r'\"')
value = f'"{value}"'
# TODO?: If value is None: delete attr, and if attr not found: append it?
entry = re.sub(f'{attr}=("[^"]*"|[^] ]*)', f'{attr}={value}', entry)
entry, n_subs = re.subn(f'{attr}=("[^"]*"|[^] ]*)', f'{attr}={value}', entry)
if n_subs < 1:
# If attr not found, then append it
entry = re.sub(r'\]$', f' {attr}={value}]', entry)
elif n_subs > 1:
print(f'Harness.create_graph() warning: {attr} overridden {n_subs} times in {keyword}!')
dot.body[i] = entry
if self.tweak.append is not None: