[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Sep 2010 18:23:35 +0200
branchstable
changeset 6308 c151c730a1ac
parent 6307 c07763c59fcb
child 6309 9f03e3c32676
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
dbapi.py
server/repository.py
--- a/dbapi.py	Wed Sep 22 18:18:29 2010 +0200
+++ b/dbapi.py	Wed Sep 22 18:23:35 2010 +0200
@@ -639,9 +639,12 @@
         return self._repo.get_schema()
 
     @check_not_closed
-    def get_option_value(self, option):
-        """return the value for `option` in the repository configuration."""
-        return self._repo.get_option_value(option)
+    def get_option_value(self, option, foreid=None):
+        """Return the value for `option` in the configuration. If `foreid` is
+        specified, the actual repository to which this entity belongs is
+        derefenced and the option value retrieved from it.
+        """
+        return self._repo.get_option_value(option, foreid)
 
     @check_not_closed
     def describe(self, eid):
--- a/server/repository.py	Wed Sep 22 18:18:29 2010 +0200
+++ b/server/repository.py	Wed Sep 22 18:23:35 2010 +0200
@@ -461,13 +461,24 @@
         cubes.remove('cubicweb')
         return cubes
 
-    def get_option_value(self, option):
-        """Return the value for `option` in the configuration.
+    def get_option_value(self, option, foreid=None):
+        """Return the value for `option` in the configuration. If `foreid` is
+        specified, the actual repository to which this entity belongs is
+        derefenced and the option value retrieved from it.
 
         This is a public method, not requiring a session id.
         """
         # XXX we may want to check we don't give sensible information
-        return self.config[option]
+        if foreid is None:
+            return self.config[option]
+        _, sourceuri, extid = self.type_and_source_from_eid(foreid)
+        if sourceuri == 'system':
+            return self.config[option]
+        pool = self._get_pool()
+        try:
+            return pool.connection(sourceuri).get_option_value(option, extid)
+        finally:
+            self._free_pool(pool)
 
     @cached
     def get_versions(self, checkversions=False):