help=('Listen for changes to files and reload the running app on all connected devices'))
help=('Listen for changes to files and reload the running app on all connected devices'))
listen_parser.set_defaults(func=self.run)
listen_parser.set_defaults(func=self.run)
defrun(self,args,pids):
defwatch_dir(self,directory):
cmd=[
ifself.watch_cmdisNone:
'which',
name=platform.system()
'fswatch'
ifname=='Linux':
]
try:
out=subprocess.check_output(cmd)
cmd=[
match=re.search(r'fswatch',out)
'which',
ifmatchisNone:
'inotifywait'
logging.error('"listen" command is only useful if you have installed fswatch. Run "brew install fswatch" to install it with homebrew.')
]
return
out=subprocess.check_output(cmd)
exceptsubprocess.CalledProcessError:
logging.error('"listen" command is only useful if you have installed inotifywait on Linux. Run "apt-get install inotify-tools" or equivalent to install it.')
returnFalse
self.watch_cmd=[
'inotifywait',
'-r',
'-e',
'modify,close_write,move,create,delete',# Only listen for events that matter, to avoid triggering constantly from the editor watching files
directory
]
elifname=='Darwin':
try:
cmd=[
'which',
'fswatch'
]
out=subprocess.check_output(cmd)
exceptsubprocess.CalledProcessError:
logging.error('"listen" command is only useful if you have installed fswatch on Mac. Run "brew install fswatch" to install it with homebrew.')
returnFalse
self.watch_cmd=[
'fswatch',
'-r',
'-v',
'-1',
directory
]
else:
logging.error('"listen" command is only available on Mac and Linux.')
returnFalse
subprocess.check_call(self.watch_cmd)
returnTrue
tempdir=None
defrun(self,args,pids):
currdir=None
tempdir=tempfile.mkdtemp()
currdir=os.getcwd()
whileTrue:
whileTrue:
# Watch filesystem for changes
# Watch filesystem for changes
cmd=[
ifnotself.watch_dir(currdir):
'fswatch',
return
'-r',
'-v',
'-1',
'.'
]
subprocess.check_call(cmd)
logging.info('Updating running Sky apps...')
logging.info('Updating running Sky apps...')
...
@@ -590,10 +629,6 @@ class StartListening(object):
...
@@ -590,10 +629,6 @@ class StartListening(object):
# since we aren't shipping the sky_snapshot binary yet.
# since we aren't shipping the sky_snapshot binary yet.