[dataimport] Turn path from relative to absolute in the LCSV_FILES structure
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 11 Oct 2017 15:28:54 +0200
changeset 2753 e562b3d62a0d
parent 2750 1ef4f5936c15
child 2757 f5069136d86d
[dataimport] Turn path from relative to absolute in the LCSV_FILES structure rather than later, so one may still use the `import_seda_schemes` high-level function to import files which are not in the migration/data directory (but rather in test/data). Related to #36331831
cubicweb_seda/dataimport.py
--- a/cubicweb_seda/dataimport.py	Wed Oct 11 15:16:03 2017 +0200
+++ b/cubicweb_seda/dataimport.py	Wed Oct 11 15:28:54 2017 +0200
@@ -19,7 +19,7 @@
 from __future__ import print_function
 
 from itertools import count
-from os.path import join, dirname
+from os.path import abspath, dirname, join
 
 from six import text_type
 
@@ -30,7 +30,9 @@
 from cubes.skos import lcsv, sobjects as skos
 
 
-LCSV_FILES = (
+LCSV_FILES = [(title, rtype, etype,
+               join(abspath(dirname(__file__)), 'migration', 'data', fname))
+              for title, rtype, etype, fname in (
     # schemes extracted from SEDA 2 XSD
     (u'SEDA 2 : Actions',
      'seda_final_action', 'SEDAStorageRule',
@@ -94,12 +96,12 @@
     (u'Cat├ęgories de fichier',
      'file_category', (),
      'file_categories.csv'),
-)
+)]
 
 
 def lcsv_import(cnx, store, fname, scheme_uri):
     """Actually import LCSV data file."""
-    with open(join(dirname(__file__), 'migration', 'data', fname)) as stream:
+    with open(fname) as stream:
         extentities = skos.lcsv_extentities(stream, scheme_uri, ';', 'utf-8')
         import_log = SimpleImportLog(fname)
         skos.store_skos_extentities(cnx, store, extentities, import_log,