def configure(self, options, updated): self.last_options = options if not self.observer: self.observer = polling.PollingObserver() # Bind the handler to the real underlying master object self.observer.schedule(ReloadHandler(self.reload), os.path.dirname(self.path) or ".") self.observer.start() self.run("configure", options, updated)
def __init__(self, src_path, db, ldamodel, topic_classifier, severity_classifier, sentiment_classifier, config): self.__src_path = src_path self.__db = db self.__event_handler = DNDFileEventHandler(self.__db, ldamodel, topic_classifier, severity_classifier, sentiment_classifier, config) self.__event_observer = polling.PollingObserver()
def main(): """ Main function to call. """ args = docopt(__doc__, version='Filewatch Trigger v0.2.0') LOGGER.debug(args) is_aws_lambda_type = args['aws-lambda'] is_cmd_type = args['cmd'] # common options watchpath = args['--watchpath'] glob_filters = args['--filter'].rstrip(',').split(',') event_bitflag = FileEvent(int(args['--event'])) force_poll = args['--force-poll'] use_abs_path = not args['--relative'] # aws-lambda only lambda_name = args['--name'] if is_aws_lambda_type else None # cmd only cmd = args['--cmd'] if is_cmd_type else None def select_invoker(): if is_aws_lambda_type: return LambdaInvoker(lambda_name) if is_cmd_type: return CmdInvoker(cmd) raise Exception("Invalid subcommand used") invoker = select_invoker() print('Filewatch Trigger program has started, CTRL-C to terminate...') event_handler = Handler(patterns=glob_filters, invoker=invoker, file_event=event_bitflag, use_abs_path=use_abs_path, ignore_directories=True) observer = Observer() if not force_poll else polling.PollingObserver() observer.schedule(event_handler, watchpath, recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
def start(standalone=True): logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') path = os.path.join(os.path.dirname(__file__), "pages") event_handler = TemplateHandler() observer = polling.PollingObserver() observer.schedule(event_handler, path, recursive=True) observer.start() # Keep reference for external control module.observer = observer print("_watch.py: Watching %s.." % path) observer.join() print("_watch.py: Good bye")
def reload_and_rerun_on_module_changes(module: types.ModuleType, session_id): event_handler = events.FileModifiedEvent(module.__file__) def dispatch(event): if event.src_path == module.__file__: importlib.reload(module) rerun(session_id) event_handler.dispatch = dispatch module_directory = pathlib.Path(module.__file__).parent # If a normal observer is used here sometimes there can be a burst # of observations triggered (for example when using VS Code). By # using polling here this effectively debounces the observation # signal. observer = polling.PollingObserver() observer.schedule(event_handler, module_directory, recursive=False) observer.start()
"Could not be removed from the databse. Was it in there to begin with?" ) if __name__ == "__main__": patterns = "*" ignore_patterns = "" ignore_directories = False case_sensitive = True my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive) my_event_handler.on_created = on_created my_event_handler.on_deleted = on_deletion path = PATHTOBEOBSERVED go_recursively = True my_observer = polling.PollingObserver() my_observer.schedule(my_event_handler, path, recursive=go_recursively) my_observer.start() try: while True: time.sleep(0.3) except KeyboardInterrupt: my_observer.stop() my_observer.join()