aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com>2018-11-01 16:18:53 -0400
committerJuergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com>2018-11-01 17:37:53 -0400
commit29aea8282fb874b57fac80c275c4601d9a1be70f (patch)
treee51fb05b0386d71aa8ee8c42f617e226979c9178
parent2d6a4f42259cb137988538d5f2392d4602da1c9d (diff)
update watch
-rw-r--r--qface/watch.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/qface/watch.py b/qface/watch.py
index e5d86ba..117fcea 100644
--- a/qface/watch.py
+++ b/qface/watch.py
@@ -3,7 +3,7 @@ from watchdog.observers import Observer
import click
from path import Path
import time
-from subprocess import call
+from .shell import sh
"""
Provides an API to monitor the file system
@@ -11,10 +11,9 @@ Provides an API to monitor the file system
class RunScriptChangeHandler(FileSystemEventHandler):
- def __init__(self, args, cwd):
+ def __init__(self, script):
super().__init__()
- self.args = args
- self.cwd = cwd
+ self.script = script
self.is_running = False
def on_modified(self, event):
@@ -26,19 +25,26 @@ class RunScriptChangeHandler(FileSystemEventHandler):
if self.is_running:
return
self.is_running = True
- call(self.args, cwd=self.cwd)
+ sh(self.script, cwd=Path.getcwd())
self.is_running = False
-def monitor(args, watch, cwd=Path.getcwd()):
+def monitor(script_dir, src, dst, argv):
"""
reloads the script given by argv when src files changes
"""
- watch = watch if isinstance(watch, (list, tuple)) else [watch]
- watch = [Path(entry).expand().abspath() for entry in watch]
- event_handler = RunScriptChangeHandler(args, cwd)
+ if script_dir.isfile():
+ script_dir = script_dir.dirname()
+ src = src if isinstance(src, (list, tuple)) else [src]
+ dst = Path(dst).expand().abspath()
+ src = [Path(entry).expand().abspath() for entry in src]
+ command = ' '.join(argv)
+ print('command: ', command)
+ event_handler = RunScriptChangeHandler(command)
observer = Observer()
- for entry in watch:
+ click.secho('watch recursive: {0}'.format(script_dir), fg='blue')
+ observer.schedule(event_handler, script_dir, recursive=True)
+ for entry in src:
if entry.isfile():
entry = entry.parent
click.secho('watch recursive: {0}'.format(entry), fg='blue')