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}...")
示例#2
0
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')
示例#3
0
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()
示例#6
0
文件: example.py 项目: vpsoft/hachiko
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()
示例#7
0
def watch_fs():
    watch = AIOWatchdog('/home/ymq/tst')
    watch.start()
    while 1:
        yield from asyncio.sleep(1)
    print('watch stoped .....')
    watch.stop()
示例#8
0
 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()
示例#10
0
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")
示例#11
0
    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")
示例#12
0
async def watch(dir, watcher):
    """Start watchdog thread monitoring changes to dir."""
    watcher = AIOWatchdog(dir, False, watcher)
    watcher.start()
示例#13
0
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)
示例#14
0
def watch_fs():
    watch = AIOWatchdog('/Users/jbiesnecker/temp/forks/test')
    watch.start()
    for _ in range(20):
        yield from asyncio.sleep(1)
    watch.stop()
示例#15
0
def watch_fs(path):
    watch = AIOWatchdog(path, event_handler=Handler())
    watch.start()
    while True:
        yield from asyncio.sleep(10)
    watch.stop()
示例#16
0
# 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)
示例#17
0
    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()