better support for setowner
authorEmmanuel Garette <egarette@cadoles.com>
Wed, 9 Mar 2016 14:48:14 +0000 (15:48 +0100)
committerEmmanuel Garette <egarette@cadoles.com>
Wed, 9 Mar 2016 14:48:14 +0000 (15:48 +0100)
tiramisu/storage/dictionary/option.py
tiramisu/storage/dictionary/value.py
tiramisu/value.py

index 3ed9ec8..d3187c4 100644 (file)
@@ -540,13 +540,3 @@ class StorageOptionDescription(StorageBase):
             raise AttributeError(_('unknown Option {0} '
                                    'in OptionDescription {1}'
                                    '').format(name, self.impl_getname()))
-
-    def _get_force_store_value(self):
-        #FIXME faire des tests (notamment pas ajouter à un config)
-        #FIXME devrait faire un cache !
-        opts, paths = self._cache_paths
-        for index in range(0, len(paths)):
-            opt = opts[index]
-            path = paths[index]
-            if 'force_store_value' in opt._properties:
-                yield (opt, path)
index 202889d..cb7baf1 100644 (file)
@@ -31,6 +31,36 @@ class Values(Cache):
         # should init cache too
         super(Values, self).__init__(storage)
 
+    def _setvalue_info(self, nb, idx, value, values, index, vidx):
+        lst = list(self._values[nb])
+        if idx is None:
+            if index is None or nb == 0:
+                lst.append(value)
+            else:
+                lst.append((value,))
+        else:
+            if index is None or nb == 0:
+                lst[idx] = value
+            else:
+                if nb == 1:
+                    if index in lst[idx]:
+                        vidx = lst[idx].index(index)
+                    else:
+                        vidx = None
+                if vidx is None:
+                    tval = list(lst[idx])
+                    tval.append(value)
+                    lst[idx] = tuple(tval)
+                elif nb != 1:
+                    tval = list(lst[idx])
+                    tval[vidx] = value
+                    lst[idx] = tuple(tval)
+                lst[idx] = tuple(lst[idx])
+        for ls in lst:
+            if isinstance(ls, list):
+                raise Exception('pouet')
+        values.append(tuple(lst))
+        return vidx
     # value
     def setvalue(self, path, value, owner, index):
         """set value for a path
@@ -39,43 +69,18 @@ class Values(Cache):
         values = []
         vidx = None
 
-        def _setvalue_info(nb, idx, value, vidx):
-            lst = list(self._values[nb])
-            if idx is None:
-                if index is None or nb == 0:
-                    lst.append(value)
-                else:
-                    lst.append((value,))
-            else:
-                if index is None or nb == 0:
-                    lst[idx] = value
-                else:
-                    if nb == 1:
-                        if index in lst[idx]:
-                            vidx = lst[idx].index(index)
-                        else:
-                            vidx = None
-                    if vidx is None:
-                        tval = list(lst[idx])
-                        tval.append(value)
-                        lst[idx] = tuple(tval)
-                    elif nb != 1:
-                        tval = list(lst[idx])
-                        tval[vidx] = value
-                        lst[idx] = tuple(tval)
-                    lst[idx] = tuple(lst[idx])
-            values.append(tuple(lst))
-            return vidx
         if path in self._values[0]:
             idx = self._values[0].index(path)
         else:
             idx = None
-        vidx = _setvalue_info(0, idx, path, vidx)
-        vidx = _setvalue_info(1, idx, index, vidx)
+        vidx = self._setvalue_info(0, idx, path, values, index, vidx)
+        vidx = self._setvalue_info(1, idx, index, values, index, vidx)
+        if isinstance(value, list):
+            value = tuple(value)
+        vidx = self._setvalue_info(2, idx, value, values, index, vidx)
         if isinstance(value, list):
             value = tuple(value)
-        vidx = _setvalue_info(2, idx, value, vidx)
-        _setvalue_info(3, idx, owner, vidx)
+        self._setvalue_info(3, idx, owner, values, index, vidx)
         self._values = tuple(values)
 
     def getvalue(self, path, index=None):
@@ -112,7 +117,18 @@ class Values(Cache):
         """
         values = {}
         for idx, path in enumerate(self._values[0]):
-            values[path] = (self._values[3][idx], self._values[2][idx])
+            indexes = self._values[1][idx]
+            value = self._values[2][idx]
+            owner = self._values[3][idx]
+            if indexes is not None:
+                val = {}
+                own = {}
+                for cpt, index in enumerate(indexes):
+                    val[str(index)] = value[cpt]
+                    own[str(index)] = owner[cpt]
+                value = val
+                owner = own
+            values[path] = (owner, value)
         return values
 
     # owner
@@ -120,19 +136,15 @@ class Values(Cache):
         """change owner for a path
         """
         idx = self._values[0].index(path)
-        if isinstance(self._values[3][idx], tuple):
-            if index is None:
-                raise ValueError('Slave need index to set owner')
-            towner = list(self._values[3][idx])
-            towner[index] = owner
-            owner = towner
-        elif index is not None:
-            raise ValueError('Only slave option needs index to set owner')
-        lst = list(self._values[3])
-        lst[idx] = owner
-        values = list(self._values)
-        values[3] = tuple(lst)
-        self._values = tuple(values)
+        if index is None:
+            vidx = None
+        else:
+            vidx = self._values[1][idx].index(index)
+        values = []
+        self._setvalue_info(3, idx, owner, values, index, vidx)
+        lst = list(self._values)
+        lst[3] = tuple(values[0])
+        self._values = tuple(lst)
 
     def get_max_length(self, path):
         if path in self._values[0]:
@@ -164,7 +176,7 @@ class Values(Cache):
 
     def _getvalue(self, path, nb, index):
         """
-        _values == ((path1, path2), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2), ((idx1_1, idx1_2), None))
+        _values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
         """
         if path in self._values[0]:
             idx = self._values[0].index(path)
index c62f15b..72f1b58 100644 (file)
@@ -134,11 +134,6 @@ class Values(object):
                                      submulti_index, True)
 
     def get_modified_values(self):
-        context = self._getcontext()
-        if context._impl_descr is not None:
-            for opt, path in context.cfgimpl_get_description(
-            )._get_force_store_value():
-                self._getowner(opt, path, force_permissive=True)
         return self._p_.get_modified_values()
 
     def __contains__(self, opt):