Created
August 30, 2012 10:50
-
-
Save abhiomkar/3526178 to your computer and use it in GitHub Desktop.
Python Script Input
This file contains 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
def usage(): | |
""" Script Usage """ | |
print "Usage: python main.py OPTIONS INPUT_FILE [OUTPUT_FILE] " | |
print "OPTIONS:" | |
print " --help, --usage, -h: Show this help message" | |
print " --meta=, -m: Meta File" | |
print "ARGS:" | |
print " INPUT_FILE: input file name or path" | |
print " OUTPUT_FILE: output file path" | |
print "" | |
print "EXAMPLES:" | |
print " python main.py --meta=meta.xml inp.log output.log" | |
print " ./main.py --meta=config.xml cust_inp.log" | |
sys.exit(1) | |
def run(): | |
# Read the Input Options and Arguments | |
try: | |
# options is the string of option letters that the script wants to recognize, with options that require an argument followed by a colon | |
opts, args = getopt.getopt(sys.argv[1:], 'hm:o:', ['meta=', 'output=', 'help', 'usage']) | |
except getopt.GetoptError, err: | |
print str(err) | |
usage() | |
sys.exit(2) | |
output_file_name = None | |
output_file = None | |
for o, v in opts: | |
if o in ['--meta', '-m']: | |
meta_file = v | |
elif o in ['--help', '--usage', '-h']: | |
usage() | |
sys.exit() | |
else: | |
assert False, "Invalid Arguments" | |
usage() | |
sys.exit() | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment