From cefd71984f3122489660d7653f1a6cbd3d431ee1 Mon Sep 17 00:00:00 2001 From: Juergen Bocklage-Ryannel Date: Mon, 19 Sep 2016 10:16:12 +0200 Subject: - Ensured script can be run from other directories and built-in generators can be called by name. - Added a clean option to generator, which if enabled cleans the output folder before usage - Output folder is created if it does not exists yet --- cli.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'cli.py') diff --git a/cli.py b/cli.py index 0a917b6..5fa95a0 100755 --- a/cli.py +++ b/cli.py @@ -12,6 +12,8 @@ import sys import yaml +CWD = Path(__file__).parent + os.environ['PYTHONPATH'] = os.getcwd() @@ -53,15 +55,15 @@ class RunTestChangeHandler(FileSystemEventHandler): def on_any_event(self, event): if event.is_directory: return - if Path(event.src_path).suffix == '.py': - sh('python3 -m pytest -v -s -l') + if Path(event.src_path).ext == '.py': + sh('python3 -m pytest') @cli.command() @click.pass_context def test_monitor(ctx): """run the tests and re-run on changes""" - sh('python3 -m pytest -v -s -l') + sh('python3 -m pytest') while True: event_handler = RunTestChangeHandler(ctx) observer = Observer() @@ -98,9 +100,10 @@ class RunScriptChangeHandler(FileSystemEventHandler): @click.option('--reload/--no-reload', default=False, help="if enabled auto-reload the generator on input changes") @click.option('--generator', help="specifies the generator (either by name or path)") @click.option('--input', type=click.Path(exists=True), help="specifies the input folder") -@click.option('--output', type=click.Path(exists=True), help="specified the output folder") +@click.option('--output', type=click.Path(exists=False), help="specified the output folder") @click.option('--list/--no-list', help="lists the available generators") -def generate(runner, generator, input, output, reload, list): +@click.option('--clean/--no-clean', help="initially cleans the output directory") +def generate(runner, generator, input, output, reload, list, clean): if list: entries = [str(x.name) for x in Path('generator').dirs()] click.echo('generators: {0}'.format(entries)) @@ -115,7 +118,7 @@ def generate(runner, generator, input, output, reload, list): print('generator, input and output arguments are required') sys.exit(-1) # check for embedded generator by name - generator = Path('generator/{0}'.format(generator)) + generator = CWD / 'generator/{0}'.format(generator) if not generator.exists(): generator = Path(generator).abspath() # look if generator points to an external generator @@ -125,6 +128,9 @@ def generate(runner, generator, input, output, reload, list): input = Path(input).abspath() output = Path(output).abspath() generator = Path(generator).abspath() + if clean: + output.rmtree_p() + output.makedirs_p() if not reload: _generate_once(generator, input, output) else: -- cgit v1.2.1