def import_aliases(project, author, path): """ Set up a data pipeline and execute it. """ with open(path, 'r') as fh: config = {'mapping': { 'canonical': {'attribute': 'canonical'}, 'alias': {'attribute': 'alias'} }} name = os.path.basename(path) pipeline = pipelines.create(project, 'import', name, config, author) pipelines.start(pipeline) imports.import_aliases(pipeline, fh) pipelines.finish(pipeline)
def run_importer(pipeline_id): """ Perform a raw data import with a given mode. """ pipeline = Pipeline.by_id(pipeline_id) pipelines.start(pipeline) mode = pipeline.config.get('mode') file_id = pipeline.config.get('file') file_ = File.by_id(file_id) if file_ is None: pipeline.log_error(pipeline, 'File object deleted: %s' % file_id) elif mode == 'aliases': import_aliases(pipeline, file_.fh) else: import_objects(pipeline, file_.fh) pipelines.finish(pipeline)