예제 #1
0
파일: output.py 프로젝트: peterhil/prism
def tail():
    """Simple tail -f like function, that will wait for input"""

    log.info("Using TAIL. Press ^C to quit. For help, see 'prism -h'.")
    gen = tail_generator(
        fileinput.input(sys.argv[1:], bufsize = options.buffer_size),
        grep = options.grep_opt,
        match_only = options.match_opt
    )
    while 1:
        print(next(gen))
예제 #2
0
파일: output.py 프로젝트: peterhil/prism
def watch():
    if not options.use_watchdog:
        log.error("Watchdog not installed.")
        quit()

    fi = fileinput.input(sys.argv[1:], bufsize = options.buffer_size)
    paths = fi._files
    log.info("Using FILEINPUT with WATCHDOG for files: %s" % (', '.join(paths),))

    log.debug("Buffer size: %s" % fi._bufsize)

    event_handler = PrismEventHandler([os.path.abspath(p) for p in paths], watch_output)

    observer = Observer()
    recursive = False

    for p in paths:
        if p == '-' or p == sys.stdin:
            log.error("Can't mix stdin with file arguments. Quitting.")
            quit()
        else:
            if os.path.isdir(p):
                log.info("Watching directory '%s'" % p)
                recursive = True
            else:
                log.info("Will schedule file '%s'" % p)
                recursive = False
            p = os.path.dirname(os.path.abspath(p)) # Watchdog doesn't notify of file changes?
            observer.schedule(event_handler, path=p, recursive=recursive)

    observer.start()
    try:
        while True:
            time.sleep(0.125)
    except KeyboardInterrupt:
        observer.stop()
        quit()
    observer.join()
예제 #3
0
파일: events.py 프로젝트: peterhil/prism
    def on_deleted(self, event):
        super(PrismEventHandler, self).on_deleted(event)

        # TODO handle deletions
        what = 'directory' if event.is_directory else 'file'
        log.info("Deleted %s: %s", what, event.src_path)
예제 #4
0
파일: events.py 프로젝트: peterhil/prism
    def on_moved(self, event):
        super(PrismEventHandler, self).on_moved(event)

        # TODO handle renames
        what = 'directory' if event.is_directory else 'file'
        log.info("Moved %s: from %s to %s", what, event.src_path, event.dest_path)