async def start_fs_watchdog(path, api=None, *a, **k): "Coroutine to bring up the filesystem watchdog" watcher = AIOWatchdog(path, event_handler=PoreRefinerFSEventHandler( path, *a, **k)) watcher.start() log.info(f"Filesystem events being watched in {path}...")
def start_watcher(): global watcher handler = Handler() print('starting file watcher...') watcher = AIOWatchdog(config.Args.logdir, event_handler=handler) watcher.start() print('watcher start is complete')
async def hot_reload_module(module: ModuleType): path = os.path.dirname(module.__file__) evh = MyEventHandler(module, debug=True) await evh.load_modules() if True: watch = AIOWatchdog(path, event_handler=evh, recursive=True) __MODULE_WATCHERS__[module.__name__] = watch watch.start()
def start_watching(plex_sql_path, backup_path, plex_metadata_path, metadata_backup_path, enable_metadata, logging_level): logger = setup_logging(logging_level) loop = asyncio.get_event_loop() logger.info("Using PLEX_DB_PATH %s", plex_sql_path) logger.info("Using DB_BACKUP_PATH %s", backup_path) logger.info("Using PLEX_METADATA_PATH %s", plex_metadata_path) logger.info("Using METADATA_BACKUP_PATH %s", metadata_backup_path) db_handler = PlexLocalFileBackupHandler(plex_sql_path, backup_path, "SQLite") db_watcher = AIOWatchdog(plex_sql_path, event_handler=db_handler) if enable_metadata: metadata_handler = PlexLocalFileBackupHandler(plex_metadata_path, metadata_backup_path, "Metadata") metadata_watcher = AIOWatchdog(plex_metadata_path, event_handler=metadata_handler) try: logger.info("Starting Watchers") loop.create_task(start_watcher(db_watcher)) if enable_metadata: loop.create_task(start_watcher(metadata_watcher)) loop.run_forever() except KeyboardInterrupt: logger.info("Stopping Watchers") db_watcher.stop() if enable_metadata: metadata_watcher.stop() finally: loop.close()
def start_watching(plex_sql_path, backup_path): logger = setup_logging() loop = asyncio.get_event_loop() logger.info("Using PLEX_DB_PATH %s", plex_sql_path) logger.info("Using DB_BACKUP_PATH %s", backup_path) handler = PlexSQLiteBackupHandler(plex_sql_path, backup_path) watcher = AIOWatchdog(plex_sql_path, event_handler=handler) try: logger.info("Starting Watcher") loop.create_task(start_watcher(watcher)) loop.run_forever() except KeyboardInterrupt: logger.info("Stopping Watcher") watcher.stop() finally: loop.close()
async def watch_fs(watch_dir): evh = MyEventHandler() watch = AIOWatchdog(watch_dir, event_handler=evh) watch.start() for _ in range(20): await asyncio.sleep(1) watch.stop()
def watch_fs(): watch = AIOWatchdog('/home/ymq/tst') watch.start() while 1: yield from asyncio.sleep(1) print('watch stoped .....') watch.stop()
async def watch_fs(): event_handler = SubclassEventHandler() # hachinko style event handler watcher = AIOWatchdog(WATCH_DIRECTORY, event_handler=event_handler) watcher.start() await check_output_is_expected(WATCH_DIRECTORY, capsys) # Stop the directory watcher watcher.stop()
async def watch_fs(watch_dir): patterns = "*" ignore_patterns = "" ignore_directories = False case_sensitive = True evh = MyEventHandler() watch = AIOWatchdog(watch_dir, event_handler=evh, recursive=True) watch.start() while True: await asyncio.sleep(1) watch.stop()
async def watch_fs(path): watch = AIOWatchdog(path, event_handler=NegmasMonitorFile(log_folder=path)) watch.start() import threading print('monitor threading is {}'. format(threading.current_thread())) import os print("monitor process id is {}".format(os.getpid())) for _ in range(100): await asyncio.sleep(1) watch.stop() print("Finish monitoring task")
async def run(self): print("run()") evh = Handler() watch = AIOWatchdog(WATCH_DIRECTORY, event_handler=evh) watch.start() #self.observer.schedule(event_handler, WATCH_DIRECTORY, recursive=True) #self.observer.start() print("Observer started") try: while True: await asyncio.sleep(1) except: watch.stop() print("Observer Stopped")
async def watch(dir, watcher): """Start watchdog thread monitoring changes to dir.""" watcher = AIOWatchdog(dir, False, watcher) watcher.start()
async def on_startup(dp): evh = EventHandler(dp.bot) dp.watch = AIOWatchdog(os.getenv("ZM_FOLDER", "/zm"), event_handler=evh) dp.watch.start() setup_handlers(dp)
def watch_fs(): watch = AIOWatchdog('/Users/jbiesnecker/temp/forks/test') watch.start() for _ in range(20): yield from asyncio.sleep(1) watch.stop()
def watch_fs(path): watch = AIOWatchdog(path, event_handler=Handler()) watch.start() while True: yield from asyncio.sleep(10) watch.stop()
# from . import config import asyncio from hachiko.hachiko import AIOWatchdog class Handler: def dispatch(self, *args, **kwargs): print(args, kwargs) @asyncio.coroutine def watch_fs(path): watch = AIOWatchdog(path, event_handler=Handler()) watch.start() while True: yield from asyncio.sleep(10) watch.stop() if __name__ == "__main__": # asyncio.get_event_loop().run_until_complete(watch_fs("/Users/ge/machine_learning/berkeley-playground/ins-runs")) # asyncio.get_event_loop().run_until_complete(watch_fs(".")) path = "." watch = AIOWatchdog(path, event_handler=Handler()) watch.start() import time print('watch is setup') while True: time.sleep(10)
async def on_deleted(self, event): if event.src_path in self._active_events: self._active_events.pop(event.src_path) async def on_moved(self, event): if event.src_path in self._active_events: self._active_events.pop(event.src_path) await self._dispatch_work(event) if __name__ == "__main__": from argparse import ArgumentParser args_parser = ArgumentParser(__name__) args_parser.add_argument('path', help='path to observing') args = args_parser.parse_args() class MyEventHandler(ReadyFilesEventHandlerWrapper): async def on_file_ready(self, file_path): print('received %s' % file_path) loop = asyncio.get_event_loop() watch = AIOWatchdog(args.path, event_handler=MyEventHandler()) watch.start() try: loop.run_forever() except KeyboardInterrupt: print('Stop loop...') watch.stop() loop.stop()