def main(): config = args.parse() say_hello() print('cli arguments as understood:\n') pprint(config, indent=2) print('\n\n') # dry run if config['dry'] is True: dry_run(config['dry_opts']) # real run elif len(config['watchers']): YOUTUBE_FILENAME_PATTERN = "(.*\\/)?([a-zA-Z0-9\\_\\-]{10,})\\.(mp3|m4a)$" watcher = Watcher() for watcher_config in config['watchers']: rc_json = get_configuration_from_file(watcher_config['rc_filename']) on_event = ConditionalFileEventHandler( both(is_moved_event, partial(filename_matches, YOUTUBE_FILENAME_PATTERN)), partial(on_youtube_music_file, rc_json=rc_json, watcher_config=watcher_config) ) watcher.schedule(on_event, watcher_config['watch'], recursive=config['recursive']) watcher.start() try: while True: time.sleep(1) except KeyboardInterrupt: if watcher is not None: watcher.stop() # inconsistent state else: raise ValueError('ValueError: Program should be run with either the --dry flag or with some --watch and --out values')
def main(): prs = argparse.ArgumentParser(description='Generate the website anew.') prs.add_argument('-c', '--conf', type=str, default="example_configuration.yml", dest='conf_path', help='Path to the configuration file.') args = prs.parse_args() conf = yaml.load(open(args.conf_path, 'r').read()) task_manager = pst.Tasker(conf) watcher = Watcher(task_manager) watcher.start() try: while True: time.sleep(1) except KeyboardInterrupt: watcher.stop() watcher.join()
class Scanner: def __init__(self, path): self.path = path self.queue = Queue.PriorityQueue() self.watcher = Watcher(path, self.queue) self.walker = Walker(path, self.queue, Settings.is_rescan_forced()) self.reader = Reader(self.queue) self.validator = Validator(self.queue) def start(self): self.validator.start() self.watcher.start() self.walker.start() self.reader.start() def stop(self): self.watcher.stop() self.reader.stop() self.validator.join() self.walker.join() self.watcher.join() self.reader.join()
def stop(self): self.gui = None Watcher.stop(self)
from watcher import Watcher import time def printer(x): print(x) ob = Watcher('./models', printer) try: while True: time.sleep(1) except KeyboardInterrupt: ob.stop()