Move group loop into build_generated() for consistency
Now, all action functions are called with a group list as argument.
This commit is contained in:
parent
94ca9cc358
commit
378e13b988
@ -47,42 +47,43 @@ def collect_filenames(description, groupkey, ext_list):
|
|||||||
return sorted([filename for pattern in patterns for filename in path.glob(pattern)])
|
return sorted([filename for pattern in patterns for filename in path.glob(pattern)])
|
||||||
|
|
||||||
|
|
||||||
def build_generated(groupkey):
|
def build_generated(groupkeys):
|
||||||
# build files
|
for key in groupkeys:
|
||||||
path = groups[groupkey]['path']
|
# preparation
|
||||||
build_readme = readme in groups[groupkey]
|
path = groups[key]['path']
|
||||||
if build_readme:
|
build_readme = readme in groups[key]
|
||||||
include_readme = 'md' in groups[groupkey][readme]
|
|
||||||
include_source = 'yml' in groups[groupkey][readme]
|
|
||||||
with open_file_write(path / readme) as out:
|
|
||||||
out.write(f'# {groups[groupkey]["title"]}\n\n')
|
|
||||||
# collect and iterate input YAML files
|
|
||||||
for yaml_file in collect_filenames('Building', groupkey, input_extensions):
|
|
||||||
print(f' {yaml_file}')
|
|
||||||
wireviz.parse_file(yaml_file)
|
|
||||||
|
|
||||||
if build_readme:
|
if build_readme:
|
||||||
i = ''.join(filter(str.isdigit, yaml_file.stem))
|
include_readme = 'md' in groups[key][readme]
|
||||||
|
include_source = 'yml' in groups[key][readme]
|
||||||
|
with open_file_write(path / readme) as out:
|
||||||
|
out.write(f'# {groups[key]["title"]}\n\n')
|
||||||
|
# collect and iterate input YAML files
|
||||||
|
for yaml_file in collect_filenames('Building', key, input_extensions):
|
||||||
|
print(f' {yaml_file}')
|
||||||
|
wireviz.parse_file(yaml_file)
|
||||||
|
|
||||||
with open_file_append(path / readme) as out:
|
if build_readme:
|
||||||
if include_readme:
|
i = ''.join(filter(str.isdigit, yaml_file.stem))
|
||||||
with open_file_read(yaml_file.with_suffix('.md')) as info:
|
|
||||||
for line in info:
|
|
||||||
out.write(line.replace('## ', f'## {i} - '))
|
|
||||||
out.write('\n\n')
|
|
||||||
else:
|
|
||||||
out.write(f'## Example {i}\n')
|
|
||||||
|
|
||||||
if include_source:
|
with open_file_append(path / readme) as out:
|
||||||
with open_file_read(yaml_file) as src:
|
if include_readme:
|
||||||
out.write('```yaml\n')
|
with open_file_read(yaml_file.with_suffix('.md')) as info:
|
||||||
for line in src:
|
for line in info:
|
||||||
out.write(line)
|
out.write(line.replace('## ', f'## {i} - '))
|
||||||
out.write('```\n')
|
out.write('\n\n')
|
||||||
out.write('\n')
|
else:
|
||||||
|
out.write(f'## Example {i}\n')
|
||||||
|
|
||||||
out.write(f'\n\n')
|
if include_source:
|
||||||
out.write(f'[Source]({yaml_file.name}) - [Bill of Materials]({yaml_file.stem}.bom.tsv)\n\n\n')
|
with open_file_read(yaml_file) as src:
|
||||||
|
out.write('```yaml\n')
|
||||||
|
for line in src:
|
||||||
|
out.write(line)
|
||||||
|
out.write('```\n')
|
||||||
|
out.write('\n')
|
||||||
|
|
||||||
|
out.write(f'\n\n')
|
||||||
|
out.write(f'[Source]({yaml_file.name}) - [Bill of Materials]({yaml_file.stem}.bom.tsv)\n\n\n')
|
||||||
|
|
||||||
|
|
||||||
def clean_generated(groupkeys):
|
def clean_generated(groupkeys):
|
||||||
@ -133,9 +134,7 @@ def parse_args():
|
|||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.action == 'build':
|
if args.action == 'build':
|
||||||
# TODO: Move this loop into the function for consistency?
|
build_generated(args.groups)
|
||||||
for groupkey in args.groups:
|
|
||||||
build_generated(groupkey)
|
|
||||||
elif args.action == 'clean':
|
elif args.action == 'clean':
|
||||||
clean_generated(args.groups)
|
clean_generated(args.groups)
|
||||||
elif args.action == 'compare':
|
elif args.action == 'compare':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user