Merge branch 'master' of ssh://git.labs.libre-entreprise.org/gitroot/tiramisu
authorgwen <gremond@cadoles.com>
Wed, 4 Sep 2013 07:05:25 +0000 (09:05 +0200)
committergwen <gremond@cadoles.com>
Wed, 4 Sep 2013 07:05:25 +0000 (09:05 +0200)
1  2 
tiramisu/option.py

diff --combined tiramisu/option.py
@@@ -97,8 -97,7 +97,8 @@@ class BaseOption(object)
          "frozen" (which has noting to do with the high level "freeze"
          propertie or "read_only" property)
          """
 -        if not name.startswith('_state') and name not in ('_cache_paths', '_consistencies'):
 +        if not name.startswith('_state') and \
 +           name not in ('_cache_paths', '_consistencies'):
              is_readonly = False
              # never change _name
              if name == '_name':
                  consistencies = self._state_consistencies
              else:
                  consistencies = self._consistencies
-             new_value = []
-             for consistency in consistencies:
-                 if load:
-                     new_value.append((consistency[0],
-                                       descr.impl_get_opt_by_path(
-                                           consistency[1])))
-                 else:
-                     new_value.append((consistency[0],
-                                       descr.impl_get_path_by_opt(
-                                           consistency[1])))
+             if isinstance(consistencies, list):
+                 new_value = []
+                 for consistency in consistencies:
+                     if load:
+                         new_value.append((consistency[0],
+                                           descr.impl_get_opt_by_path(
+                                               consistency[1])))
+                     else:
+                         new_value.append((consistency[0],
+                                           descr.impl_get_path_by_opt(
+                                               consistency[1])))
+             else:
+                 new_value = {}
+                 for key, _consistencies in consistencies.items():
+                     new_value[key] = []
+                     for key_cons, _cons in _consistencies:
+                         _list_cons = []
+                         for _con in _cons:
+                             if load:
+                                 _list_cons.append(descr.impl_get_opt_by_path(_con))
+                             else:
+                                 _list_cons.append(descr.impl_get_path_by_opt(_con))
+                         new_value[key].append((key_cons, tuple(_list_cons)))
              if load:
                  del(self._state_consistencies)
-                 self._consistencies = tuple(new_value)
+                 self._consistencies = new_value
              else:
-                 self._state_consistencies = tuple(new_value)
+                 self._state_consistencies = new_value
  
      def _impl_convert_requires(self, descr, load=False):
 +        """export of the requires during the serialization process
 +
 +        :type descr: :class:`tiramisu.option.OptionDescription`
 +        :param load: `True` if we are at the init of the option description
 +        :type load: bool
 +        """
          if not load and self._requires is None:
              self._state_requires = None
          elif load and self._state_requires is None:
          try:
              self._stated
          except AttributeError:
 -            raise SystemError(_('cannot serialize Option, only in OptionDescription'))
 +            raise SystemError(_('cannot serialize Option, '
 +                                'only in OptionDescription'))
          slots = set()
          for subclass in self.__class__.__mro__:
              if subclass is not object:
          slots -= frozenset(['_cache_paths', '__weakref__'])
          states = {}
          for slot in slots:
 -            # remove variable if save variable converted in _state_xxxx variable
 +            # remove variable if save variable converted
 +            # in _state_xxxx variable
              if '_state' + slot not in slots:
                  if slot.startswith('_state'):
                      # should exists
  
      # unserialize
      def _impl_setstate(self, descr):
 +        """the under the hood stuff that need to be done
 +        before the serialization.
 +
 +        :type descr: :class:`tiramisu.option.OptionDescription`
 +        """
          self._impl_convert_consistencies(descr, load=True)
          self._impl_convert_requires(descr, load=True)
          try:
              pass
  
      def __setstate__(self, state):
 +        """special method that enables us to serialize (pickle)
 +
 +        Usualy, a `__setstate__` method does'nt need any parameter,
 +        but somme under the hood stuff need to be done before this action
 +
 +        :parameter state: a dict is passed to the loads, it is the attributes
 +                          of the options object
 +        :type state: dict
 +        """
          for key, value in state.items():
              setattr(self, key, value)
  
@@@ -307,8 -298,8 +321,8 @@@ class Option(BaseOption)
  
      Reminder: an Option object is **not** a container for the value
      """
 -    __slots__ = ('_multi', '_validator', '_default_multi', '_default', '_callback',
 -                 '_multitype', '_master_slaves', '__weakref__')
 +    __slots__ = ('_multi', '_validator', '_default_multi', '_default',
 +                 '_callback', '_multitype', '_master_slaves', '__weakref__')
      _empty = ''
  
      def __init__(self, name, doc, default=None, default_multi=None,
@@@ -644,8 -635,10 +658,10 @@@ else
  
  
  class SymLinkOption(BaseOption):
-     __slots__ = ('_name', '_opt', '_state_opt')
+     __slots__ = ('_name', '_opt', '_state_opt', '_consistencies')
      _opt_type = 'symlink'
+     #not return _opt consistencies
+     _consistencies = {}
  
      def __init__(self, name, opt):
          self._name = name
          del(self._state_opt)
          super(SymLinkOption, self)._impl_setstate(descr)
  
+     def _impl_convert_consistencies(self, descr, load=False):
+         if load:
+             del(self._state_consistencies)
+         else:
+             self._state_consistencies = None
  
  class IPOption(Option):
      "represents the choice of an ip"