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())

Filed under  //

Comments [0]

simple bash script template to process a file

#!/bin/bash
 
if [[ "$#" == 1 && -f $1 ]];
then
 # replace with something functional like 'rm -f $1'!
 echo "file $1 exists"
else
 echo "Usage: $0 "
fi

Filed under  //

Comments [0]