Example #1
0
        ln_duration=args.ln_duration,
    )
    observer = Observer()
    observer.schedule(handler, path=args.source, recursive=args.recursive)
    observer.start()

    if args.sort_old:
        if args.recursive:
            files_to_sort = [
                os.path.join(dp, f)
                for dp, dn, fn in os.walk(os.path.expanduser(args.source))
                for f in fn
            ]
        else:
            files_to_sort = [
                os.path.join(args.source, f)
                for f in os.listdir(os.path.expanduser(args.source))
            ]
            files_to_sort = [f for f in files_to_sort if os.path.isfile(f)]
        event_cls = collections.namedtuple("Event", ("src_path"))

        for f in files_to_sort:
            handler.on_modified(event_cls(f))

    try:
        while True:
            time.sleep(10)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()