Skip to content

Commit

Permalink
Make all actions honor the optional argument -generate
Browse files Browse the repository at this point in the history
This make it possible to select the group of files to use
for any action by following the action argument with '-generate' and
then the space separated group names.
  • Loading branch information
kvid committed Jul 20, 2020
1 parent 099c202 commit ec29076
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/wireviz/build_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,32 @@ def build(dirname, build_readme, include_source, include_readme):
out.write(f'[Source]({yaml_file.name}) - [Bill of Materials]({yaml_file.stem}.bom.tsv)\n\n\n')


def clean_examples():
for key in paths.keys():
def clean_generated(pathkeys):
for key in pathkeys:
# collect and remove files
for filename in collect_filenames('Cleaning', key, generated_extensions, readme):
if filename.is_file():
print(f' rm {filename}')
os.remove(filename)


def compare_generated(include_from_graphviz = False):
def compare_generated(pathkeys, include_from_graphviz = False):
compare_extensions = generated_extensions if include_from_graphviz else extensions_not_from_graphviz
for key in paths.keys():
for key in pathkeys:
# collect and compare files
for filename in collect_filenames('Comparing', key, compare_extensions, readme):
cmd = f'git --no-pager diff {filename}'
print(f' {cmd}')
os.system(cmd)


def restore_generated():
for key, value in paths.items():
def restore_generated(pathkeys):
for key in pathkeys:
# collect input YAML files
filename_list = collect_filenames('Restoring', key, input_extensions)
# collect files to restore
filename_list = [fn.with_suffix(ext) for fn in filename_list for ext in generated_extensions]
filename_list.append(value['path'] / readme)
filename_list.append(paths[key]['path'] / readme)
# restore files
for filename in filename_list:
cmd = f'git checkout -- {filename}'
Expand All @@ -110,8 +110,8 @@ def restore_generated():

def parse_args():
parser = argparse.ArgumentParser(description='Wireviz Example Manager',)
parser.add_argument('action', nargs='?', action='store', default='build')
parser.add_argument('-generate', nargs='*', choices=['examples', 'demos', 'tutorial'], default=['examples', 'demos', 'tutorial'])
parser.add_argument('action', nargs='?', action='store', choices=['build','clean','compare','restore'], default='build')
parser.add_argument('-generate', nargs='*', choices=paths.keys(), default=paths.keys())
return parser.parse_args()


Expand All @@ -126,11 +126,11 @@ def main():
if gentype == 'tutorial':
build('tutorial', build_readme = True, include_source = True, include_readme = True)
elif args.action == 'clean':
clean_examples()
clean_generated(args.generate)
elif args.action == 'compare':
compare_generated()
compare_generated(args.generate)
elif args.action == 'restore':
restore_generated()
restore_generated(args.generate)


if __name__ == '__main__':
Expand Down

0 comments on commit ec29076

Please sign in to comment.