Skip to content
Snippets Groups Projects
Commit 615dad81 authored by graeser's avatar graeser Committed by graeser@FU-BERLIN.DE
Browse files

Add help on usage.

Notice that you must supply a - argument to read  from std:in now.
Otherwise you will get an error.

[[Imported from SVN: r3335]]
parent ec95a032
No related branches found
No related tags found
No related merge requests found
...@@ -153,19 +153,54 @@ class PeriodicActionThread (threading.Thread): ...@@ -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): def main(args):
try: 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: except getopt.GetoptError, err:
# print help information and exit: # print help information and exit:
print str(err) # will print something like "option -a not recognized" print str(err) # will print something like "option -a not recognized"
# usage() print ''
usage()
sys.exit(2) sys.exit(2)
# input file (default: stdin) for (o, a) in opts:
infile = sys.stdin if o in ("--help",):
usage()
return
# timeout to clear buffer and view items (default: 0.1s) # timeout to clear buffer and view items (default: 0.1s)
timeout = 0.1 timeout = 0.1
...@@ -185,11 +220,22 @@ def main(args): ...@@ -185,11 +220,22 @@ def main(args):
# switch to determine if view follows appended lines (default: True) # switch to determine if view follows appended lines (default: True)
follow = True follow = True
if (len(args)>0): if (len(args)==1):
if (args[0]=='-'): if (args[0]=='-'):
infile = sys.stdin infile = sys.stdin
else: 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: for (o, a) in opts:
if o in ("-t", "--timeout"): if o in ("-t", "--timeout"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment