Пример #1
0
def query(ctx, q, schema_file, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache,
          fragment_cache, host, port):
    check_init(ctx)

    q = q.replace("'", '"')
    if cache_file:
        path_parts = cache_file.split('/')
        cache_base = '/'.join(cache_file.split('/')[:-1])
        cache_file = path_parts[-1]

    if resource_cache or fragment_cache:
        remote_cache = all([cache_host, cache_port, cache_db])
        cache = RedisCache(redis_file=None if remote_cache else (cache_file or 'data.db'),
                           base='.agora/store' if not cache_file else cache_base,
                           path='',
                           redis_host=cache_host,
                           redis_db=cache_db,
                           redis_port=cache_port)
    else:
        cache = None

    ctx.obj['gw'].data_cache = cache
    processor = GraphQLProcessor(ctx.obj['gw'], schema_path=schema_file, scholar=fragment_cache, host=host,
                                 port=port, follow_cycles=not ignore_cycles, base='.agora/store/fragments')
    res = processor.query(q)
    click.echo(jsonify(res.to_dict()))
Пример #2
0
def seeds(ctx, query, arg, host, port):
    args = dict(map(lambda a: split_arg(a), arg))
    gw = ctx.obj['gw']

    ted = gw.discover(query, lazy=False)
    dgw = DataGateway(gw.agora, ted, cache=None, port=port, server_name=host)
    seed_uris = dgw.seeds(**args)
    click.echo(jsonify(list(seed_uris)))
Пример #3
0
def show_paths(ctx, source, dest):
    gw = ctx.obj['gw']
    try:
        click.echo(jsonify(
            gw.agora.fountain.get_paths(dest,
                                        force_seed=[('<{}-uri>'.format(source.lower()).replace(':', '-'), source)])))
    except TypeError:
        error('Source and/or destination are unknown')
Пример #4
0
def list_things(ctx):
    ted = ctx.obj['gw'].ted
    thing_ids = map(lambda x: x.id, ted.ecosystem.tds)
    thing_ids.extend(map(lambda x: x.node,
                         ted.ecosystem.non_td_root_resources))
    click.echo(jsonify(thing_ids))
Пример #5
0
def list_tds(ctx):
    ted = ctx.obj['gw'].ted
    td_ids = map(lambda x: x.id, ted.ecosystem.tds)
    click.echo(jsonify(td_ids))
Пример #6
0
def list_prefixes(ctx):
    gw = ctx.obj['gw']
    click.echo(jsonify(gw.agora.fountain.prefixes))
Пример #7
0
def list_types(ctx):
    gw = ctx.obj['gw']
    click.echo(jsonify(gw.agora.fountain.types))
Пример #8
0
def list_resources(ctx):
    gw = ctx.obj['gw']
    click.echo(jsonify(map(lambda r: r.node, gw.enrichments)))
Пример #9
0
def list_extensions(ctx):
    gw = ctx.obj['gw']
    click.echo(jsonify(gw.extensions))
Пример #10
0
def add_prefix(ctx, prefix, ns):
    gw = ctx.obj['gw']
    gw.agora.fountain.add_prefixes({prefix: ns})
    print jsonify(gw.agora.fountain.prefixes)
Пример #11
0
def show_property(ctx, name):
    gw = ctx.obj['gw']
    try:
        click.echo(jsonify(gw.get_property(name)))
    except NotFoundError:
        error('There is no known property called "{}"'.format(name))
Пример #12
0
def show_config(ctx):
    click.echo(jsonify(load_config()))
Пример #13
0
def show_args(ctx):
    args = ctx.obj['gw'].args
    click.echo(jsonify(args))