Skip to content

Commit

Permalink
Move group loop into build_generated() for consistency
Browse files Browse the repository at this point in the history
Now, all action functions are called with a group list as argument.
  • Loading branch information
kvid committed Jul 24, 2020
1 parent d7d0236 commit 67f5e20
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions src/wireviz/build_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,43 @@ def collect_filenames(description, groupkey, ext_list):
return sorted([filename for pattern in patterns for filename in path.glob(pattern)])


def build_generated(groupkey):
# build files
path = groups[groupkey]['path']
build_readme = readme in groups[groupkey]
if build_readme:
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)

def build_generated(groupkeys):
for key in groupkeys:
# preparation
path = groups[key]['path']
build_readme = readme in groups[key]
if build_readme:
i = ''.join(filter(str.isdigit, yaml_file.stem))

with open_file_append(path / readme) as out:
if include_readme:
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_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'![]({yaml_file.stem}.png)\n\n')
out.write(f'[Source]({yaml_file.name}) - [Bill of Materials]({yaml_file.stem}.bom.tsv)\n\n\n')
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)

if build_readme:
i = ''.join(filter(str.isdigit, yaml_file.stem))

with open_file_append(path / readme) as out:
if include_readme:
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_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'![]({yaml_file.stem}.png)\n\n')
out.write(f'[Source]({yaml_file.name}) - [Bill of Materials]({yaml_file.stem}.bom.tsv)\n\n\n')


def clean_generated(groupkeys):
Expand Down Expand Up @@ -133,9 +134,7 @@ def parse_args():
def main():
args = parse_args()
if args.action == 'build':
# TODO: Move this loop into the function for consistency?
for groupkey in args.groups:
build_generated(groupkey)
build_generated(args.groups)
elif args.action == 'clean':
clean_generated(args.groups)
elif args.action == 'compare':
Expand Down

0 comments on commit 67f5e20

Please sign in to comment.