list is Multi now which enables us to implement item access
authorgwen <gremond@cadoles.com>
Wed, 11 Jul 2012 14:47:07 +0000 (16:47 +0200)
committergwen <gremond@cadoles.com>
Wed, 11 Jul 2012 14:47:07 +0000 (16:47 +0200)
config.py
option.py
tool.py

index ad4e7fc..1a8f0b3 100644 (file)
--- a/config.py
+++ b/config.py
@@ -25,7 +25,7 @@ from error import (HiddenOptionError, ConfigError, NotFoundError,
                             SpecialOwnersError, MandatoryError, MethodCallError, 
                                            DisabledOptionError, ModeOptionError)
 from option import (OptionDescription, Option, SymLinkOption, group_types, 
-                                                          apply_requires, modes)
+                                                   Multi, apply_requires, modes)
 import autolib
 from autolib import special_owners, special_owner_factory
 # ____________________________________________________________
@@ -65,8 +65,14 @@ class Config(object):
         self._validate_duplicates(self._cfgimpl_descr._children)
         for child in self._cfgimpl_descr._children:
             if isinstance(child, Option):
-                self._cfgimpl_values[child._name] = child.getdefault()
-                self._cfgimpl_previous_values[child._name] = child.getdefault()
+                if child.is_multi():
+                    mm = Multi(child.getdefault())
+                    self._cfgimpl_values[child._name] = mm
+                    self._cfgimpl_previous_values[child._name] = mm
+                else:
+                    dd = child.getdefault()
+                    self._cfgimpl_values[child._name] = dd
+                    self._cfgimpl_previous_values[child._name] = dd 
                 if child.getcallback() is not None:
                     if child._is_hidden():
                         self._cfgimpl_value_owners[child._name] = 'auto'
index 3493200..4105420 100644 (file)
--- a/option.py
+++ b/option.py
@@ -30,7 +30,19 @@ reverse_actions = {'hide': 'show', 'show': 'hide',
 # ____________________________________________________________
 # OptionDescription authorized group_type values
 group_types = ['default', 'family', 'group', 'master']
+# multi types 
+class Multi(list):
+    "wrapper for list (multi) option types"
+    def __getitem__(self, key):
+        # FIXME test if None, etc...
+        return super(Multi, self).__getitem__(key)
+#        return list.__getitem__(self, key)
+
+    def __setitem__(self, key, value):
+        # FIXME  do some stuff here
+        return super(Multi, self).__setitem__(key, value)
 # ____________________________________________________________
+
 class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
     #reminder: an Option object is **not** a container for the value
     _frozen = False
@@ -65,7 +77,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
         if self.multi == True:
             if default == None:
                 default = []
-            if type(default) != list or not self.validate(default):
+            if not isinstance(default, list) or not self.validate(default):
                 raise ConfigError("invalid default value {0} "
                 "for option {1} : not list type".format(str(default), name))
         else:
@@ -80,7 +92,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
             if value != None:
                 return self._validate(value)
         else:
-            if type(value) != list:
+            if not isinstance(value, list): 
                 raise ConfigError("invalid value {0} " 
                         "for option {1} which must be a list".format(value,
                         self._name))
diff --git a/tool.py b/tool.py
index 2291849..9a31c45 100644 (file)
--- a/tool.py
+++ b/tool.py
@@ -36,7 +36,7 @@ def reverse_from_paths(data):
     }
     def option_factory(name, value):
         "dummy -> Option('dummy')"
-        if type(value) == list:
+        if isinstance(value, list):
             return _build_map[type(value[0])](name, '', multi=True, default=value)
         else:            
             return _build_map[type(value)](name, '', default=value)