Esempio n. 1
0
def main():
    (LOG, cmd) = rdftools.startup('scripts.convert_command', add_args)
    try:
        graph = rdftools.read_all(cmd.input, cmd.read)
        rdftools.write(graph, cmd.output, cmd.write)
    except SyntaxError as ex:
        print(i18n.t('scripts.read_error', message=ex.message))
Esempio n. 2
0
def main():
    (LOG, cmd) = rdftools.startup('scripts.select_command', add_args)

    graph = rdftools.read_all(cmd.input, cmd.read)

    if cmd.select in ['subjects', 'predicates', 'objects']:
        selector(LOG, graph, cmd.select)
    elif cmd.select == 'types':
        selector(LOG, graph, 'objects', predicate=RDF.type)
Esempio n. 3
0
def main():
    global LOG
    (LOG, cmd) = rdftools.startup('shell.command',
                                  add_args=None, read_files=False)
    info(i18n.t('shell.welcome', version=rdftools.__VERSION__))
    configure_readline()
    context = clear(None, None)
    context.base = cmd.base
    parse_cmdfile(context, os.path.join(os.path.expanduser("~"), ".rdfshrc"))
    run_loop(context)
Esempio n. 4
0
def test_startup(translator):
    def add_args(parser):
        parser.add_argument('-q', '--query', action='store')
        return parser

    (log, cmd) = rdftools.startup(
        'test.command',
        add_args,
        argv=['-vvv', '-b', 'http://example.org', '-q', 'select'])
    assert log is not None
    assert cmd is not None
Esempio n. 5
0
def main():
    (LOG, cmd) = rdftools.startup('RDF file validator.', add_args=None)

    for input in cmd.input:
        LOG.info(i18n.t('scripts.validate_started', name=input))
        try:
            rdftools.read(input, cmd.read)
            LOG.info(i18n.t('scripts.validate_succeeded'))
        except:  # noqa: E722
            LOG.warning(i18n.t('scripts.validate_failed', exc_info=True))
            sys.exit(1)
Esempio n. 6
0
def main():
    (LOG, cmd) = rdftools.startup('scripts.query_command', add_args)

    graph = rdftools.read_all(cmd.input, cmd.read)

    LOG.info(i18n.t('scripts.query_started'))
    LOG.debug(cmd.query)
    start = timer()
    results = graph.query(cmd.query)
    end = timer()
    LOG.debug(i18n.t('scripts.query_rows', len=len(results)))
    if len(results) > 0:
        columns = results.bindings[0].keys()
        LOG.debug(
            i18n.t('scripts.query_columns',
                   names=', '.join([str(c) for c in columns])))
        rdftools.report(columns, results, end - start)
    else:
        print(i18n.t('scripts.query_no_results'))