#!/usr/bin/env python # # Copyright (C) 2003-2011 Upi Tamminen # import os, sys, time, struct, string, getopt OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4 DIR_READ, DIR_WRITE = 1, 2 def playlog(fd, settings): ssize = struct.calcsize(' settings['maxdelay']: sleeptime = settings['maxdelay'] if settings['maxdelay'] > 0: time.sleep(sleeptime) prevtime = curtime sys.stdout.write(data) sys.stdout.flush() elif str(tty) == str(currtty) and op == OP_CLOSE: break def help(brief = 0): print 'Usage: %s [-bfhi] [-m secs] [-w file] \n' % \ os.path.basename(sys.argv[0]) if not brief: print ' -f keep trying to read the log until it\'s closed' print ' -m maximum delay in seconds, to avoid' + \ ' boredom or fast-forward\n' + \ ' to the end. (default is 3.0)' print ' -i show the input stream instead of output' print ' -b show both input and output streams' print ' -h display this help\n' sys.exit(1) if __name__ == '__main__': settings = { 'tail': 0, 'maxdelay': 3.0, 'input_only': 0, 'both_dirs': 0, } try: optlist, args = getopt.getopt(sys.argv[1:], 'fhibm:w:', ['help']) except getopt.GetoptError, error: print 'Error: %s\n' % error help() for o, a in optlist: if o == '-f': settings['tail'] = 1 elif o == '-m': settings['maxdelay'] = float(a) # takes decimals elif o == '-i': settings['input_only'] = 1 elif o == '-b': settings['both_dirs'] = 1 elif o in ['-h', '--help']: help() if len(args) < 1: help() try: logfd = open(args[0], 'rb') except IOError: print "Couldn't open log file!" sys.exit(2) playlog(logfd, settings) # vim: set sw=4: