本文整理汇总了Python中fsevents.Observer.start方法的典型用法代码示例。如果您正苦于以下问题:Python Observer.start方法的具体用法?Python Observer.start怎么用?Python Observer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fsevents.Observer
的用法示例。
在下文中一共展示了Observer.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def main():
observer = Observer()
observer.start()
path = '/Users/seungjin/Desktop'
def callback(event):
#print "mask: " + str(event.mask)
#print "cookie: " + str(event.cookie)
#print "name: " + str(event.name)
print event
if event.mask == 256: #looks like new file comming
newFile(str(event.name))
elif event.mask == 512: #looks line file deleted
rmFile(str(event.name))
elif event.mask == 2: #looks like overwriting?
print "hihihihi"
def newFile(filename):
print "new file is comming"
#pushing this file into cloud
gs = Googlestorage()
#print gs.list_objects()
gs.upload_objects(filename)
def rmFile(filename):
#print "%s is removed" % filename
gs = Googlestorage() # this is evil.. do i need to make global goolgestorage object??? idk
gs.delete_objects_and_buckets(filename)
stream = Stream(callback,path,file_events=True)
observer.schedule(stream)
示例2: main
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def main():
def sigterm_handler(_signo, _stack_frame):
try:
Notifier.notify('Unregistering fs watch', title='LittleHelp', subtitle=project_path)
except:
pass
logging.info("Sigterm handler called")
observer.unschedule(stream)
observer.stop()
observer.join()
try:
Notifier.notify('Unregistered fs watch', title='LittleHelp', subtitle=project_path)
except:
pass
sys.exit(0)
try:
Notifier.notify('Registering watch', title='LittleHelp', subtitle=project_path)
observer = Observer()
stream = Stream(file_event_callback, project_path, file_events=True)
observer.schedule(stream)
observer.start()
signal.signal(signal.SIGTERM, sigterm_handler)
while True:
sleep(0.1)
except:
logging.exception("Unhandled exception")
示例3: _assert_action_after_watcher
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def _assert_action_after_watcher(self, process_asap, assertions_cb):
events = []
def callback(event):
events.append(event)
import os
import time
from fsevents import Stream
from fsevents import Observer
observer = Observer(process_asap=process_asap)
observer.start()
stream = Stream(callback, self.tempdir, file_events=True)
observer.schedule(stream)
# add single file
del events[:]
f = open(os.path.join(self.tempdir, "test"), "w")
f.write("abc")
f.flush()
f.close()
time.sleep(0.2)
# stop and join observer
observer.stop()
observer.unschedule(stream)
observer.join()
os.unlink(f.name)
assertions_cb(events, f)
示例4: test_existing_directories_are_not_reported
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def test_existing_directories_are_not_reported(self):
import os
from fsevents import Stream, Observer
events = []
def callback(event):
events.append(event)
stream = Stream(callback, self.tempdir, file_events=True)
new1 = os.path.join(self.tempdir, "newdir1")
new2 = os.path.join(self.tempdir, "newdir2")
os.mkdir(new1)
observer = Observer()
observer.schedule(stream)
observer.start()
import time
while not observer.isAlive():
time.sleep(0.1)
del events[:]
time.sleep(1)
os.mkdir(new2)
try:
time.sleep(1.1)
observer.stop()
observer.unschedule(stream)
observer.join()
from fsevents import IN_CREATE
self.assertEqual(len(events), 1)
self.assertEqual(events[0].mask, IN_CREATE)
self.assertEqual(events[0].name, os.path.realpath(new2))
finally:
os.rmdir(new1)
os.rmdir(new2)
示例5: run
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def run():
observer = Observer()
observer.start()
# start foreman
forerunner = Forerunner()
forerunner.start()
# call callback when files under the cwd change
stream = Stream(forerunner.callback, './', file_events=True)
observer.schedule(stream)
while True:
try:
sleep(1)
except KeyboardInterrupt:
observer.unschedule(stream)
observer.stop()
observer.join()
foreman = forerunner.foreman
for i in range(1, 10):
if foreman.poll() is not None:
break
print "sleeping... %i" % i
sleep(1)
if foreman.poll() is None:
foreman.kill()
sleep(1)
break
示例6: test_single_file_added
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def test_single_file_added(self):
events = []
def callback(*args):
events.append(args)
f, path = self._make_temporary()
from fsevents import Observer
observer = Observer(callback, file_events=True)
observer.start()
observer.schedule(path)
# add single file
import time
while not observer.isAlive():
time.sleep(0.1)
del events[:]
f.close()
time.sleep(1.1)
# stop and join observer
observer.stop()
observer.join()
self.assertEquals(events[0][0], path)
示例7: _loop_darwin
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def _loop_darwin(self): # pragma: no cover
"""loop implementation for darwin platform"""
from fsevents import Observer #pylint: disable=F0401
from fsevents import Stream #pylint: disable=F0401
from fsevents import IN_MODIFY #pylint: disable=F0401
observer = Observer()
handler = self._handle
def fsevent_callback(event):
if event.mask == IN_MODIFY:
handler(event)
for watch_this in self.watch_dirs:
stream = Stream(fsevent_callback, watch_this, file_events=True)
observer.schedule(stream)
observer.daemon = True
observer.start()
try:
# hack to keep main thread running...
import time
while True:
time.sleep(99999)
except (SystemExit, KeyboardInterrupt):
pass
示例8: test_single_file_added_multiple_streams
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def test_single_file_added_multiple_streams(self):
events = []
def callback(*args):
events.append(args)
f, path = self._make_temporary()
from fsevents import Stream
stream1 = Stream(callback, path)
stream2 = Stream(callback, path)
from fsevents import Observer
observer = Observer()
observer.schedule(stream1)
observer.schedule(stream2)
observer.start()
# add single file
import time
while not observer.isAlive():
time.sleep(0.1)
time.sleep(0.1)
del events[:]
f.close()
time.sleep(0.2)
# stop and join observer
observer.stop()
observer.unschedule(stream1)
observer.unschedule(stream2)
observer.join()
self.assertEquals(events[0][0], path)
self.assertEquals(events[1][0], path)
示例9: test_single_file_added_with_observer_unscheduled
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def test_single_file_added_with_observer_unscheduled(self):
events = []
def callback(*args):
events.append(args)
f, path = self._make_temporary()
from fsevents import Stream
stream = Stream(callback, path)
from fsevents import Observer
observer = Observer()
observer.start()
import time
while not observer.isAlive():
time.sleep(0.1)
observer.schedule(stream)
observer.unschedule(stream)
# add single file
del events[:]
f.close()
time.sleep(0.1)
# stop and join observer
observer.stop()
observer.join()
self.assertEqual(events, [])
示例10: test_start_then_watch
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def test_start_then_watch(self):
events = []
def callback(*args):
events.append(args)
f, path = self._make_temporary()
from fsevents import Stream
stream = Stream(callback, path)
from fsevents import Observer
observer = Observer()
observer.schedule(stream)
observer.start()
# add single file
import time
while not observer.isAlive():
time.sleep(0.1)
del events[:]
f.close()
time.sleep(0.2)
# stop and join observer
observer.stop()
observer.unschedule(stream)
observer.join()
self.assertEqual(events, [(path, self.create_and_remove_mask)])
示例11: callback
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def callback(event):
global observer, git_sync
if event.mask == kFSEventStreamEventFlagItemCreated:
# Sublime Text Seems to trigger a lot of these and they don't seem to
# warrant a new sync, so lets skip these for now.
return
filename = event.name
git_dir = os.path.join(config['local_path'], '.git')
if git_dir in filename:
# Skip sync for file change that are in the .git directory.
return
if observer:
# Stop observing.
observer.unschedule(stream)
observer.stop()
git_sync.run_sync()
# Start observing again.
observer = Observer()
observer.schedule(stream)
observer.start()
示例12: main
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def main():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('path')
arg_parser.add_argument('-c', '--cmd', required=True, nargs='+', help='Console command for execute')
arg_parser.add_argument('-d', '--delay', type=int, default=5, nargs='?', help='Synchronization delay in seconds')
arg_parser.add_argument('-v', '--verbose', action='store_true', help='verbose flag')
try:
args = arg_parser.parse_args()
path = args.path
if not os.path.isdir(path):
raise IOError('Path `%s` is not a directory' % path)
event_handler = EventHandler()
timer = TimerInterval(callback_func, args.delay, event_handler=event_handler, cmd=args.cmd, verbose=args.verbose)
stream = Stream(event_handler.callback_handler, path, file_events=True)
observer = Observer()
observer.schedule(stream)
observer.start()
timer.start()
except IOError as e:
print e
except KeyboardInterrupt:
observer.unschedule(stream)
observer.stop()
timer.stop()
示例13: __init__
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
class Dmon:
def __init__(self, dir, handlers):
self._handlers = handlers
self._dir = dir
def _call_handler(self, method, fname):
for handler in self._handlers:
getattr(handler, method)(fname)
def _run_pyinotify(self):
from lib import pyinotify
class PyInotifyEventProcessor(pyinotify.ProcessEvent):
def __init__(self, c_handler):
self._call = c_handler
def process_IN_CREATE(self, event):
self._call('on_create', event.pathname)
def process_IN_DELETE(self, event):
self._call('on_delete', event.pathname)
def process_IN_MODIFY(self, event):
self._call('on_update', event.pathname)
wm = pyinotify.WatchManager()
self._observer = pyinotify.Notifier(wm, PyInotifyEventProcessor(self._call_handler))
mask = pyinotify.ALL_EVENTS
wm.add_watch(self._dir, mask, rec=True)
while True:
self._observer.process_events()
if self._observer.check_events():
self._observer.read_events()
time.sleep(1)
def _run_macfse(self):
from lib import fsevents
from fsevents import Stream
from fsevents import Observer
def macfse_callback(event):
if event.mask in [256, 128]:
self._call_handler('on_create', event.name)
elif event.mask in [512, 64]:
self._call_handler('on_delete', event.name)
elif event.mask == 2:
self._call_handler('on_update', event.name)
self._observer = Observer()
self._stream = Stream(macfse_callback, self._dir, file_events=True)
self._observer.schedule(self._stream)
self._observer.start()
def start(self):
if 'darwin' in sys.platform.lower():
self._run_macfse()
elif 'linux' in sys.platform.lower():
self._run_pyinotify()
def stop(self):
if 'darwin' in sys.platform.lower():
self._observer.unschedule(self._stream)
self._observer.stop()
elif 'linux' in sys.platform.lower():
self._observer.stop()
示例14: run
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def run(self):
observer = Observer()
observer.start()
#handler = self.process_event(self)
stream = Stream(self, self.path, file_events=True)
observer.schedule(stream)
示例15: watch_files
# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import start [as 别名]
def watch_files(paths):
global observer
observer = Observer()
stream = Stream(update_file, file_events=True, *paths)
observer.schedule(stream)
log.info("Starting observer")
observer.daemon = True
observer.start()
log.info("Observer started")