Created
December 31, 2011 11:55
-
-
Save colwilson/1543783 to your computer and use it in GitHub Desktop.
python main file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## {{{ http://code.activestate.com/recipes/528877/ (r5) | |
#!/usr/bin/env python | |
""" | |
SYNOPSIS | |
TODO helloworld [-h,--help] [-v,--verbose] [--version] | |
DESCRIPTION | |
TODO This describes how to use this script. This docstring | |
will be printed by the script if there is an error or | |
if the user requests help (-h or --help). | |
EXAMPLES | |
TODO: Show some examples of how to use this script. | |
EXIT STATUS | |
TODO: List exit codes | |
AUTHOR | |
TODO: Name <[email protected]> | |
LICENSE | |
This script is in the public domain, free from copyrights or restrictions. | |
VERSION | |
$Id$ | |
""" | |
import sys, os, traceback, optparse | |
import time | |
import re | |
#from pexpect import run, spawn | |
def main (): | |
global options, args | |
# TODO: Do something more interesting here... | |
print 'Hello world!' | |
if __name__ == '__main__': | |
try: | |
start_time = time.time() | |
parser = optparse.OptionParser(formatter=optparse.TitledHelpFormatter(), usage=globals()['__doc__'], version='$Id$') | |
parser.add_option ('-v', '--verbose', action='store_true', default=False, help='verbose output') | |
(options, args) = parser.parse_args() | |
#if len(args) < 1: | |
# parser.error ('missing argument') | |
if options.verbose: print time.asctime() | |
main() | |
if options.verbose: print time.asctime() | |
if options.verbose: print 'TOTAL TIME IN MINUTES:', | |
if options.verbose: print (time.time() - start_time) / 60.0 | |
sys.exit(0) | |
except KeyboardInterrupt, e: # Ctrl-C | |
raise e | |
except SystemExit, e: # sys.exit() | |
raise e | |
except Exception, e: | |
print 'ERROR, UNEXPECTED EXCEPTION' | |
print str(e) | |
traceback.print_exc() | |
os._exit(1) | |
## end of http://code.activestate.com/recipes/528877/ }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment