requirements: calculate all requirements for an option
[tiramisu.git] / tiramisu / setting.py
index d99a02e..46741b5 100644 (file)
@@ -206,7 +206,7 @@ class Property(object):
 def set_storage(name, **args):
     storage_type.set_storage(name)
     settings = __import__(storage_type.get_storage(), globals(), locals(),
-                          ['Setting'], -1).Setting()
+                          ['Setting']).Setting()
     for option, value in args.items():
         try:
             getattr(settings, option)
@@ -223,23 +223,23 @@ def get_storage(context, session_id, persistent):
     if session_id is None:
         session_id = gen_id(context)
     return __import__(storage_type.get_storage(), globals(), locals(),
-                      ['Storage'], -1).Storage(session_id, persistent)
+                      ['Storage']).Storage(session_id, persistent)
 
 
 def list_sessions():
     return __import__(storage_type.get_storage(), globals(), locals(),
-                      ['list_sessions'], -1).list_sessions()
+                      ['list_sessions']).list_sessions()
 
 
 def delete_session(session_id):
     return __import__(storage_type.get_storage(), globals(), locals(),
-                      ['delete_session'], -1).delete_session(session_id)
+                      ['delete_session']).delete_session(session_id)
 
 
 #____________________________________________________________
 class Settings(object):
     "``Config()``'s configuration options"
-    __slots__ = ('context', '_owner', '_p_')
+    __slots__ = ('context', '_owner', '_p_', '__weakref__')
 
     def __init__(self, context, storage):
         """
@@ -255,8 +255,8 @@ class Settings(object):
         self._owner = owners.user
         self.context = weakref.ref(context)
         import_lib = 'tiramisu.storage.{0}.setting'.format(storage.storage)
-        self._p_ = __import__(import_lib, globals(), locals(), ['Settings'],
-                              -1).Settings(storage)
+        self._p_ = __import__(import_lib, globals(), locals(), ['Settings']
+                              ).Settings(storage)
 
     #____________________________________________________________
     # properties methods
@@ -399,7 +399,18 @@ class Settings(object):
                                               "").format(opt_or_descr._name,
                                                          str(props)), props)
 
-    def setpermissive(self, permissive, path=None):
+    def setpermissive(self, permissive, opt=None, path=None):
+        """
+        enables us to put the permissives in the storage
+
+        :param path: the option's path
+        :param type: str
+        :param opt: if an option object is set, the path is extracted.
+                    it is better (faster) to set the path parameter
+                    instead of passing a :class:`tiramisu.option.Option()` object.
+        """
+        if opt is not None and path is None:
+            path = self._get_opt_path(opt)
         if not isinstance(permissive, tuple):
             raise TypeError(_('permissive must be a tuple'))
         self._p_.setpermissive(path, permissive)
@@ -496,7 +507,7 @@ class Settings(object):
                 try:
                     value = self.context()._getattr(reqpath,
                                                     force_permissive=True)
-                except PropertiesOptionError, err:
+                except PropertiesOptionError as err:
                     if not transitive:
                         continue
                     properties = err.proptype
@@ -516,7 +527,7 @@ class Settings(object):
                     calc_properties.add(action)
                     # the calculation cannot be carried out
                     break
-            return calc_properties
+        return calc_properties
 
     def _get_opt_path(self, opt):
         return self.context().cfgimpl_get_description().impl_get_path_by_opt(opt)