[dataimport] rename nohook store .source attribute
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 29 Jan 2016 15:08:13 +0100
changeset 11307 74f5814ecdf0
parent 11306 e759631889be
child 11308 df75fe529ba8
[dataimport] rename nohook store .source attribute so it's clearly not the samething as metagenerator.source. Also add a bit of doc along the way.
cubicweb/dataimport/pgstore.py
cubicweb/dataimport/stores.py
--- a/cubicweb/dataimport/pgstore.py	Thu Jan 28 11:17:31 2016 +0100
+++ b/cubicweb/dataimport/pgstore.py	Fri Jan 29 15:08:13 2016 +0100
@@ -217,19 +217,19 @@
         """
         super(SQLGenObjectStore, self).__init__(cnx)
         ### hijack default source
-        self.source = SQLGenSourceWrapper(
-            self.source, cnx.vreg.schema,
+        self._system_source = SQLGenSourceWrapper(
+            self._system_source, cnx.vreg.schema,
             dump_output_dir=dump_output_dir)
         ### XXX This is done in super().__init__(), but should be
         ### redone here to link to the correct source
-        self._add_relation = self.source.add_relation
+        self._add_relation = self._system_source.add_relation
         self.indexes_etypes = {}
         if nb_threads_statement != 1:
             warn('[3.21] SQLGenObjectStore is no longer threaded', DeprecationWarning)
 
     def flush(self):
         """Flush data to the database"""
-        self.source.flush()
+        self._system_source.flush()
 
     def relate(self, subj_eid, rtype, obj_eid, **kwargs):
         if subj_eid is None or obj_eid is None:
@@ -249,7 +249,7 @@
                 """turn an index name to (database) attribute name"""
                 return index.replace(etype.lower(), '').replace('idx', '').strip('_')
             indices = [(index, index_to_attr(index))
-                       for index in self.source.dbhelper.list_indices(cu, etype)
+                       for index in self._system_source.dbhelper.list_indices(cu, etype)
                        # Do not consider 'cw_etype_pkey' index
                        if not index.endswith('key')]
             self.indexes_etypes[etype] = indices
--- a/cubicweb/dataimport/stores.py	Thu Jan 28 11:17:31 2016 +0100
+++ b/cubicweb/dataimport/stores.py	Fri Jan 29 15:08:13 2016 +0100
@@ -151,13 +151,16 @@
 
 class NoHookRQLObjectStore(RQLObjectStore):
     """Store that works by accessing low-level CubicWeb's source API, with all hooks deactivated. It
-    must be given a metadata generator object to handle metadata which are usually handled by hooks
-    (see :class:`MetaGenerator`).
+    may be given a metadata generator object to handle metadata which are usually handled by hooks.
+
+    Arguments:
+    - `cnx`, a connection to the repository
+    - `metagen`, optional :class:`MetaGenerator` instance
     """
 
     def __init__(self, cnx, metagen=None):
         super(NoHookRQLObjectStore, self).__init__(cnx)
-        self.source = cnx.repo.system_source
+        self._system_source = cnx.repo.system_source
         self._rschema = cnx.repo.schema.rschema
         self._create_eid = cnx.repo.system_source.create_eid
         self._add_relation = self.source.add_relation
@@ -186,8 +189,8 @@
         cnx = self._cnx
         entity.eid = self._create_eid(cnx)
         entity_source, extid = self.metagen.init_entity(entity)
-        self.source.add_info(cnx, entity, entity_source, extid)
-        self.source.add_entity(cnx, entity)
+        self._system_source.add_info(cnx, entity, entity_source, extid)
+        self._system_source.add_entity(cnx, entity)
         kwargs = dict()
         if inspect.getargspec(self._add_relation).keywords:
             kwargs['subjtype'] = entity.cw_etype