Esempio n. 1
0
def load_csv(ctx, mapping, output, context, csv_file):
    """ Load entities from a CSV file. """
    graph = ctx.obj['GRAPH']
    mapping = ensure_uri(mapping)
    csv_uri = ensure_uri(csv_file)
    log.debug('Loading data from %r', csv_uri)
    load_mapped_csv(graph, csv_uri, read_yaml_uri(mapping), context_id=context)
    if output is not None:
        save_dump(graph, output)
Esempio n. 2
0
def load_csv(ctx, mapping, output, context, csv_file):
    """ Load entities from a CSV file. """
    graph = ctx.obj['GRAPH']
    mapping = ensure_uri(mapping)
    csv_uri = ensure_uri(csv_file)
    log.debug('Loading data from %r', csv_uri)
    load_mapped_csv(graph, csv_uri, read_yaml_uri(mapping), context_id=context)
    if output is not None:
        save_dump(graph, output)
Esempio n. 3
0
def query(ctx, input, output, context, query_file):
    """ Run an MQL query and store the results. """
    graph = ctx.obj['GRAPH']
    for uri in input:
        load_dump(graph, ensure_uri(uri))

    if query_file is not None:
        query = read_yaml_uri(ensure_uri(query_file))
    else:
        query = yaml.loads(sys.stdin)
    save_query_json(graph, query, output, context_id=context)
Esempio n. 4
0
def query(ctx, input, output, context, query_file):
    """ Run an MQL query and store the results. """
    graph = ctx.obj['GRAPH']
    for uri in input:
        load_dump(graph, ensure_uri(uri))

    if query_file is not None:
        query = read_yaml_uri(ensure_uri(query_file))
    else:
        query = yaml.loads(sys.stdin)
    save_query_json(graph, query, output, context_id=context)
Esempio n. 5
0
def cli(ctx, debug, config):
    """ JSON graph-based data processing utility. """
    ctx.obj = ctx.obj or {}
    ctx.obj['DEBUG'] = debug

    fmt = '[%(levelname)-8s] %(name)-12s: %(message)s'
    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level, format=fmt)
    logging.getLogger('requests').setLevel(logging.WARNING)

    data = None
    if config is not None:
        data = read_yaml_uri(ensure_uri(config))
    else:
        config = path_to_uri(os.getcwd())

    ctx.obj['GRAPH'] = Graph(config=data, base_uri=config)
Esempio n. 6
0
def cli(ctx, debug, config):
    """ JSON graph-based data processing utility. """
    ctx.obj = ctx.obj or {}
    ctx.obj['DEBUG'] = debug

    fmt = '[%(levelname)-8s] %(name)-12s: %(message)s'
    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level, format=fmt)
    logging.getLogger('requests').setLevel(logging.WARNING)

    data = None
    if config is not None:
        data = read_yaml_uri(ensure_uri(config))
    else:
        config = path_to_uri(os.getcwd())

    ctx.obj['GRAPH'] = Graph(config=data, base_uri=config)
Esempio n. 7
0
def fixture_uri(path):
    base = os.path.join(fixtures_dir, path)
    base_uri = 'file://' + urllib.pathname2url(base)
    return read_yaml_uri(base_uri), base_uri