python script template
#!/usr/bin/env python
"""
Some documentation:
Usage:
-h help
-r results file
"""
# Import libraries
import sys
import getopt
def process(arg):
if arg.endswith(".results"):
print_results(arg)
else:
print arg, "not recognized :'("
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(argv=None):
if argv is None:
argv=sys.argv
try:
# parse command line options
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.error, msg:
raise Usage(msg)
# process options
for o, a in opts:
if o in ("-h", "--help"):
print __doc__
return 0
# process arguments
for arg in args:
process(arg)
except Usage, err:
print >> sys.stderr, err.msg
print >> sys.stderr, "for help use -help"
return 2
if __name__ == "__main__":
sys.exit(main())