def main(): parse_command_line() logger = logging.getLogger("bboxer") logger.info("Root is set to %s", os.path.abspath(options.root)) # Add events watcher for options.root wm = pyinotify.WatchManager() handler = RootEventsNotifier(logger) notifier = pyinotify.TornadoAsyncNotifier( wm, IOLoop.instance(), default_proc_fun=handler) wm.add_watch(options.root, pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_DELETE_SELF) app = web.Application([ ("/bboxer.html", BBoxerHandler), ("/selections", SelectionsHandler), ("/update", UpdateHandler), ("/touched", TouchedHandler, {"events_handler": handler}), (r"/images/(?P<path>.*)", web.StaticFileHandler, {"path": options.root}), (r"/thumbnails/(?P<path>.*)", ThumbnailsHandler), (r"/((js|css|fonts|img|maps)/.*)", web.StaticFileHandler, {'path': root.common.web.root}), ("/", web.RedirectHandler, {"url": "/bboxer.html", "permanent": True}), ("", web.RedirectHandler, {"url": "/bboxer.html", "permanent": True})], template_path=root.common.web.templates ) app.listen(options.port) logger.info("Listening on %d", options.port) try: IOLoop.instance().start() finally: notifier.stop()
def setup_server(args, config, key): clients = [] state_manager = StateManager(config['app_id'], Database(get_data_dir(), get_lock_file()), CommandCipher(key)) ensure_lock_file() ensure_data_dir() wm = pyinotify.WatchManager() notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop.IOLoop.current(), change_callback, pyinotify.ProcessEvent()) notifier.clients = clients notifier.state_manager = state_manager wm.add_watch(get_lock_file(), pyinotify.IN_CLOSE_WRITE) # make sure initial state is prepared fresh = not state_manager.notify() auth_bucket = LeakyBucket(timedelta(seconds=3), 3) app = web.Application([ (r'/gtd', GTDSocketHandler, { 'config': config, 'auth_bucket': auth_bucket, 'clients': clients, 'state_manager': state_manager }), ]) app.listen(args.port, address='127.0.0.1') schedule_midnight(ioloop.IOLoop.current(), clients) return fresh
def start(cls, func): if HAS_PYINOTIFY: if not cls.notifier: cls.notifier = pyinotify.TornadoAsyncNotifier( cls.wm, ioloop.IOLoop.instance(), default_proc_fun=TaskEventHandler(func=func)) Task.watch() # initial run so we don't miss the first change return HAS_PYINOTIFY
def __init__(self, files, query): log.debug('Watching for %s' % files) inotify = pyinotify.WatchManager() self.files = files self.query = query self.notifier = pyinotify.TornadoAsyncNotifier( inotify, ioloop, self.notified, pyinotify.ProcessEvent()) inotify.add_watch( files, pyinotify.EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'], rec=True)
def start(self, callback): if not self.notifier: self.callback = callback from tornado import ioloop self.notifier = pyinotify.TornadoAsyncNotifier( self.wm, ioloop.IOLoop.instance(), default_proc_fun=self.inotify_event ) callback() return True
def __init__(self): inotify = pyinotify.WatchManager() self.files = glob('/usr/lib/libpython*') if not self.files: self.files = glob('/lib/libpython*') log.debug('Watching for %s' % self.files) self.notifier = pyinotify.TornadoAsyncNotifier( inotify, ioloop, self.notified, pyinotify.ProcessEvent()) inotify.add_watch( self.files, pyinotify.EventsCodes.ALL_FLAGS['IN_OPEN'] | pyinotify.EventsCodes.ALL_FLAGS['IN_CLOSE_NOWRITE'])
def repomon(config): wm = pyinotify.WatchManager() ioloop = IOLoop.instance() handler = EventHandler( filterPkg, config=config, wm=wm, ioloop=ioloop, ) return pyinotify.TornadoAsyncNotifier( wm, ioloop, default_proc_fun=handler, )
def start(self): for f in os.listdir(self.path): name = file2mod(f) if not name: continue self._load(name) wm = pyinotify.WatchManager() wm.add_watch(self.path, pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY, rec=False) handle = EventHandler(self) self._notifier = pyinotify.TornadoAsyncNotifier( wm, self._ioloop, default_proc_fun=handle)
async def main(): profiles = get_profiles() newClient = Client("wss://localhost:8080/device/controller", profiles['controller']["username"], profiles['controller']["password"], profiles) await newClient.connect() # Create the watch manager watch_manager = pyinotify.WatchManager() # TODO do we need event_notifier? event_notifier = pyinotify.TornadoAsyncNotifier( watch_manager, IOLoop.current(), New_Device_Handler(client=newClient, profiles=profiles)) watch_manager.add_watch("/tmp/devices", pyinotify.IN_CREATE)
def __init__(self, extra_search_path=None): inotify = pyinotify.WatchManager() self.files = glob('/usr/lib/libpython*') if not self.files: self.files = glob('/lib/libpython*') if extra_search_path is not None: # Handle custom installation paths for root, dirnames, filenames in os.walk(extra_search_path): for filename in fnmatch.filter(filenames, 'libpython*'): self.files.append(os.path.join(root, filename)) log.debug('Watching for %s' % self.files) self.notifier = pyinotify.TornadoAsyncNotifier( inotify, ioloop, self.notified, pyinotify.ProcessEvent()) inotify.add_watch( self.files, pyinotify.EventsCodes.ALL_FLAGS['IN_OPEN'] | pyinotify.EventsCodes.ALL_FLAGS['IN_CLOSE_NOWRITE'])
def __init__(self, parser, io_loop=None): """ :type parser: click_config.Parser """ self.io_loop = io_loop or ioloop.IOLoop.current() self.manager = pyinotify.WatchManager() self.notifier = pyinotify.TornadoAsyncNotifier(self.manager, self.io_loop) self.absolute_paths = [os.path.abspath(p) for p in parser.config_paths] self._sections = defaultdict(LayerDict) for i, path in enumerate(self.absolute_paths): self.watch_path(path) self.listeners = {} configs = [ _parse_files(_extract_files_from_paths([path])) for path in self.absolute_paths ] for i, gen in enumerate(chain(configs, parser.overrides)): for f, sect, items in gen: self._sections[sect].set_layer((i, f), dict(items))
async def main(): if not os.path.exists("/tmp/devices"): os.mkdir("/tmp/devices") profiles = get_profiles() newClient = Client("wss://localhost:8080/device/controller", profiles['controller']["username"], profiles['controller']["password"]) await newClient.connect() # Create the watch manager watch_manager = pyinotify.WatchManager() # TODO do we need event_notifier? event_notifier = pyinotify.TornadoAsyncNotifier( watch_manager, IOLoop.current(), New_Device_Handler(client=newClient, profiles=profiles)) watch_manager.add_watch("/tmp/devices", pyinotify.IN_CREATE) for files in os.listdir("/tmp/devices"): full_path = os.path.join("/tmp/devices", files) if os.path.isdir(full_path): await register_device(full_path, newClient, profiles)
from tornado.ioloop import IOLoop class EventHandler(pyinotify.ProcessEvent): def process_IN_DELETE(self, event): print "Removing:", event.pathname def process_IN_MODIFY(self, event): print "Modifying:", event.pathname def handle_read_callback(notifier): """ Just stop receiving IO read events after the first iteration (unrealistic example). """ print('handle_read callback') # notifier.io_loop.stop() # notifier.stop() wm = pyinotify.WatchManager() ioloop = IOLoop.instance() notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop, handle_read_callback, EventHandler()) wm.add_watch('watch_this', pyinotify.ALL_EVENTS) ioloop.start() # ioloop.close() # notifier.stop()
def __init__(self, loop): self.loop = loop self.watches = {} self.wm = pyinotify.WatchManager() self.tornado_notifier = pyinotify.TornadoAsyncNotifier( self.wm, self.loop.ioloop)
import pyinotify from tornado.ioloop import IOLoop def handle_read_callback(notifier): """ Just stop receiving IO read events after the first iteration (unrealistic example). """ print('handle_read callback') notifier.io_loop.stop() wm = pyinotify.WatchManager() ioloop = IOLoop.instance() notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop, callback=handle_read_callback) wm.add_watch('/tmp', pyinotify.ALL_EVENTS) ioloop.start() ioloop.close() notifier.stop()