server/utils.py
branchstable
changeset 5066 bf5cbc351e99
parent 4714 fccda6dd91bf
child 5376 2c3f14bc2590
--- 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)'