# HG changeset patch # User Sylvain Thénault # Date 1269937721 -7200 # Node ID bf5cbc351e997878782ccd188da27300ae588c4a # Parent 01d85f3a3d9ed7b986f0579a7c19b1daef01ac92 [repo] move eschema_eid function from hooks.metadata to server.utils diff -r 01d85f3a3d9e -r bf5cbc351e99 dataimport.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)) diff -r 01d85f3a3d9e -r bf5cbc351e99 hooks/metadata.py --- 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): diff -r 01d85f3a3d9e -r bf5cbc351e99 server/utils.py --- 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)'