implement configurable default values for parameters
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
1927d4852a
commit
fc40a40ae0
2 changed files with 21 additions and 2 deletions
|
@ -62,6 +62,7 @@ class CdistType(object):
|
|||
self.__optional_parameters = None
|
||||
self.__optional_multiple_parameters = None
|
||||
self.__boolean_parameters = None
|
||||
self.__parameter_defaults = None
|
||||
|
||||
@classmethod
|
||||
def list_types(cls, base_path):
|
||||
|
@ -190,3 +191,19 @@ class CdistType(object):
|
|||
finally:
|
||||
self.__boolean_parameters = parameters
|
||||
return self.__boolean_parameters
|
||||
|
||||
@property
|
||||
def parameter_defaults(self):
|
||||
if not self.__parameter_defaults:
|
||||
defaults = {}
|
||||
try:
|
||||
defaults_dir = os.path.join(self.absolute_path, "parameter", "default")
|
||||
for name in os.listdir(defaults_dir):
|
||||
with open(os.path.join(defaults_dir, name)) as fd:
|
||||
defaults[name] = fd.read().strip()
|
||||
except EnvironmentError:
|
||||
# error ignored
|
||||
pass
|
||||
finally:
|
||||
self.__parameter_defaults = defaults
|
||||
return self.__parameter_defaults
|
||||
|
|
|
@ -96,10 +96,12 @@ class Emulator(object):
|
|||
parser.add_argument(argument, dest=parameter, action='append', required=True)
|
||||
for parameter in self.cdist_type.optional_parameters:
|
||||
argument = "--" + parameter
|
||||
parser.add_argument(argument, dest=parameter, action='store', required=False)
|
||||
parser.add_argument(argument, dest=parameter, action='store', required=False,
|
||||
default=self.cdist_type.parameter_defaults.get(parameter, None))
|
||||
for parameter in self.cdist_type.optional_multiple_parameters:
|
||||
argument = "--" + parameter
|
||||
parser.add_argument(argument, dest=parameter, action='append', required=False)
|
||||
parser.add_argument(argument, dest=parameter, action='append', required=False,
|
||||
default=self.cdist_type.parameter_defaults.get(parameter, None))
|
||||
for parameter in self.cdist_type.boolean_parameters:
|
||||
argument = "--" + parameter
|
||||
parser.add_argument(argument, dest=parameter, action='store_const', const='')
|
||||
|
|
Loading…
Reference in a new issue