def get_opt(argv):
(opts, args) = getopt.gnu_getopt(argv, 'j:e:t:', ['jobs=', 'env=', 'tags='])
if args:
args = ','.join(args)
raise Exception('non-dashed options "%s" not recognized' % args)
jobs_dir = None
env_vars = []
job_tags = []
for (opt, arg) in opts:
if opt in ['-j', '--jobs']:
jobs_dir = arg
elif opt in ['-e', '--env']:
env_vars = arg.split(',')
elif opt in ['-t', '--tags']:
job_tags = [a for a in arg.split(',') if a]
if not jobs_dir:
raise Exception('at least -j or --jobs must be specified')
return (jobs_dir, job_tags, env_vars)
python类gnu_getopt()的实例源码
def get_opt(argv):
(opts, args) = getopt.gnu_getopt(
argv, 's:r:d:t:', ['source=', 'refspec=', 'destination=', 'timeout=']
)
if args:
args = ','.join(args)
raise Exception('non-dashed options "%s" not recognized' % args)
src = None
dst = None
refspec = None
timeout = 600
for (opt, arg) in opts:
if opt in ['-s', '--source']:
src = arg
elif opt in ['-r', '--refspec']:
refspec = arg
elif opt in ['-d', '--destination']:
dst = arg
elif opt in ['-t', '--timeout']:
timeout = int(arg)
return (src, dst, refspec, timeout)
def get_opt(argv):
(opts, args) = getopt.gnu_getopt(argv, 'j:e:t:', ['jobs=', 'env=', 'tags='])
if args:
args = ','.join(args)
raise Exception('non-dashed options "%s" not recognized' % args)
jobs_dir = None
env_vars = []
job_tags = []
for (opt, arg) in opts:
if opt in ['-j', '--jobs']:
jobs_dir = arg
elif opt in ['-e', '--env']:
env_vars = arg.split(',')
elif opt in ['-t', '--tags']:
job_tags = [a for a in arg.split(',') if a]
if not jobs_dir:
raise Exception('at least -j or --jobs must be specified')
return (jobs_dir, job_tags, env_vars)
def get_opt(argv):
(opts, args) = getopt.gnu_getopt(
argv, 's:r:d:t:', ['source=', 'refspec=', 'destination=', 'timeout=']
)
if args:
args = ','.join(args)
raise Exception('non-dashed options "%s" not recognized' % args)
src = None
dst = None
refspec = None
timeout = 600
for (opt, arg) in opts:
if opt in ['-s', '--source']:
src = arg
elif opt in ['-r', '--refspec']:
refspec = arg
elif opt in ['-d', '--destination']:
dst = arg
elif opt in ['-t', '--timeout']:
timeout = int(arg)
return (src, dst, refspec, timeout)
def __init__(self):
# Since everything in this class is so heavily overloaded, the only
# way of defining and using fields is to access __dict__ directly.
# Dictionary: flag name (string) -> Flag object.
self.__dict__['__flags'] = {}
# Dictionary: module name (string) -> list of Flag objects that are defined
# by that module.
self.__dict__['__flags_by_module'] = {}
# Dictionary: module id (int) -> list of Flag objects that are defined by
# that module.
self.__dict__['__flags_by_module_id'] = {}
# Dictionary: module name (string) -> list of Flag objects that are
# key for that module.
self.__dict__['__key_flags_by_module'] = {}
# Set if we should use new style gnu_getopt rather than getopt when parsing
# the args. Only possible with Python 2.3+
self.UseGnuGetOpt(False)
def parse_args(args, options):
"""Parse arguments from command-line to set options."""
long_opts = ['help', 'oauth', 'followers', 'following', 'api-rate', 'ids']
short_opts = "horgai"
opts, extra_args = getopt(args, short_opts, long_opts)
for opt, arg in opts:
if opt in ('-h', '--help'):
print(__doc__)
raise SystemExit(1)
elif opt in ('-o', '--oauth'):
options['oauth'] = True
elif opt in ('-r', '--followers'):
options['followers'] = True
elif opt in ('-g', '--following'):
options['followers'] = False
elif opt in ('-a', '--api-rate'):
options['api-rate' ] = True
elif opt in ('-i', '--ids'):
options['show_id'] = True
options['extra_args'] = extra_args
def parse_args(query=''):
query = query.split()
dic = {
'isUpdate': False,
'platform': default_platform,
'command': ''
}
try:
opts, args = getopt.gnu_getopt(query, 'uo:')
except:
return dic
for opt, arg in opts:
if opt == '-u':
dic['isUpdate'] = True
elif opt == '-o':
dic['platform'] = arg
dic['command'] = '-'.join(args)
return dic
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def parse_args(args, options):
"""Parse arguments from command-line to set options."""
short_opts = 's:t:m:fp:ih'
long_opts = ['save-dir=', 'timeline=', 'mentions=',
'favorites', 'privatemsg=', 'isoformat', 'help']
opts, extra_args = gnu_getopt(args, short_opts, long_opts)
for opt, arg in opts:
if opt in ('-s', '--save-dir'):
options['save-dir'] = arg
elif opt in ('-t', '--timeline'):
options['timeline'] = arg
elif opt in ('-m', '--mentions'):
options['mentions'] = arg
elif opt in ('-f', '--favorites'):
options['favorites'] = True
elif opt in ('-p', '--privatemsg'):
options['privatemsg'] = arg
elif opt in ('-i', '--isoformat'):
options['isoformat'] = True
elif opt in ('-h', '--help'):
print(__doc__)
sys.exit(0)
options['extra_args'] = extra_args
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'ho', ['help', 'output='])
except getopt.GetoptError:
Usage()
sys.exit(2)
try:
user = args[0]
except:
Usage()
sys.exit(2)
output = None
for o, a in opts:
if o in ("-h", "--help"):
Usage()
sys.exit(2)
if o in ("-o", "--output"):
output = a
FetchTwitter(user, output)
def __init__(self):
# Since everything in this class is so heavily overloaded, the only
# way of defining and using fields is to access __dict__ directly.
# Dictionary: flag name (string) -> Flag object.
self.__dict__['__flags'] = {}
# Dictionary: module name (string) -> list of Flag objects that are defined
# by that module.
self.__dict__['__flags_by_module'] = {}
# Dictionary: module id (int) -> list of Flag objects that are defined by
# that module.
self.__dict__['__flags_by_module_id'] = {}
# Dictionary: module name (string) -> list of Flag objects that are
# key for that module.
self.__dict__['__key_flags_by_module'] = {}
# Set if we should use new style gnu_getopt rather than getopt when parsing
# the args. Only possible with Python 2.3+
self.UseGnuGetOpt(False)
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def __init__(self):
# Since everything in this class is so heavily overloaded, the only
# way of defining and using fields is to access __dict__ directly.
# Dictionary: flag name (string) -> Flag object.
self.__dict__['__flags'] = {}
# Dictionary: module name (string) -> list of Flag objects that are defined
# by that module.
self.__dict__['__flags_by_module'] = {}
# Dictionary: module id (int) -> list of Flag objects that are defined by
# that module.
self.__dict__['__flags_by_module_id'] = {}
# Dictionary: module name (string) -> list of Flag objects that are
# key for that module.
self.__dict__['__key_flags_by_module'] = {}
# Set if we should use new style gnu_getopt rather than getopt when parsing
# the args. Only possible with Python 2.3+
self.UseGnuGetOpt(False)
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# recognize "-" as an argument
opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
self.env["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def parse_args(args, options):
"""Parse arguments from command-line to set options."""
long_opts = ['help', 'oauth', 'followers', 'following', 'api-rate', 'ids']
short_opts = "horgai"
opts, extra_args = getopt(args, short_opts, long_opts)
for opt, arg in opts:
if opt in ('-h', '--help'):
print(__doc__)
raise SystemExit(1)
elif opt in ('-o', '--oauth'):
options['oauth'] = True
elif opt in ('-r', '--followers'):
options['followers'] = True
elif opt in ('-g', '--following'):
options['followers'] = False
elif opt in ('-a', '--api-rate'):
options['api-rate' ] = True
elif opt in ('-i', '--ids'):
options['show_id'] = True
options['extra_args'] = extra_args
def parse_args(args, options):
"""Parse arguments from command-line to set options."""
long_opts = ['help', 'oauth', 'followers', 'following', 'api-rate', 'ids']
short_opts = "horgai"
opts, extra_args = getopt(args, short_opts, long_opts)
for opt, arg in opts:
if opt in ('-h', '--help'):
print(__doc__)
raise SystemExit(1)
elif opt in ('-o', '--oauth'):
options['oauth'] = True
elif opt in ('-r', '--followers'):
options['followers'] = True
elif opt in ('-g', '--following'):
options['followers'] = False
elif opt in ('-a', '--api-rate'):
options['api-rate' ] = True
elif opt in ('-i', '--ids'):
options['show_id'] = True
options['extra_args'] = extra_args
def __init__(self):
# Since everything in this class is so heavily overloaded, the only
# way of defining and using fields is to access __dict__ directly.
# Dictionary: flag name (string) -> Flag object.
self.__dict__['__flags'] = {}
# Dictionary: module name (string) -> list of Flag objects that are defined
# by that module.
self.__dict__['__flags_by_module'] = {}
# Dictionary: module id (int) -> list of Flag objects that are defined by
# that module.
self.__dict__['__flags_by_module_id'] = {}
# Dictionary: module name (string) -> list of Flag objects that are
# key for that module.
self.__dict__['__key_flags_by_module'] = {}
# Set if we should use new style gnu_getopt rather than getopt when parsing
# the args. Only possible with Python 2.3+
self.UseGnuGetOpt(False)
def attach(dname='REDHAWK_DEV', debug=False):
global dom
try :
olist, a= getopt.gnu_getopt(sys.argv,"d:")
d=filter(lambda x: x[0] == '-d', olist )[0]
dname=d[1]
sys.argv=a
except:
pass
print "Attach:"+str(dname)
dom=redhawk.attach(dname )
if debug:
redhawk.setDebug(true)
def attach(dname='REDHAWK_DEV', debug=False):
global dom
try :
olist, a= getopt.gnu_getopt(sys.argv,"d:")
d=filter(lambda x: x[0] == '-d', olist )[0]
dname=d[1]
sys.argv=a
except:
pass
print "Attach:"+str(dname)
dom=redhawk.attach(dname )
if debug:
redhawk.setDebug(true)
def UseGnuGetOpt(self, use_gnu_getopt=True):
"""Use GNU-style scanning. Allows mixing of flag and non-flag arguments.
See http://docs.python.org/library/getopt.html#getopt.gnu_getopt
Args:
use_gnu_getopt: wether or not to use GNU style scanning.
"""
self.__dict__['__use_gnu_getopt'] = use_gnu_getopt
def parse_args(args, options):
"""Parse arguments from command-line to set options."""
long_opts = ['help', 'oauth', 'save-dir=', 'api-rate', 'timeline=', 'mentions=', 'favorites', 'follow-redirects',"redirect-sites=", 'dms=', 'isoformat']
short_opts = "hos:at:m:vfr:d:i"
opts, extra_args = getopt(args, short_opts, long_opts)
for opt, arg in opts:
if opt in ('-h', '--help'):
print(__doc__)
raise SystemExit(0)
elif opt in ('-o', '--oauth'):
options['oauth'] = True
elif opt in ('-s', '--save-dir'):
options['save-dir'] = arg
elif opt in ('-a', '--api-rate'):
options['api-rate' ] = True
elif opt in ('-t', '--timeline'):
options['timeline'] = arg
elif opt in ('-m', '--mentions'):
options['mentions'] = arg
elif opt in ('-v', '--favorites'):
options['favorites'] = True
elif opt in ('-f', '--follow-redirects'):
options['follow-redirects'] = True
elif opt in ('-r', '--redirect-sites'):
options['redirect-sites'] = arg
elif opt in ('-d', '--dms'):
options['dms'] = arg
elif opt in ('-i', '--isoformat'):
options['isoformat'] = True
options['extra_args'] = extra_args
def parse_args(args, options):
long_opts = ['help', 'format=', 'refresh', 'oauth=',
'refresh-rate=', 'config=', 'length=', 'timestamp',
'datestamp', 'no-ssl', 'force-ansi']
short_opts = "e:p:f:h?rR:c:l:td"
opts, extra_args = getopt(args, short_opts, long_opts)
if extra_args and hasattr(extra_args[0], 'decode'):
extra_args = [arg.decode(locale.getpreferredencoding())
for arg in extra_args]
for opt, arg in opts:
if opt in ('-f', '--format'):
options['format'] = arg
elif opt in ('-r', '--refresh'):
options['refresh'] = True
elif opt in ('-R', '--refresh-rate'):
options['refresh_rate'] = int(arg)
elif opt in ('-l', '--length'):
options["length"] = int(arg)
elif opt in ('-t', '--timestamp'):
options["timestamp"] = True
elif opt in ('-d', '--datestamp'):
options["datestamp"] = True
elif opt in ('-?', '-h', '--help'):
options['action'] = 'help'
elif opt in ('-c', '--config'):
options['config_filename'] = arg
elif opt == '--no-ssl':
options['secure'] = False
elif opt == '--oauth':
options['oauth_filename'] = arg
elif opt == '--force-ansi':
options['force-ansi'] = True
if extra_args and not ('action' in options and options['action'] == 'help'):
options['action'] = extra_args[0]
options['extra_args'] = extra_args[1:]
def parse_args(args):
options = {}
short_opts = 'rR:f:l:tdc:h'
long_opts = ['refresh', 'refresh-rate=',
'format=', 'length=', 'timestamp', 'datestamp',
'config=', 'oauth=', 'help', 'invert-split', 'force-ansi']
opts, extra_args = gnu_getopt(args, short_opts, long_opts)
# decode Non-ASCII args for Python 2
if extra_args and hasattr(extra_args[0], 'decode'):
extra_args = [arg.decode(locale.getpreferredencoding()) for arg in extra_args]
for opt, arg in opts:
if opt in ('-r', '--refresh'):
options['refresh'] = True
elif opt in ('-R', '--refresh-rate'):
options['refresh-rate'] = int(arg)
elif opt in ('-f', '--format'):
options['format'] = arg
elif opt in ('-l', '--length'):
options['length'] = int(arg)
elif opt in ('-t', '--timestamp'):
options['timestamp'] = True
elif opt in ('-d', '--datestamp'):
options['datestamp'] = True
elif opt in ('-c', '--config'):
options['config-filename'] = arg
elif opt == '--oauth':
options['oauth-filename'] = arg
elif opt in ('-h', '--help'):
options['action'] = 'help'
elif opt == '--invert-split':
options['invert-split'] = True
elif opt == '--force-ansi':
options['force-ansi'] = True
if extra_args and 'action' not in options:
options['action'] = extra_args[0]
options['extra-args'] = extra_args[1:]
return options
def UseGnuGetOpt(self, use_gnu_getopt=True):
"""Use GNU-style scanning. Allows mixing of flag and non-flag arguments.
See http://docs.python.org/library/getopt.html#getopt.gnu_getopt
Args:
use_gnu_getopt: wether or not to use GNU style scanning.
"""
self.__dict__['__use_gnu_getopt'] = use_gnu_getopt
def parse_parameters(cmd_args, short_option_definition, long_option_definition):
try:
opts, args = getopt.gnu_getopt(cmd_args, short_option_definition, long_option_definition)
except ImportError as e:
print("unable to import python module 'getopt'")
print(e)
sys.exit(-1)
except getopt.GetoptError as e:
print("error when parsing command line arguments")
print(e)
sys.exit(-1)
else:
return opts, args