Skel.py
Revision as of 18:32, 10 February 2008 by PeterHarding (talk | contribs) (New page: My skeleton Python script... <pre> #!/usr/bin/env python # # Author: Peter Harding <plh@performiq.com.au> # # PerformIQ Pty. Ltd. # Level 6, # ...)
My skeleton Python script...
#!/usr/bin/env python # # Author: Peter Harding <plh@performiq.com.au> # # PerformIQ Pty. Ltd. # Level 6, # 170 Queen Street, # MELBOURNE, VIC, 3000 # # Phone: 03 9641 2222 # Fax: 03 9641 2200 # Mobile: 0418 375 085 # # Copyright (C) PerformIQ Pty Ltd, 1992-2005 # All rights reserved # # @(#) [1.0.01] skel.py 2006-03-07 # # # NAME # skel.py - Sample script # # SYNOPSIS # skel.py [-dv] [-D <DATE>|-S <STARTDATE>|-E <ENDDATE>] # # PARAMETERS # -D <DATE> Date (in ISO format # -d Debug # -v Verbose # # DESCRIPTION # ... # # RETURNS # 0 for successful completion, 1 for any error # # FILES # ... # # $Id:$ # #--------------------------------------------------------------------- """ ... """ #--------------------------------------------------------------------- import sys import getopt #--------------------------------------------------------------------- def is_weekday(dow): if ((dow >= 0) and (dow <=4)): return 1 else: return 0 #--------------------------------------------------------------------- def to_datetime(date): date = int(date) mday = date % 100 month = ( date % 10000) / 100 year = date / 10000 return datetime.date(day=mday, month=month, year=year) #--------------------------------------------------------------------- def main(): global both_flg global check_flg global debug_flg global load_flg global verbose_flg global asxCode global userId global mode if None: try: userId = os.environ['USER'] except: print "***** USER environment variable not set" # sys.exit(0) try: opts, args = getopt.getopt(sys.argv[1:], "bcCdD:E:lS:tvVY?") except getopt.error, msg: print __doc__ return 1 date = None start_date = None end_date = None for o, a in opts: if o == '-?': print __doc__ return 1 elif o == '-b': both_flg = 1 elif o == '-c': mode = CSV elif o == '-C': check_flg = 1 elif o == '-d': debug_flg = 1 elif o == '-D': date = to_datetime(a) elif o == '-E': end_date = to_datetime(a) elif o == '-S': start_date = to_datetime(a) elif o == '-t': mode = TXT elif o == '-Y': date = datetime.date.today() - datetime.timedelta(days=1) elif o == '-l': load_flg = 1 elif o == '-v': verbose_flg = 1 elif o == '-V': print "Version: %s" % __version__ return 1 else: return 1 return 1 #--------------------------------------------------------------------- if __name__ == '__main__' or __name__ == sys.argv[0]: sys.exit(main()) #--------------------------------------------------------------------- """ Revision History: Date Who Description -------- --- -------------------------------------------------- 20030920 plh Initial implementation 20031002 plh Cleaned up args in main(). Added '-h', '-?', '-V' Problems to fix: To Do: Issues: """