Commit 8e092c40 by devttys0

Fixed processing of module option type fields

parent 2689a825
...@@ -721,33 +721,43 @@ class Modules(object): ...@@ -721,33 +721,43 @@ class Modules(object):
elif has_key(args, module_option.long) and args[module_option.long] not in [None, False]: elif has_key(args, module_option.long) and args[module_option.long] not in [None, False]:
# TODO: There is one module_option.type for many module_option.kwargs. This means that # Loop through all the kwargs for this command line option
# all kwargs must be of the same type, else errors can happen in the below processing. for (name, default_value) in iterator(module_option.kwargs):
# Fix to check the defined type of each kwarg, and make the module_option.type obsolete.
for (name, value) in iterator(module_option.kwargs): # If this kwarg has not been previously processed, or if its priority is equal to or
# greater than the previously processed kwarg's priority, then let's process it.
if not has_key(last_priority, name) or last_priority[name] <= module_option.priority: if not has_key(last_priority, name) or last_priority[name] <= module_option.priority:
# Track the priority for future iterations that may process the same kwarg name
last_priority[name] = module_option.priority
# If the specified type for these kwargs is None, just set the kwarg to its specified default value.
# Else, set it to the value specified from the user.
if module_option.type is not None: if module_option.type is not None:
value = args[module_option.long] value = args[module_option.long]
else:
value = default_value
last_priority[name] = module_option.priority # Convert the user-supplied value into the type specified in module_option.type.
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values.
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values
try: try:
if module_option.type == int: # Only convert the user-supplied value to a specific type if this kwarg's default
kwargs[name] = int(value, 0) # type is the same as the type specified for the module option.
elif module_option.type == float: if value != default_value and type(default_value) == module_option.type:
kwargs[name] = float(value) if module_option.type == int:
elif module_option.type == dict: kwargs[name] = int(value, 0)
if not has_key(kwargs, name): elif module_option.type == float:
kwargs[name] = {} kwargs[name] = float(value)
kwargs[name][len(kwargs[name])] = value elif module_option.type == dict:
elif module_option.type == list: if not has_key(kwargs, name):
if not has_key(kwargs, name): kwargs[name] = {}
kwargs[name] = [] kwargs[name][len(kwargs[name])] = value
# HACK. Fix the above TODO and this check is no longer necessary elif module_option.type == list:
if type(kwargs[name]) == list: if not has_key(kwargs, name):
kwargs[name] = []
kwargs[name].append(value) kwargs[name].append(value)
else:
kwargs[name] = value
else: else:
kwargs[name] = value kwargs[name] = value
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment