From 22860099ba9a1665fccc306472bda00cee07cb6b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 17 Apr 2014 18:47:48 +0200 Subject: [PATCH] report/generate.py: corrections --- report/generate.py | 4 +-- tiramisu/option/__init__.py | 12 +++---- tiramisu/option/masterslave.py | 64 ++++++++++++++++++++-------------- tiramisu/value.py | 7 ++++ 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/report/generate.py b/report/generate.py index 56a15c7..ade3547 100644 --- a/report/generate.py +++ b/report/generate.py @@ -61,9 +61,9 @@ def opt_rst_content(path, prefix, descr, value): content.add(ListItem().join(Strong("path:"), Text(path))) content.add(ListItem().join(Strong("parent config:"), Text(prefix))) if isinstance(descr, ChoiceOption): - content.add(ListItem().join(Strong("possible values:"), Text(str(descr._values)))) + content.add(ListItem().join(Strong("possible values:"), Text(str(descr.impl_get_values())))) if not isinstance(descr, SymLinkOption): - content.add(ListItem().join(Strong("mime type:"), Text(str(descr._opt_type)))) + content.add(ListItem().join(Strong("mime type:"), Text(str(descr.__class__.__name__)))) content.add(ListItem().join(Strong("default value:"), Text(str(descr.impl_getdefault())))) content.add(ListItem().join(Strong("description:"), Text(str(descr.impl_get_information('doc'))))) content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires)))) diff --git a/tiramisu/option/__init__.py b/tiramisu/option/__init__.py index 1a325f8..3be1c50 100644 --- a/tiramisu/option/__init__.py +++ b/tiramisu/option/__init__.py @@ -8,9 +8,9 @@ from .option import (ChoiceOption, BoolOption, IntOption, FloatOption, FilenameOption) -__all__ = (MasterSlaves, OptionDescription, Option, SymLinkOption, - ChoiceOption, BoolOption, IntOption, FloatOption, - StrOption, UnicodeOption, IPOption, PortOption, - NetworkOption, NetmaskOption, BroadcastOption, - DomainnameOption, EmailOption, URLOption, UsernameOption, - FilenameOption) +__all__ = ('MasterSlaves', 'OptionDescription', 'Option', 'SymLinkOption', + 'ChoiceOption', 'BoolOption', 'IntOption', 'FloatOption', + 'StrOption', 'UnicodeOption', 'IPOption', 'PortOption', + 'NetworkOption', 'NetmaskOption', 'BroadcastOption', + 'DomainnameOption', 'EmailOption', 'URLOption', 'UsernameOption', + 'FilenameOption') diff --git a/tiramisu/option/masterslave.py b/tiramisu/option/masterslave.py index 4298cc7..7a9057f 100644 --- a/tiramisu/option/masterslave.py +++ b/tiramisu/option/masterslave.py @@ -89,33 +89,45 @@ class MasterSlaves(object): def getitem(self, values, opt, path, validate, force_permissive, force_properties, validate_properties): if opt == self.master: - value = values._get_validated_value(opt, path, validate, - force_permissive, - force_properties, - validate_properties) - if validate is True: - masterlen = len(value) - for slave in self.slaves: - try: - slave_path = values._get_opt_path(slave) - slave_value = values._get_validated_value(slave, - slave_path, - False, - False, - None, False, - None) # not undefined - slavelen = len(slave_value) - self.validate_slave_length(masterlen, slavelen, slave._name) - except ConfigError: - pass - return value + return self._getmaster(values, opt, path, validate, + force_permissive, force_properties, + validate_properties) else: - value = values._get_validated_value(opt, path, validate, - force_permissive, - force_properties, - validate_properties, - None) # not undefined - return self.get_slave_value(values, opt, value, validate, validate_properties) + return self._getslave(values, opt, path, validate, + force_permissive, force_properties, + validate_properties) + + def _getmaster(self, values, opt, path, validate, force_permissive, + force_properties, validate_properties): + value = values._get_validated_value(opt, path, validate, + force_permissive, + force_properties, + validate_properties) + if validate is True: + masterlen = len(value) + for slave in self.slaves: + try: + slave_path = values._get_opt_path(slave) + slave_value = values._get_validated_value(slave, + slave_path, + False, + False, + None, False, + None) # not undefined + slavelen = len(slave_value) + self.validate_slave_length(masterlen, slavelen, slave._name) + except ConfigError: + pass + return value + + def _getslave(self, values, opt, path, validate, force_permissive, + force_properties, validate_properties): + value = values._get_validated_value(opt, path, validate, + force_permissive, + force_properties, + validate_properties, + None) # not undefined + return self.get_slave_value(values, opt, value, validate, validate_properties) def setitem(self, values, opt, value, path): if opt == self.master: diff --git a/tiramisu/value.py b/tiramisu/value.py index 4700e8e..99467f2 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -508,6 +508,13 @@ class Multi(list): self._getcontext().cfgimpl_get_values()._setvalue(self.opt, self.path, self) + def __repr__(self, *args, **kwargs): + print args, kwargs + return super(Multi, self).__repr__(*args, **kwargs) + + def __getitem__(self, y): + return super(Multi, self).__getitem__(y) + def append(self, value=undefined, force=False, setitem=True): """the list value can be updated (appened) only if the option is a master