Extract a get_store function to let a chance to client cube to hack store creation
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 19 Oct 2016 15:53:12 +0200
changeset 1889 0441a4cbec7e
parent 1888 c74d8dd017ce
child 1890 1019e4f3227c
Extract a get_store function to let a chance to client cube to hack store creation For instance in SAEM, we need a store with custom metadata generator that will generate ark for imported concepts.
dataimport.py
--- a/dataimport.py	Tue Oct 18 17:53:43 2016 +0200
+++ b/dataimport.py	Wed Oct 19 15:53:12 2016 +0200
@@ -106,18 +106,30 @@
 
 
 def init_seda_scheme(cnx, title):
+    """Create a scheme to hold SEDA concepts with the given title.
+
+    Separated function to be monkey-patched if one need to customize the store (eg saem).
+    """
     description = u'edition 2009' if title.startswith('SEDA :') else None
     return cnx.create_entity('ConceptScheme', title=title, description=description)
 
 
-def import_seda_schemes(cnx, lcsv_import=lcsv_import):
-    """Import all LCSV data files defined in LCSV_FILES"""
+def get_store(cnx):
+    """Return the store to be used to import LCSV data files.
+
+    Separated function to be monkey-patched if one needs to customize the store (eg saem).
+    """
     if cnx.repo.system_source.dbdriver == 'postgres':
         from cubicweb.dataimport.massive_store import MassiveObjectStore
-        store = MassiveObjectStore(cnx, eids_seq_range=1000)
+        return MassiveObjectStore(cnx, eids_seq_range=1000)
     else:
         from cubicweb.dataimport.stores import NoHookRQLObjectStore
-        store = NoHookRQLObjectStore(cnx)
+        return NoHookRQLObjectStore(cnx)
+
+
+def import_seda_schemes(cnx, lcsv_import=lcsv_import):
+    """Import all LCSV data files defined in LCSV_FILES."""
+    store = get_store(cnx)
     for title, rtypes, etypes, fname in LCSV_FILES:
         if not cnx.find('ConceptScheme', title=title):
             print('importing', title.encode('utf-8'))