summaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-08-02 12:40:57 +0200
committerJuergen Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-11-30 10:01:19 +0100
commitada58821a68c61d9bc905ce793dd4d0f6b497645 (patch)
tree4f9dede65368fcb04155fc8298f3a2381b0705b9 /cli.py
parent6a3dd2248f24670ad70a28a70e848e33eac651c5 (diff)
downloadqtivi-qface-ada58821a68c61d9bc905ce793dd4d0f6b497645.tar.gz
initial commit
Diffstat (limited to 'cli.py')
-rwxr-xr-xcli.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/cli.py b/cli.py
new file mode 100755
index 0000000..0ca3d4a
--- /dev/null
+++ b/cli.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+import click
+from subprocess import call
+from watchdog.events import FileSystemEventHandler
+from watchdog.observers import Observer
+from pathlib import Path
+import time
+
+
+def sh(cmd, all=False):
+ click.echo('$ {0}'.format(cmd))
+ return call(cmd, shell=True)
+
+
+@click.group()
+def cli():
+ pass
+
+
+@cli.command()
+def antlr():
+ sh('antlr4 -Dlanguage=Python3 -Werror -package qif.idl.parser -o qif/idl/parser -listener -visitor T.g4')
+
+
+@cli.command()
+def test():
+ sh('python3 -m pytest -v -s -l --pdb')
+
+
+class RunTestChangeHandler(FileSystemEventHandler):
+ def __init__(self, clickContext):
+ super(RunTestChangeHandler).__init__()
+ self.clickContext = clickContext
+
+ 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 --pdb')
+
+
+@cli.command()
+@click.pass_context
+def test_monitor(ctx):
+ while True:
+ event_handler = RunTestChangeHandler(ctx)
+ observer = Observer()
+ observer.schedule(event_handler, '.', recursive=True)
+ observer.start()
+ try:
+ while True:
+ time.sleep(1)
+ except KeyboardInterrupt:
+ observer.stop()
+ observer.join()
+
+
+class RunScriptChangeHandler(FileSystemEventHandler):
+ def __init__(self, script):
+ super(RunTestChangeHandler).__init__()
+ self.script = script
+
+ def on_modified(self, event):
+ if event.src_path.endswith('.cache'):
+ return
+ print(event)
+ sh(self.script)
+
+
+@cli.command()
+@click.option('--script')
+def generator_monitor(script):
+ print('run script: ' + script)
+ event_handler = RunScriptChangeHandler(script)
+ observer = Observer()
+ observer.schedule(event_handler, './templates', recursive=True)
+ observer.schedule(event_handler, str(Path(script).parent), recursive=False)
+ observer.start()
+ try:
+ while True:
+ time.sleep(5)
+ except KeyboardInterrupt:
+ observer.stop()
+ observer.join()
+
+if __name__ == '__main__':
+ cli()