[repo] move eschema_eid function from hooks.metadata to server.utils stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 30 Mar 2010 10:28:41 +0200
branchstable
changeset 5066 bf5cbc351e99
parent 5065 01d85f3a3d9e
child 5067 adc2122eed03
[repo] move eschema_eid function from hooks.metadata to server.utils
dataimport.py
hooks/metadata.py
server/utils.py
--- a/dataimport.py	Tue Mar 30 10:20:03 2010 +0200
+++ b/dataimport.py	Tue Mar 30 10:28:41 2010 +0200
@@ -62,6 +62,7 @@
 from logilab.common.decorators import cached
 from logilab.common.deprecation import deprecated
 
+from cubicweb.server.utils import eschema_eid
 
 def ucsvreader_pb(filepath, encoding='utf-8', separator=',', quote='"',
                   skipfirst=False, withpb=True):
@@ -685,10 +686,8 @@
     # schema has been loaded from the fs (hence entity type schema eids are not
     # known)
     def test_gen_is(self, entity):
-        from cubicweb.hooks.metadata import eschema_eid
         return eschema_eid(self.session, entity.e_schema)
     def test_gen_is_instanceof(self, entity):
-        from cubicweb.hooks.metadata import eschema_eid
         eids = []
         for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
             eids.append(eschema_eid(self.session, eschema))
--- a/hooks/metadata.py	Tue Mar 30 10:20:03 2010 +0200
+++ b/hooks/metadata.py	Tue Mar 30 10:28:41 2010 +0200
@@ -12,17 +12,7 @@
 
 from cubicweb.selectors import implements
 from cubicweb.server import hook
-
-
-def eschema_eid(session, eschema):
-    """get eid of the CWEType entity for the given yams type"""
-    # eschema.eid is None if schema has been readen from the filesystem, not
-    # from the database (eg during tests)
-    if eschema.eid is None:
-        eschema.eid = session.execute(
-            'Any X WHERE X is CWEType, X name %(name)s',
-            {'name': str(eschema)})[0][0]
-    return eschema.eid
+from cubicweb.server.utils import eschema_eid
 
 
 class MetaDataHook(hook.Hook):
--- a/server/utils.py	Tue Mar 30 10:20:03 2010 +0200
+++ b/server/utils.py	Tue Mar 30 10:28:41 2010 +0200
@@ -65,6 +65,18 @@
                 del sol[vname]
 
 
+def eschema_eid(session, eschema):
+    """get eid of the CWEType entity for the given yams type. You should use
+    this because when schema has been loaded from the file-system, not from the
+    database, (e.g. during tests), eschema.eid is not set.
+    """
+    if eschema.eid is None:
+        eschema.eid = session.execute(
+            'Any X WHERE X is CWEType, X name %(name)s',
+            {'name': str(eschema)})[0][0]
+    return eschema.eid
+
+
 DEFAULT_MSG = 'we need a manager connection on the repository \
 (the server doesn\'t have to run, even should better not)'