X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=bin%2Fmtail.py;h=f5d287c3bc333068a10cb2b8dd85007323d04118;hb=HEAD;hp=41466cfce518909579b0cb0e0a3c87df18f5bb3e;hpb=0f8c747b4f0b71f77d36e89e9d6d869de128c132;p=myplc.git diff --git a/bin/mtail.py b/bin/mtail.py index 41466cf..f5d287c 100755 --- a/bin/mtail.py +++ b/bin/mtail.py @@ -8,12 +8,13 @@ It can be altered to fit other formats too ''' import os, sys, time +import select +import sys, tty, termios + from optparse import OptionParser class mtail: - subversion_id = "$Id$" - default_time_format = "%H:%M:%S" def __init__ (self, args ): @@ -29,7 +30,7 @@ class mtail: usage = """usage: %prog [options] file-or-dir ... example: # %prog -e '*access*' /var/log""" - parser=OptionParser(usage=usage,version=self.subversion_id) + parser=OptionParser(usage=usage) # tail_period parser.add_option("-p","--period", type="int", dest="tail_period", default=1, help="Files check period in seconds") @@ -75,7 +76,6 @@ example: self.args.append("/var/log/httpd/sfa_access_log") if self.options.verbose: - print 'Version:',self.subversion_id print 'Options:',self.options print 'Arguments:',self.args @@ -237,7 +237,8 @@ example: sys.exit(1) counter = 0 - while 1: + fdin = sys.stdin.fileno() + while True: ## hit the period ? # dont do this twice at startup if (counter !=0 and counter % self.options.rescan_period == 0): @@ -248,7 +249,24 @@ example: time.sleep(1) counter += 1 - + # react on some keys - rough but convenient + if os.isatty(fdin): + # read stdin + typed=[] + while select.select([sys.stdin,],[],[],0.0)[0]: + typed.append(sys.stdin.read(1)) +# print 'found chars',typed + for char in typed: + if char.lower() in ['l']: os.system("clear") + elif char.lower() in ['m']: + for i in range(3) : print 60 * '=' + elif char.lower() in ['q']: sys.exit(0) + elif char.lower() in ['h']: + print """l: refresh page +m: mark +q: quit +h: help""" + ### if __name__ == '__main__': mtail (sys.argv[1:]).run()