Skel.py
Revision as of 13:54, 29 February 2008 by PeterHarding (talk | contribs)
My skeleton Python script...
Version
#!/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: """
Another Version
#!/usr/bin/env python # # Author: Peter Harding <plh@pha.com.au> # Peter Harding & Associates Pty. Ltd. # Level 6, # 170 Queen Street, # MELBOURNE, VIC, 3000 # # Phone: 03 9641 2222 # Fax: 03 9641 2200 # Mobile: 0418 375 085 # # Purpose: Skeleton python script # # # Copyright (C) Peter Harding, 2003 # All rights reserved # # $Id: skel.py,v 1.1.1.1 2003/10/22 11:57:35 zyx Exp $ # #--------------------------------------------------------------------- """ Skeleton Python Framework Usage: skel.py -g <no> -v The '-g <no>' option is used to specify the number of groups. The '-v' turns on verbose mode. """ #--------------------------------------------------------------------- import os import sys import getopt import string import whrandom #--------------------------------------------------------------------- __version__ = "1.0.0" wrk = None no = None #--------------------------------------------------------------------- def process(): pass #--------------------------------------------------------------------- def main(): global debugFlg global no global verboseFlg try: opts, args = getopt.getopt(sys.argv[1:], "dg:vV?") except getopt.error, msg: print __doc__, return 1 for o, a in opts: if o == '-d': debugFlg = 1 elif o == '-g': no = int(a) elif o == '-v': verboseFlg = 1 elif o == '-V': print "Version: %s" % __version__ return 0 elif o == '-?': print __doc__() return 0 if args: for arg in args: process arg global wrk wrk = os.getcwd() process() #--------------------------------------------------------------------- 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: """