[dataimport] cleanup a bit nohook store, mostly protecting some attributes
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 29 Jan 2016 15:08:34 +0100
changeset 11140 fabcd1c6dcd1
parent 11139 df928a3a94e3
child 11142 45f738a634e5
[dataimport] cleanup a bit nohook store, mostly protecting some attributes
cubicweb/dataimport/pgstore.py
cubicweb/dataimport/stores.py
--- a/cubicweb/dataimport/pgstore.py	Wed Feb 03 11:13:51 2016 +0100
+++ b/cubicweb/dataimport/pgstore.py	Fri Jan 29 15:08:34 2016 +0100
@@ -40,6 +40,7 @@
     """
     cu.executemany(statement, data)
 
+
 def _execmany_thread_copy_from(cu, statement, data, table,
                                columns, encoding='utf-8'):
     """ Execute thread with copy from
@@ -54,6 +55,7 @@
         else:
             cu.copy_from(buf, table, null=u'NULL', columns=columns)
 
+
 def _execmany_thread(sql_connect, statements, dump_output_dir=None,
                      support_copy_from=True, encoding='utf-8'):
     """
@@ -220,7 +222,7 @@
             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.source.add_relation
         self.indexes_etypes = {}
         if nb_threads_statement != 1:
             warn('[3.21] SQLGenObjectStore is no longer threaded', DeprecationWarning)
@@ -233,11 +235,11 @@
         if subj_eid is None or obj_eid is None:
             return
         # XXX Could subjtype be inferred ?
-        self.source.add_relation(self._cnx, subj_eid, rtype, obj_eid,
-                                 self.rschema(rtype).inlined, **kwargs)
+        self._add_relation(self._cnx, subj_eid, rtype, obj_eid,
+                           self.rschema(rtype).inlined, **kwargs)
         if self.rschema(rtype).symmetric:
-            self.source.add_relation(self._cnx, obj_eid, rtype, subj_eid,
-                                     self.rschema(rtype).inlined, **kwargs)
+            self._add_relation(self._cnx, obj_eid, rtype, subj_eid,
+                               self.rschema(rtype).inlined, **kwargs)
 
     def drop_indexes(self, etype):
         """Drop indexes for a given entity type"""
@@ -368,7 +370,7 @@
                                      'inlined relation %s'
                                      ', as it cannot be inferred: '
                                      'this type is given as keyword argument '
-                                     '``subjtype``'% rtype)
+                                     '``subjtype``' % rtype)
             statement = self.sqlgen.update(SQL_PREFIX + subjtype,
                                            data, ['cw_eid'])
         else:
--- a/cubicweb/dataimport/stores.py	Wed Feb 03 11:13:51 2016 +0100
+++ b/cubicweb/dataimport/stores.py	Fri Jan 29 15:08:34 2016 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -158,8 +158,8 @@
     def __init__(self, cnx, metagen=None):
         super(NoHookRQLObjectStore, self).__init__(cnx)
         self.source = cnx.repo.system_source
-        self.rschema = cnx.repo.schema.rschema
-        self.add_relation = self.source.add_relation
+        self._rschema = cnx.repo.schema.rschema
+        self._add_relation = self.source.add_relation
         if metagen is None:
             metagen = MetaGenerator(cnx)
         self.metagen = metagen
@@ -187,18 +187,18 @@
         self.source.add_info(cnx, entity, entity_source, extid)
         self.source.add_entity(cnx, entity)
         kwargs = dict()
-        if inspect.getargspec(self.add_relation).keywords:
+        if inspect.getargspec(self._add_relation).keywords:
             kwargs['subjtype'] = entity.cw_etype
         for rtype, targeteids in rels.items():
             # targeteids may be a single eid or a list of eids
-            inlined = self.rschema(rtype).inlined
+            inlined = self._rschema(rtype).inlined
             try:
                 for targeteid in targeteids:
-                    self.add_relation(cnx, entity.eid, rtype, targeteid,
-                                      inlined, **kwargs)
+                    self._add_relation(cnx, entity.eid, rtype, targeteid,
+                                       inlined, **kwargs)
             except TypeError:
-                self.add_relation(cnx, entity.eid, rtype, targeteids,
-                                  inlined, **kwargs)
+                self._add_relation(cnx, entity.eid, rtype, targeteids,
+                                   inlined, **kwargs)
         self._nb_inserted_entities += 1
         return entity.eid
 
@@ -210,11 +210,10 @@
         and ``eid_to``.
         """
         assert not rtype.startswith('reverse_')
-        self.add_relation(self._cnx, eid_from, rtype, eid_to,
-                          self.rschema(rtype).inlined)
-        if self.rschema(rtype).symmetric:
-            self.add_relation(self._cnx, eid_to, rtype, eid_from,
-                              self.rschema(rtype).inlined)
+        rschema = self._rschema(rtype)
+        self._add_relation(self._cnx, eid_from, rtype, eid_to, rschema.inlined)
+        if rschema.symmetric:
+            self._add_relation(self._cnx, eid_to, rtype, eid_from, rschema.inlined)
         self._nb_inserted_relations += 1
 
     @property