diff --git a/bin/hierarchicviewer.py b/bin/hierarchicviewer.py index c386f03016f43bc408ac5a456fc0085347d0cbbe..50e792db4a2237de13fab26a6cfe617e438c1501 100644 --- a/bin/hierarchicviewer.py +++ b/bin/hierarchicviewer.py @@ -153,19 +153,54 @@ class PeriodicActionThread (threading.Thread): +def usage(): + print 'SYNOPSIS' + print ' python hierarchicviewer.py [OPTIONS] FILE' + print ' python hierarchicviewer.py [OPTIONS] -' + print '' + print 'DESCRIPTION' + print ' If FILE was given view content of file in a hierarchic view.' + print ' If - is given view standard input in a hierarchic view.' + print ' Input should contain UP and DOWN indicators that indicate' + print ' to switch the level in the output hierarchy correspondingly.' + print '' + print ' --help' + print ' View this help text.' + print '' + print ' -u REGEX , --up=REGEX' + print ' Lines matching REGEX are considered as indicator to switch' + print ' up in the hierarchy. (default: \'^ *\\}\')' + print '' + print ' -d REGEX , --down=REGEX' + print ' Lines matching REGEX are considered as indicator to switch' + print ' down in the hierarchy. (default: \'^ *\\{\')' + print '' + print ' -h, --hideupdown' + print ' Hide lines that contain UP or DOWN indicators in the output.' + print '' + print ' -n, --nofollow' + print ' If supplied the view does not follow if new lines are appended.' + print '' + print ' -t TIMEOUT, --timeout=TIMEOUT' + print ' The input buffer it cleared periodically and added to the' + print ' hierarchic view after TIMEOUT seconds. (default: 0.1)' + def main(args): try: - (opts, args) = getopt.getopt(sys.argv[1:], "t:u:d:hn", ["timeout=", "up=", "down=", "hideupdown", "nofollow", "noappend"]) + (opts, args) = getopt.getopt(sys.argv[1:], "t:u:d:hn", ["timeout=", "up=", "down=", "hideupdown", "nofollow", "noappend", "help"]) except getopt.GetoptError, err: # print help information and exit: print str(err) # will print something like "option -a not recognized" -# usage() + print '' + usage() sys.exit(2) - # input file (default: stdin) - infile = sys.stdin + for (o, a) in opts: + if o in ("--help",): + usage() + return # timeout to clear buffer and view items (default: 0.1s) timeout = 0.1 @@ -185,11 +220,22 @@ def main(args): # switch to determine if view follows appended lines (default: True) follow = True - if (len(args)>0): + if (len(args)==1): if (args[0]=='-'): infile = sys.stdin else: - infile = file(sys.argv[1], 'r') + try: + infile = file(args[0], 'r') + except IOError: + print 'Could not open file:', args[0] + print '' + usage() + sys.exit(2) + else: + print 'You did not supply a file or the - argument.' + print '' + usage() + sys.exit(2) for (o, a) in opts: if o in ("-t", "--timeout"):