Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change command line options #173

Merged
merged 4 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
from setuptools import setup, find_packages

from src.wireviz import __version__

project_name = 'wireviz'

# Utility function to read the README file.
Expand All @@ -15,7 +17,7 @@ def read(fname):

setup(
name=project_name,
version='0.1',
version=__version__,
author='Daniel Rojas',
#author_email='',
description='Easily document cables and wiring harnesses',
Expand Down
3 changes: 3 additions & 0 deletions src/wireviz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please don't import anything in this file to avoid issues when it is imported in setup.py

__version__ = '0.1.1'
32 changes: 20 additions & 12 deletions src/wireviz/build_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
script_path = Path(__file__).absolute()

sys.path.insert(0, str(script_path.parent.parent)) # to find wireviz module
from wireviz import wireviz
from wireviz import wireviz, __version__
from wv_helper import open_file_write, open_file_read, open_file_append


dir = script_path.parent.parent.parent
readme = 'readme.md'
groups = {
'examples': {
'path': Path(script_path).parent.parent.parent / 'examples',
'path': dir / 'examples',
'prefix': 'ex',
readme: [], # Include no files
'title': 'Example Gallery',
},
'tutorial' : {
'path': Path(script_path).parent.parent.parent / 'tutorial',
'path': dir / 'tutorial',
'prefix': 'tutorial',
readme: ['md', 'yml'], # Include .md and .yml files
'title': 'WireViz Tutorial',
},
'demos' : {
'path': Path(script_path).parent.parent.parent / 'examples',
'path': dir / 'examples',
'prefix': 'demo',
},
}
Expand Down Expand Up @@ -96,17 +97,21 @@ def clean_generated(groupkeys):
os.remove(filename)


def compare_generated(groupkeys, include_graphviz_output = False):
def compare_generated(groupkeys, branch = '', include_graphviz_output = False):
if branch:
branch = f' {branch.strip()}'
compare_extensions = generated_extensions if include_graphviz_output else extensions_not_containing_graphviz_output
for key in groupkeys:
# collect and compare files
for filename in collect_filenames('Comparing', key, compare_extensions):
cmd = f'git --no-pager diff "{filename}"'
cmd = f'git --no-pager diff{branch} -- "{filename}"'
print(f' {cmd}')
os.system(cmd)


def restore_generated(groupkeys):
def restore_generated(groupkeys, branch = ''):
if branch:
branch = f' {branch.strip()}'
for key in groupkeys:
# collect input YAML files
filename_list = collect_filenames('Restoring', key, input_extensions)
Expand All @@ -116,18 +121,21 @@ def restore_generated(groupkeys):
filename_list.append(groups[key]['path'] / readme)
# restore files
for filename in filename_list:
cmd = f'git checkout -- "{filename}"'
cmd = f'git checkout{branch} -- "{filename}"'
print(f' {cmd}')
os.system(cmd)


def parse_args():
parser = argparse.ArgumentParser(description='Wireviz Example Manager',)
parser.add_argument('-V', '--version', action='version', version='%(prog)s - wireviz ' + __version__)
parser.add_argument('action', nargs='?', action='store',
choices=['build','clean','compare','restore'], default='build',
choices=['build','clean','compare','diff','restore'], default='build',
help='what to do with the generated files (default: build)')
parser.add_argument('-c', '--compare-graphviz-output', action='store_true',
help='the Graphviz output is also compared (default: False)')
parser.add_argument('-b', '--branch', action='store', default='',
help='branch or commit to compare with or restore from')
parser.add_argument('-g', '--groups', nargs='+',
choices=groups.keys(), default=groups.keys(),
help='the groups of generated files (default: all)')
Expand All @@ -140,10 +148,10 @@ def main():
build_generated(args.groups)
elif args.action == 'clean':
clean_generated(args.groups)
elif args.action == 'compare':
compare_generated(args.groups, args.compare_graphviz_output)
elif args.action == 'compare' or args.action == 'diff':
compare_generated(args.groups, args.branch, args.compare_graphviz_output)
elif args.action == 'restore':
restore_generated(args.groups)
restore_generated(args.groups, args.branch)


if __name__ == '__main__':
Expand Down
5 changes: 3 additions & 2 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if __name__ == '__main__':
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))


from wireviz import __version__
from wireviz.Harness import Harness
from wireviz.wv_helper import expand, open_file_read

Expand Down Expand Up @@ -211,9 +211,10 @@ def parse_cmdline():
parser = argparse.ArgumentParser(
description='Generate cable and wiring harness documentation from YAML descriptions',
)
parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('input_file', action='store', type=str, metavar='YAML_FILE')
parser.add_argument('-o', '--output_file', action='store', type=str, metavar='OUTPUT')
parser.add_argument('--generate-bom', action='store_true', default=True)
# Not implemented: parser.add_argument('--generate-bom', action='store_true', default=True)
parser.add_argument('--prepend-file', action='store', type=str, metavar='YAML_FILE')
return parser.parse_args()

Expand Down