help=('Listen for changes to files and reload the running app on all connected devices'))
listen_parser.set_defaults(func=self.run)
defrun(self,args,pids):
cmd=[
'which',
'fswatch'
]
out=subprocess.check_output(cmd)
match=re.search(r'fswatch',out)
ifmatchisNone:
logging.error('"listen" command is only useful if you have installed fswatch. Run "brew install fswatch" to install it with homebrew.')
return
defwatch_dir(self,directory):
ifself.watch_cmdisNone:
name=platform.system()
ifname=='Linux':
try:
cmd=[
'which',
'inotifywait'
]
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
currdir=None
defrun(self,args,pids):
tempdir=tempfile.mkdtemp()
currdir=os.getcwd()
whileTrue:
# Watch filesystem for changes
cmd=[
'fswatch',
'-r',
'-v',
'-1',
'.'
]
subprocess.check_call(cmd)
ifnotself.watch_dir(currdir):
return
logging.info('Updating running Sky apps...')
...
...
@@ -590,10 +629,6 @@ class StartListening(object):
# since we aren't shipping the sky_snapshot binary yet.