Beispiel #1
0
def outputlines(fi, grep=False, match_only=False, watch=True):
    try:
        if watch and (fi == '-' or fi == sys.stdin):
            fi = sys.stdin
            while 1:
                try:
                    line = fi.readline()
                    if line:
                        sys.stdout.write(colourise(line, grep, match_only))
                except KeyboardInterrupt:
                    break
        else:
            for line in fi:
                sys.stdout.write(colourise(line, grep, match_only))

    except IOError as e:
        log.error(e)
        quit()
Beispiel #2
0
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()