summaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-09-16 08:33:22 +0200
committerJuergen Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-11-30 10:01:20 +0100
commit3ae245707dfa4b0f5caa502cbde5ae46b522306b (patch)
tree3304751eae93269a70a899d17737a590fa94f5c6 /cli.py
parentf26b8cc2b1678a72580b61961f49568b5b33bc1f (diff)
downloadqtivi-qface-3ae245707dfa4b0f5caa502cbde5ae46b522306b.tar.gz
Added some targets and changed how generators can be called (by name and by path now)
Diffstat (limited to 'cli.py')
-rwxr-xr-xcli.py53
1 files changed, 45 insertions, 8 deletions
diff --git a/cli.py b/cli.py
index 6228d7a..1960108 100755
--- a/cli.py
+++ b/cli.py
@@ -8,6 +8,7 @@ from watchdog.observers import Observer
from pathlib import Path
import time
import os
+import sys
import yaml
@@ -86,7 +87,9 @@ class RunScriptChangeHandler(FileSystemEventHandler):
return
if event.is_directory:
return
- print(event)
+ self.run()
+
+ def run(self):
sh('python3 {0}'.format(self.script), cwd=self.cwd)
@@ -121,19 +124,32 @@ def generate_monitor(runner, generator, input, output):
@cli.command()
-@click.option('--runner', type=click.File('r'))
-@click.option('--reload/--no-reload', default=False)
-@click.option('--generator', type=click.Path(exists=True))
-@click.option('--input', type=click.Path(exists=True))
-@click.option('--output', type=click.Path(exists=True))
-def generate(runner, generator, input, output, reload):
+@click.option('--runner', type=click.File('r'), help="use the runner YAML file to configure the generation")
+@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('--list/--no-list', help="lists the available generators")
+def generate(runner, generator, input, output, reload, list):
+ if list:
+ entries = [e.name for e in Path('generator').iterdir()]
+ click.echo('generators: {0}'.format(entries))
+ sys.exit(0)
"""run the named generator"""
if runner:
config = yaml.load(runner)
generator = config['generator']
input = config['input']
output = config['output']
- generator = Path(generator).absolute()
+ if not generator or not input or not output:
+ print('generator, input and output arguments are required')
+ sys.exit(-1)
+ generator = Path('generator') / generator
+ if not generator.exists():
+ generator = Path(generator).absolute()
+ if not generator.exists():
+ print('can not find the specified generator: ' + str(generator))
+ sys.exit(-1)
input = Path(input).absolute()
output = Path(output).absolute()
if not reload:
@@ -142,6 +158,7 @@ def generate(runner, generator, input, output, reload):
_generate_reload(generator, input, output)
+
def _generate_once(generator, input, output):
script = '{0}.py'.format(generator.name)
input = Path(input).absolute()
@@ -155,11 +172,13 @@ def _generate_reload(generator, input, output):
"""run the named generator and monitor the input and generator folder"""
script = generator / '{0}.py --input {1} --output {2}'.format(generator.name, input, output)
event_handler = RunScriptChangeHandler(script, cwd=generator.as_posix())
+ event_handler.run() # run always once
observer = Observer()
observer.schedule(event_handler, generator.as_posix(), recursive=True)
observer.schedule(event_handler, input.as_posix(), recursive=True)
observer.schedule(event_handler, './qface', recursive=True)
observer.start()
+
try:
while True:
time.sleep(2)
@@ -168,5 +187,23 @@ def _generate_reload(generator, input, output):
observer.join()
+@click.option('--editable/--no-editable', default=False, help='install editable package')
+@cli.command()
+def install(editable):
+ """install the script onto the system using pip3"""
+ script_dir = str(Path(__file__).parent.absolute())
+ print(script_dir)
+ if editable:
+ sh('pip3 install --editable {0} --upgrade'.format(script_dir))
+ else:
+ sh('pip3 install {0} --upgrade'.format(script_dir))
+
+
+@cli.command()
+def uninstall():
+ """uninstall the script from the system using pip3"""
+ sh('pip3 uninstall qface')
+
+
if __name__ == '__main__':
cli()