Additions:
see [[http://code.google.com/p/klenwell/source/browse/trunk/projects/python/boilerplate/getopt.py getopt.py]]
Deletions:
Additions:
see [[http://code.google.com/p/klenwell/source/browse/trunk/projects/python/boilerplate/getopt.py?spec=svn283&r=283 getopt.py]]
Additions:
klenwell@local:~/tmp $ python parseopt.py -a ok -rn two args
Deletions:
Additions:
import sys, getopt
"""
add usage text here
"""
'args' : [],
'not_required' : False, # n
optlist, args = getopt.getopt(args, 'a:nr', ['foo='])
sys.stderr.write(parse_command_line.__doc__)
elif opt == '-n':
optdict['not_required'] = True
optdict['args'] = args
if not optdict['arg_required'] or not optdict['required']:
f = "\n\t-a=<val> and -r parameters required to run\n%s\n"
sys.stderr.write(f % (parse_command_line.__doc__))
optdict = parse_command_line()
print optdict
# example
klenwell@local:~/qed/fatrook $ python /home/klenwell/tmp/parseopt.py -a ok -rn two args
{'arg_required': 'ok', 'foo': 'bar', 'args': ['two', 'args'], 'not_required': True, 'required': True}
"""
add usage text here
"""
'args' : [],
'not_required' : False, # n
optlist, args = getopt.getopt(args, 'a:nr', ['foo='])
sys.stderr.write(parse_command_line.__doc__)
elif opt == '-n':
optdict['not_required'] = True
optdict['args'] = args
if not optdict['arg_required'] or not optdict['required']:
f = "\n\t-a=<val> and -r parameters required to run\n%s\n"
sys.stderr.write(f % (parse_command_line.__doc__))
optdict = parse_command_line()
print optdict
# example
klenwell@local:~/qed/fatrook $ python /home/klenwell/tmp/parseopt.py -a ok -rn two args
{'arg_required': 'ok', 'foo': 'bar', 'args': ['two', 'args'], 'not_required': True, 'required': True}
Deletions:
"""add usage text here"""
'verbose' : False, # v
optlist, list = getopt.getopt(args, 'r:v', ['foo='])
sys.stderr.write(parse_commandline.__doc__)
elif opt == '-v':
optdict['verbose'] = True
if not optdict['required']:
sys.stderr.write('-r parameter required to run')
sys.stderr.write(parse_commandline.__doc__)
optdict = parse_commandline()
Additions:
def parse_command_line():
"""add usage text here"""
optdict = {
'arg_required' : False, # a:
'required' : False, # r
'verbose' : False, # v
'foo' : 'bar', # foo=
optlist, list = getopt.getopt(args, 'r:v', ['foo='])
optdict['foo'] = val
optdict['verbose'] = True
elif opt == '-a':
optdict['arg_required'] = val
optdict['required'] = True
if not optdict['required']:
return optdict
optdict = parse_commandline()
"""add usage text here"""
optdict = {
'arg_required' : False, # a:
'required' : False, # r
'verbose' : False, # v
'foo' : 'bar', # foo=
optlist, list = getopt.getopt(args, 'r:v', ['foo='])
optdict['foo'] = val
optdict['verbose'] = True
elif opt == '-a':
optdict['arg_required'] = val
optdict['required'] = True
if not optdict['required']:
return optdict
optdict = parse_commandline()
Deletions:
""" You can add usage text here """
OptionDict = {
'arg_required' : False # a:
'required' : False # r
'verbose' : False # v
'foo' : 'bar' # foo=
optlist, list = getopt.getopt(
args, 'r:v', ['foo='])
OptionDict['foo'] = val
OptionDict['verbose'] = True
OptionDict['arg_required'] = val
OptionDict['required'] = True
if not OptionDict['required']:
return OptionDict
CommandOpt = parse_commandline()
Additions:
# output
2.1.6-beta0
2.1.6-beta0
Additions:
python -c <command>
Deletions:
Additions:
====python from command line====
''python -c <command>''
# Example to check version of pyodbc module installed
$ python -c "import pyodbc; print pyodbc.version"
''python -c <command>''
# Example to check version of pyodbc module installed
$ python -c "import pyodbc; print pyodbc.version"
Additions:
sys.stderr.write('-r parameter required to run')
Deletions:
sys.stderr.write(parse_commandline.__doc__)
Additions:
OptionDict['required'] = True
Deletions:
Additions:
'arg_required' : False # a:
'required' : False # r
'verbose' : False # v
'foo' : 'bar' # foo=
OptionDict['arg_required'] = val
OptionDict['required'] = True
if not OptionDict['required']:
sys.stderr.write('-r parameter required to run')
sys.stderr.write(parse_commandline.__doc__)
'required' : False # r
'verbose' : False # v
'foo' : 'bar' # foo=
OptionDict['arg_required'] = val
OptionDict['required'] = True
if not OptionDict['required']:
sys.stderr.write('-r parameter required to run')
sys.stderr.write(parse_commandline.__doc__)
Deletions:
'verbose' : False # v
'foo' : 'bar' # foo=
OptionDict['required'] = True