From 0cd94a32695955b879275415a8a8b9ba249e5610 Mon Sep 17 00:00:00 2001 From: Fernando Serena Date: Mon, 27 Aug 2018 13:41:27 +0200 Subject: [PATCH] First commit --- .gitignore | 7 + LICENSE | 202 +++++++++++++++++++++++++++++ README.md | 3 + agora_cli/__init__.py | 23 ++++ agora_cli/add.py | 166 ++++++++++++++++++++++++ agora_cli/compute.py | 51 ++++++++ agora_cli/delete.py | 154 ++++++++++++++++++++++ agora_cli/discover.py | 55 ++++++++ agora_cli/get.py | 170 ++++++++++++++++++++++++ agora_cli/init.py | 46 +++++++ agora_cli/learn.py | 104 +++++++++++++++ agora_cli/list.py | 76 +++++++++++ agora_cli/metadata.json | 7 + agora_cli/publish.py | 279 ++++++++++++++++++++++++++++++++++++++++ agora_cli/qgl.py | 75 +++++++++++ agora_cli/query.py | 154 ++++++++++++++++++++++ agora_cli/root.py | 46 +++++++ agora_cli/show.py | 121 +++++++++++++++++ agora_cli/utils.py | 144 +++++++++++++++++++++ contributors.txt | 1 + requirements.txt | 10 ++ setup.cfg | 2 + setup.py | 53 ++++++++ 23 files changed, 1949 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 agora_cli/__init__.py create mode 100644 agora_cli/add.py create mode 100644 agora_cli/compute.py create mode 100644 agora_cli/delete.py create mode 100644 agora_cli/discover.py create mode 100644 agora_cli/get.py create mode 100644 agora_cli/init.py create mode 100644 agora_cli/learn.py create mode 100644 agora_cli/list.py create mode 100644 agora_cli/metadata.json create mode 100644 agora_cli/publish.py create mode 100644 agora_cli/qgl.py create mode 100644 agora_cli/query.py create mode 100644 agora_cli/root.py create mode 100644 agora_cli/show.py create mode 100644 agora_cli/utils.py create mode 100644 contributors.txt create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c2565c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.env/ +.idea/ +*.pyc +*.egg-info +dist/ +.coverage +build/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7a4a3ea --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c24ada5 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Agora CLI + +A command line interface for Agora. diff --git a/agora_cli/__init__.py b/agora_cli/__init__.py new file mode 100644 index 0000000..a0feee3 --- /dev/null +++ b/agora_cli/__init__.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +__author__ = 'Fernando Serena' + +from agora_cli import list, get, show, add, delete, compute, discover, query, publish, init, qgl, learn +from agora_cli.root import cli \ No newline at end of file diff --git a/agora_cli/add.py b/agora_cli/add.py new file mode 100644 index 0000000..9b33d9d --- /dev/null +++ b/agora_cli/add.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click +from agora.engine.plan.agp import extend_uri +from agora_wot.blocks.endpoint import Endpoint +from agora_wot.blocks.td import TD, Mapping, AccessMapping, ResourceTransform +from agora_wot.gateway import Gateway +from rdflib import Graph, URIRef, RDF + +from agora_cli.root import cli +from agora_cli.utils import show_ted, check_init, store_host_replacements + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def add(ctx): + check_init(ctx) + + +@add.command('thing') +@click.argument('uri') +@click.option('--type', multiple=True) +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def add_thing(ctx, uri, type, turtle): + gw = ctx.obj['gw'] + agora = gw.agora + if not all([t in agora.fountain.types for t in type]): + raise AttributeError('Unknown type') + + g = Graph() + prefixes = agora.fountain.prefixes + + uri_ref = URIRef(uri) + if not type: + ted = gw.ted + dgw = Gateway(gw.agora, ted, cache=None) + rg, headers = dgw.loader(uri) + + type_uris = set([extend_uri(t, prefixes) for t in agora.fountain.types]) + + resource_types = set(rg.objects(uri_ref, RDF.type)) + type = tuple(set.intersection(type_uris, resource_types)) + + for t in type: + g.add((uri_ref, RDF.type, URIRef(extend_uri(t, prefixes)))) + + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + + +@add.command('td') +@click.argument('id') +@click.option('--type', multiple=True) +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def add_td(ctx, id, type, turtle): + gw = ctx.obj['gw'] + agora = gw.agora + if not all([t in agora.fountain.types for t in type]): + raise AttributeError('Unknown type') + + prefixes = agora.fountain.prefixes + type_uris = [extend_uri(t, prefixes) for t in type] + td = TD.from_types(types=type_uris, id=id) + g = td.to_graph(th_nodes={}) + + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + + +@add.command('am') +@click.argument('id') +@click.argument('link') +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def add_access_mapping(ctx, id, link, turtle): + gw = ctx.obj['gw'] + + td = gw.get_description(id) + if not td: + raise AttributeError('Unknown description: {}'.format(id)) + + endpoint_hrefs = map(lambda e: u'{}'.format(e.href), td.endpoints) + if link in endpoint_hrefs: + raise AttributeError('Link already mapped') + + e = Endpoint(href=link) + am = AccessMapping(e) + td.add_access_mapping(am) + g = td.to_graph(th_nodes={}) + + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + click.echo(am.id) + + +@add.command('mapping') +@click.argument('id') +@click.argument('amid') +@click.option('--predicate', required=True) +@click.option('--key', required=True) +@click.option('--jsonpath') +@click.option('--root', default=False, is_flag=True) +@click.option('--transformed-by') +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def add_mapping(ctx, id, amid, predicate, key, jsonpath, root, transformed_by, turtle): + gw = ctx.obj['gw'] + + td = gw.get_description(id) + if not td: + raise AttributeError('Unknown description: {}'.format(id)) + + transform_td = None + if transformed_by: + transform_td = gw.get_description(transformed_by) + + target_am = [am for am in td.access_mappings if str(am.id) == amid or am.endpoint.href.toPython() == amid] + if not target_am: + raise AttributeError('Unknown access mapping') + + target_am = target_am.pop() + + m = Mapping(key=key, predicate=URIRef(extend_uri(predicate, gw.agora.fountain.prefixes)), root=root, path=jsonpath, + transform=ResourceTransform(transform_td) if transform_td else None) + target_am.mappings.add(m) + g = td.to_graph(th_nodes={}) + + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + click.echo(m.id) + + +@add.group('host') +@click.pass_context +def add_host(ctx): + pass + + +@add_host.command('replacement') +@click.argument('base') +@click.argument('replace') +@click.pass_context +def add_host_replacement(ctx, base, replace): + ctx.obj['repls'][base] = replace + store_host_replacements(ctx.obj['repls']) diff --git a/agora_cli/compute.py b/agora_cli/compute.py new file mode 100644 index 0000000..0d87b87 --- /dev/null +++ b/agora_cli/compute.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click +from agora_graphql.gql import GraphQLProcessor + +from agora_cli.root import cli +from agora_cli.utils import split_arg, check_init + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def compute(ctx): + check_init(ctx) + + +@compute.command('search-plan') +@click.pass_context +@click.argument('query') +@click.option('--arg', multiple=True) +def search_plan(ctx, query, arg): + args = dict(map(lambda a: split_arg(a), arg)) + gw = ctx.obj['gw'] + res = gw.fragment(query, **args) + plan = res['plan'] + click.echo(plan.serialize(format='turtle')) + + +@compute.command('gql-schema') +@click.pass_context +def show_gql_schema(ctx): + processor = GraphQLProcessor(ctx.obj['gw']) + click.echo(processor.schema_text) diff --git a/agora_cli/delete.py b/agora_cli/delete.py new file mode 100644 index 0000000..c541c99 --- /dev/null +++ b/agora_cli/delete.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import json + +import click +from agora import RedisCache +from agora.engine.utils.graph import get_triple_store +from agora_gw.data.repository import CORE +from rdflib import Graph, BNode, RDF, Literal + +from agora_cli.root import cli +from agora_cli.utils import check_init, store_host_replacements, show_ted + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def delete(ctx): + check_init(ctx) + + +@delete.command('extension') +@click.pass_context +@click.argument('name') +def delete_extension(ctx, name): + gw = ctx.obj['gw'] + gw.delete_extension(name) + + +@delete.group('host') +@click.pass_context +def delete_host(ctx): + pass + + +@delete_host.command('replacement') +@click.argument('base') +@click.pass_context +def delete_host_replacement(ctx, base): + if base in ctx.obj['repls']: + del ctx.obj['repls'][base] + store_host_replacements(ctx.obj['repls']) + + +@delete.command('cache') +@click.pass_context +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +def delete_cache(ctx, cache_file, cache_host, cache_port, cache_db): + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + cache.r.flushdb() + g = get_triple_store(persist_mode=True, base='.agora/store/fragments') + for c in g.contexts(): + g.remove_context(c) + g.remove((None, None, None)) + + +@delete.command('am') +@click.argument('id') +@click.argument('amid') +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def delete_access_mapping(ctx, id, amid, turtle): + gw = ctx.obj['gw'] + + td = gw.get_description(id) + if not td: + raise AttributeError('Unknown description: {}'.format(id)) + + target_am = [am for am in td.access_mappings if str(am.id) == amid or am.endpoint.href.toPython() == amid] + if not target_am: + raise AttributeError('Unknown access mapping') + + target_am = target_am.pop() + td.remove_access_mapping(target_am) + g = td.to_graph(th_nodes={}) + + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + click.echo(target_am.id) + + +@delete.command('mapping') +@click.argument('id') +@click.argument('mid') +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def delete_mapping(ctx, id, mid, turtle): + gw = ctx.obj['gw'] + + td = gw.get_description(id) + if not td: + raise AttributeError('Unknown description: {}'.format(id)) + + target_m = None + target_am = None + for am in td.access_mappings: + m = filter(lambda m: str(m.id) == mid, am.mappings) + if m: + target_m = m.pop() + target_am = am + break + + if not target_m: + raise AttributeError('Unknown access mapping') + + target_am.mappings.remove(target_m) + g = td.to_graph(th_nodes={}) + + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + click.echo(target_m.id) + + +@delete.command('td') +@click.argument('id') +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def delete_description(ctx, id, turtle): + gw = ctx.obj['gw'] + + td = gw.get_description(id) + if not td: + raise AttributeError('Unknown description: {}'.format(id)) + + ctx.obj['gw'].delete_description(id) + #show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + click.echo(td.id) diff --git a/agora_cli/discover.py b/agora_cli/discover.py new file mode 100644 index 0000000..fd8916f --- /dev/null +++ b/agora_cli/discover.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click +from agora_wot.gateway import Gateway + +from agora_cli.root import cli +from agora_cli.show import show_ted +from agora_cli.utils import split_arg, jsonify, check_init + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def discover(ctx): + check_init(ctx) + + +@discover.command() +@click.pass_obj +@click.option('--turtle', default=False, is_flag=True) +def show(obj, turtle): + show_ted(obj['ted'], format='text/turtle' if turtle else 'application/ld+json') + + +@discover.command() +@click.option('--eco-query', required=True) +@click.option('--arg', multiple=True) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def seeds(ctx, eco_query, arg, host, port): + args = dict(map(lambda a: split_arg(a), arg)) + ted = ctx.obj['gw'].discover(eco_query, lazy=False) + dgw = Gateway(ctx.obj['gw'].agora, ted, cache=None, port=port, server_name=host) + seeds = dgw.proxy.instantiate_seeds(**args) + seed_uris = set(reduce(lambda x, y: x + y, seeds.values(), [])) + click.echo(jsonify(list(seed_uris))) diff --git a/agora_cli/get.py b/agora_cli/get.py new file mode 100644 index 0000000..31f7358 --- /dev/null +++ b/agora_cli/get.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python +# coding=utf-8 +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +from Queue import Queue, Empty +from datetime import datetime +from threading import Thread + +import click +from agora import RedisCache +from agora.engine.plan.agp import extend_uri +from agora.engine.utils import Semaphore +from agora_graphql.gql.data import DataGraph +from agora_wot.gateway import Gateway +from rdflib import URIRef, RDF, Graph + +from agora_cli.root import cli +from agora_cli.utils import show_thing, split_arg, check_init + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def get(ctx): + check_init(ctx) + + +@get.command('resource') +@click.argument('uri') +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.option('--turtle', default=False, is_flag=True) +@click.option('--raw', default=False, is_flag=True) +@click.pass_context +def get_resource(ctx, uri, host, port, turtle, raw): + gw = ctx.obj['gw'] + ted = gw.ted + dgw = Gateway(gw.agora, ted, cache=None, port=port, server_name=host) + g, headers = dgw.loader(uri) + + uri_ref = URIRef(uri) + prefixes = gw.agora.fountain.prefixes + type_uris = set([extend_uri(t, prefixes) for t in gw.agora.fountain.types]) + + resource_types = set(g.objects(uri_ref, RDF.type)) + known_types = set.intersection(type_uris, resource_types) + ag = Graph() + for prefix, uri in prefixes.items(): + ag.bind(prefix, uri) + + if raw: + ag.__iadd__(g) + else: + known_types_n3 = [t.n3(ag.namespace_manager) for t in known_types] + known_props = reduce(lambda x, y: x.union(set(gw.agora.fountain.get_type(y)['properties'])), known_types_n3, set()) + known_props_uri = set([extend_uri(p, prefixes) for p in known_props]) + known_refs = reduce(lambda x, y: x.union(set(gw.agora.fountain.get_type(y)['refs'])), known_types_n3, set()) + known_refs_uri = set([extend_uri(p, prefixes) for p in known_refs]) + for (s, p, o) in g: + if s == uri_ref and ((p == RDF.type and o in known_types) or p in known_props_uri): + ag.add((s, p, o)) + if o == uri_ref and p in known_refs_uri: + ag.add((s, p, o)) + + show_thing(ag, format='text/turtle' if turtle else 'application/ld+json') + + +def gen_thread(status, queue, fragment): + try: + gen = fragment['generator'] + plan = fragment['plan'] + prefixes = fragment['prefixes'] + first = True + best_mime = 'text/turtle' # ''application/agora-quad' + min_quads = '-min' in best_mime + if best_mime.startswith('application/agora-quad'): + for c, s, p, o in gen: + if min_quads: + quad = u'{}·{}·{}·{}\n'.format(c, s.n3(plan.namespace_manager), + p.n3(plan.namespace_manager), o.n3(plan.namespace_manager)) + else: + quad = u'{}·{}·{}·{}\n'.format(c, s.n3(), p.n3(), o.n3()) + + queue.put(quad) + else: + if first: + for prefix, uri in prefixes.items(): + queue.put('@prefix {}: <{}> .\n'.format(prefix, uri)) + queue.put('\n') + for c, s, p, o in gen: + triple = u'{} {} {} .\n'.format(s.n3(plan.namespace_manager), + p.n3(plan.namespace_manager), o.n3(plan.namespace_manager)) + + queue.put(triple) + except Exception as e: + status['exception'] = e + + status['completed'] = True + + +def gen_queue(status, stop_event, queue): + with stop_event: + while not status['completed'] or not queue.empty(): + status['last'] = datetime.now() + try: + for chunk in queue.get(timeout=1.0): + yield chunk + except Empty: + if not status['completed']: + pass + elif status['exception']: + raise Exception(status['exception'].message) + + +@get.command() +@click.argument('q') +@click.option('--arg', multiple=True) +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def fragment(ctx, q, arg, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, port): + args = dict(map(lambda a: split_arg(a), arg)) + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + else: + cache = None + stop = Semaphore() + queue = Queue() + + dgw = ctx.obj['gw'].data(q, cache=cache, lazy=False, server_name=host, port=port, base='.agora/store/fragments') + gen = dgw.fragment(q, stop_event=stop, scholar=fragment_cache, **args) + request_status = { + 'completed': False, + 'exception': None + } + stream_th = Thread(target=gen_thread, args=(request_status, queue, gen)) + stream_th.daemon = False + stream_th.start() + + for chunk in gen_queue(request_status, stop, queue): + click.echo(chunk, nl=False) diff --git a/agora_cli/init.py b/agora_cli/init.py new file mode 100644 index 0000000..1d2ed14 --- /dev/null +++ b/agora_cli/init.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click + +from agora_cli.root import cli +from agora_cli.utils import store_config, is_init, init_base + +__author__ = 'Fernando Serena' + + +@cli.command() +@click.option('--host') +@click.option('--port', type=int) +@click.option('--extension-base', default='http://agora.org/extensions/') +@click.option('--repository-base', default='http://agora.org/data/') +@click.option('--repo-sparql-host', default='http://localhost:7200/repositories/tds') +@click.option('--repo-update-host', default='http://localhost:7200/repositories/tds/statements') +@click.option('--repo-cache-host', default=None) +@click.option('--repo-cache-db', default=1) +@click.option('--repo-cache-port', default=None) +@click.pass_context +def init(ctx, **kwargs): + if is_init(): + click.echo("[FAIL] Couldn't init Agora: ", nl=False, err=True) + ctx.abort() + + init_base() + store_config(**kwargs) + click.echo('[ OK ] Agora is ready') diff --git a/agora_cli/learn.py b/agora_cli/learn.py new file mode 100644 index 0000000..578304c --- /dev/null +++ b/agora_cli/learn.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click +from agora.engine.plan.agp import extend_uri +from agora_wot.blocks.endpoint import Endpoint +from agora_wot.blocks.td import TD, Mapping, AccessMapping, ResourceTransform +from agora_wot.blocks.utils import describe +from agora_wot.gateway import Gateway +from rdflib import Graph, URIRef, RDF, BNode + +from agora_cli.root import cli +from agora_cli.utils import show_ted, check_init, store_host_replacements + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def learn(ctx): + check_init(ctx) + + +@learn.command('extension') +@click.pass_context +@click.argument('name') +@click.argument('file', type=click.Path(exists=True)) +def learn_extension(ctx, name, file): + gw = ctx.obj['gw'] + with open(file, 'r') as f: + g = Graph().parse(f, format='turtle') + gw.add_extension(name, g) + + +@learn.command('descriptions') +@click.argument('file', type=click.Path(exists=True)) +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def learn_descriptions(ctx, file, turtle): + with open(file, 'r') as f: + g = Graph().parse(f, format='turtle') + ted = ctx.obj['gw'].add_description(g) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + + +@learn.command('thing') +@click.argument('id') +@click.argument('file', type=click.Path(exists=True)) +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def learn_descriptions(ctx, id, file, turtle): + gw = ctx.obj['gw'] + + td = gw.get_description(id) + if not td: + raise AttributeError('Unknown description: {}'.format(id)) + + g = td.to_graph() + td.resource.to_graph(graph=g) + + with open(file, 'r') as f: + lg = Graph().parse(f, format='turtle') + + for s, p, o in describe(lg, td.resource.node): + g.add((s, p, o)) + + rg = Graph() + for prefix, uri in g.namespaces(): + rg.bind(prefix, uri) + + resource_node = td.resource.node + td_node = BNode() + th_node = BNode() + for s, p, o in g: + if s == td.node: + s = td_node + if o == td.node: + o = td_node + + if s == resource_node: + s = th_node + if o == resource_node: + o = th_node + + rg.add((s, p, o)) + + ted = ctx.obj['gw'].add_description(rg) + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') diff --git a/agora_cli/list.py b/agora_cli/list.py new file mode 100644 index 0000000..1b807b4 --- /dev/null +++ b/agora_cli/list.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click + +from agora_cli.root import cli +from agora_cli.utils import jsonify, check_init + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def list(ctx): + check_init(ctx) + + +@list.command('extensions') +@click.pass_context +def list_extensions(ctx): + gw = ctx.obj['gw'] + click.echo(jsonify(gw.extensions)) + + +@list.command('types') +@click.pass_context +def list_types(ctx): + gw = ctx.obj['gw'] + click.echo(jsonify(gw.agora.fountain.types)) + + +@list.command('properties') +@click.pass_context +def list_properties(ctx): + gw = ctx.obj['gw'] + click.echo(jsonify(gw.agora.fountain.properties)) + + +@list.command('prefixes') +@click.pass_context +def list_prefixes(ctx): + gw = ctx.obj['gw'] + click.echo(jsonify(gw.agora.fountain.prefixes)) + + +@list.command('tds') +@click.pass_context +def list_tds(ctx): + ted = ctx.obj['gw'].ted + td_ids = map(lambda x: x.id, ted.ecosystem.tds) + click.echo(jsonify(td_ids)) + + +@list.command('things') +@click.pass_context +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)) diff --git a/agora_cli/metadata.json b/agora_cli/metadata.json new file mode 100644 index 0000000..07d5b99 --- /dev/null +++ b/agora_cli/metadata.json @@ -0,0 +1,7 @@ +{ + "version": "0.0.1", + "author": "Fernando Serena", + "email": "kudhmud@gmail.com", + "github": "https://github.com/fserena/agora-cli", + "description": "A command line interface for Agora" +} diff --git a/agora_cli/publish.py b/agora_cli/publish.py new file mode 100644 index 0000000..c781f3a --- /dev/null +++ b/agora_cli/publish.py @@ -0,0 +1,279 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click +from agora import RedisCache +from agora_graphql.gql import GraphQLProcessor +from agora_graphql.server import AgoraGraphQLView +from agora_gw.server.app import Application +from agora_graphql.server.app import Application as GQLApplication +from agora_gw.server.worker import number_of_workers +from agora_wot.gateway import Gateway +from flask import Flask +from flask_cors import CORS + +from agora_cli.root import cli + +from agora.server.fountain import build as fs +from agora.server.planner import build as ps +from agora.server.sparql import build as ss +from agora.server.fragment import build as frs + +from agora_cli.utils import check_init, split_arg + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def publish(ctx): + check_init(ctx) + + +@publish.command('ecosystem') +@click.pass_context +@click.option('--query', required=True) +@click.option('--host', default='localhost') +@click.option('--port', default=5000) +@click.option('--cache-file') +def publish_ecosystem(ctx, query, host, port, cache_file): + if cache_file: + cache = RedisCache(redis_file=cache_file) + else: + cache = None + ted = ctx.obj['gw'].discover(query, lazy=False) + dgw = Gateway(ctx.obj['gw'].agora, ted, cache=cache, port=port, server_name=host) + dgw.server.gw.config['ENV'] = 'development' + + dgw.server.gw.run(host='0.0.0.0', port=port, threaded=True) + + +@publish.command('gw') +@click.pass_context +@click.option('--port', default=8000) +def publish_gateway(ctx, port): + try: + options = { + 'bind': '%s:%s' % ('0.0.0.0', str(port)), + 'workers': number_of_workers(), + 'workerconnections': 1000, + 'timeout': 300, + 'errorlog': '-', + 'accesslog': '-', + 'gw': ctx.obj['gw'].eco + } + Application(options).run() + except (KeyboardInterrupt, SystemExit, SystemError): + pass + + +@publish.command('fountain') +@click.pass_context +@click.option('--port', default=5000) +def publish_fountain(ctx, port): + fountain = ctx.obj['gw'].agora.fountain + server = fs(fountain) + server.run(host='0.0.0.0', port=port, threaded=True) + + +@publish.command('planner') +@click.pass_context +@click.option('--port', default=5000) +def publish_planner(ctx, port): + planner = ctx.obj['gw'].agora.planner + server = ps(planner) + server.run(host='0.0.0.0', port=port, threaded=True) + + +def query_f(dgw, incremental, scholar): + def wrapper(*args, **kwargs): + kwargs['incremental'] = incremental + kwargs['scholar'] = scholar + return dgw.query(*args, **kwargs) + + return wrapper + + +@publish.command('sparql') +@click.argument('q') +@click.option('--incremental', is_flag=True, default=False) +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def publish_sparql(ctx, q, incremental, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, + host, + port): + check_init(ctx) + + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + else: + cache = None + + click.echo('Discovering ecosystem...', nl=False) + dgw = ctx.obj['gw'].data(q, cache=cache, lazy=False, server_name=host, port=port, base='.agora/store/fragments') + click.echo('Done') + + server = ss(ctx.obj['gw'].agora, query_function=query_f(dgw, incremental, fragment_cache)) + server.run(host='0.0.0.0', port=port, threaded=True) + click.echo() + + +def fragment_f(dgw, scholar): + def wrapper(*args, **kwargs): + kwargs['scholar'] = scholar + return dgw.fragment(*args, **kwargs) + + return wrapper + + +@publish.command('fragment') +@click.argument('q') +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def publish_sparql(ctx, q, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, + port): + check_init(ctx) + + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + else: + cache = None + + click.echo('Discovering ecosystem...', nl=False) + dgw = ctx.obj['gw'].data(q, cache=cache, lazy=False, server_name=host, port=port, base='.agora/store/fragments') + click.echo('Done') + + server = frs(ctx.obj['gw'].agora, fragment_function=fragment_f(dgw, fragment_cache)) + server.run(host='0.0.0.0', port=port, threaded=True) + click.echo() + + +@publish.command('ui') +@click.argument('q') +@click.option('--incremental', is_flag=True, default=False) +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def publish_ui(ctx, q, incremental, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, + port): + check_init(ctx) + + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + else: + cache = None + + click.echo('Discovering ecosystem...', nl=False) + dgw = ctx.obj['gw'].data(q, cache=cache, lazy=False, server_name=host, port=port, base='.agora/store/fragments') + click.echo('Done') + + server = fs(ctx.obj['gw'].agora.fountain) + frs(ctx.obj['gw'].agora, server=server, fragment_function=fragment_f(dgw, fragment_cache)) + ss(ctx.obj['gw'].agora, server=server, query_function=query_f(dgw, incremental, fragment_cache)) + server.run(host='0.0.0.0', port=port, threaded=True) + click.echo() + + +@publish.command('gql') +@click.option('--schema-file') +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def publish_gql(ctx, schema_file, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, + port): + check_init(ctx) + + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + else: + cache = None + + app = Flask(__name__) + CORS(app) + + ctx.obj['gw'].data_cache = cache + gql_processor = GraphQLProcessor(ctx.obj['gw'], schema_file) + + app.add_url_rule('/graphql', + view_func=AgoraGraphQLView.as_view('graphql', schema=gql_processor.schema, + executor=gql_processor.executor, + middleware=gql_processor.middleware, + graphiql=True)) + + options = { + 'bind': '%s:%s' % ('0.0.0.0', str(port)), + 'workers': number_of_workers(), + 'threads': 1, + 'workerconnections': 1000, + 'timeout': 4000, + 'workerclass': 'gthread', + 'errorlog': '-', + 'accesslog': '-' + } + GQLApplication(app, options).run() diff --git a/agora_cli/qgl.py b/agora_cli/qgl.py new file mode 100644 index 0000000..6588be6 --- /dev/null +++ b/agora_cli/qgl.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" +import json +from Queue import Empty, Queue +from datetime import datetime +from threading import Thread + +import click +from agora import RedisCache +from agora.engine.utils import Semaphore +from rdflib import URIRef, BNode + +from agora_cli.root import cli +from agora_cli.utils import split_arg, check_init, jsonify +from agora_graphql.gql import GraphQLProcessor + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def gql(ctx): + check_init(ctx) + + +@gql.command() +@click.argument('q') +@click.option('--schema-file', type=click.Path(exists=True)) +# @click.option('--incremental', is_flag=True, default=False) +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def query(ctx, q, schema_file, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, + port): + check_init(ctx) + + q = q.replace("'", '"') + 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', + 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, server_name=host, + port=port) + res = processor.query(q) + click.echo(jsonify(res.to_dict())) diff --git a/agora_cli/query.py b/agora_cli/query.py new file mode 100644 index 0000000..f1fe926 --- /dev/null +++ b/agora_cli/query.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" +import json +from Queue import Empty, Queue +from datetime import datetime +from threading import Thread + +import click +from agora import RedisCache +from agora.engine.utils import Semaphore +from rdflib import URIRef, BNode + +from agora_cli.root import cli +from agora_cli.utils import split_arg, check_init + +__author__ = 'Fernando Serena' + + +def head(row): + return {'vars': list(row.labels)} + + +def value_type(value): + if isinstance(value, URIRef): + return 'uri' + elif isinstance(value, BNode): + return 'bnode' + else: + if value.datatype is not None: + return 'typed-literal' + return 'literal' + + +def result(row): + def r_dict(l): + value = row[l] + type = value_type(value) + value_p = value.toPython() + if isinstance(value_p, datetime): + value_p = str(value_p) + res = {"type": type, "value": value_p} + if 'literal' in type: + if value.datatype: + res['datatype'] = value.datatype.toPython() + if value.language: + res['xml:lang'] = str(value.language) + return res + + return {l: r_dict(l) for l in row.labels if row[l] is not None} + + +def gen_thread(status, queue, gen): + first = True + try: + for row in gen: + if first: + queue.put(u'{\n') + queue.put(u' "head": %s,\n "results": {\n "bindings": [\n' % json.dumps(head(row))) + first = False + else: + queue.put(',\n') + queue.put(u' {}'.format(json.dumps(result(row), ensure_ascii=False))) + if first: + queue.put('{\n') + queue.put(' "head": [],\n "results": {\n "bindings": []\n }\n') + else: + queue.put('\n ]\n }\n') + queue.put('}') + except Exception, e: + exception = e + print e.message + + status['completed'] = True + + +def gen_queue(status, stop_event, queue): + with stop_event: + while not status['completed'] or not queue.empty(): + status['last'] = datetime.now() + try: + for chunk in queue.get(timeout=1.0): + yield chunk + except Empty: + if not status['completed']: + pass + elif status['exception']: + raise Exception(status['exception'].message) + + +@cli.command() +@click.argument('q') +@click.option('--arg', multiple=True) +@click.option('--incremental', is_flag=True, default=False) +@click.option('--cache-file') +@click.option('--cache-host') +@click.option('--cache-port') +@click.option('--cache-db') +@click.option('--resource-cache', is_flag=True, default=False) +@click.option('--fragment-cache', is_flag=True, default=False) +@click.option('--host', default='agora') +@click.option('--port', default=80) +@click.pass_context +def query(ctx, q, arg, incremental, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, + port): + check_init(ctx) + + args = dict(map(lambda a: split_arg(a), arg)) + + 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', + path='', + redis_host=cache_host, + redis_db=cache_db, + redis_port=cache_port) + else: + cache = None + stop = Semaphore() + queue = Queue() + + click.echo('Discovering ecosystem...', nl=False) + dgw = ctx.obj['gw'].data(q, cache=cache, lazy=False, server_name=host, port=port, base='.agora/store/fragments') + click.echo('Done') + gen = dgw.query(q, incremental=incremental, stop_event=stop, scholar=fragment_cache, **args) + + request_status = { + 'completed': False, + 'exception': None + } + stream_th = Thread(target=gen_thread, args=(request_status, queue, gen)) + stream_th.daemon = False + stream_th.start() + + for chunk in gen_queue(request_status, stop, queue): + click.echo(chunk, nl=False) + + click.echo() diff --git a/agora_cli/root.py b/agora_cli/root.py new file mode 100644 index 0000000..d5a3268 --- /dev/null +++ b/agora_cli/root.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" +import logging + +import click +from agora import setup_logging, Agora +from agora_gw import Gateway + +from agora_cli.utils import load_config, mute_logger, load_host_replacements + +__author__ = 'Fernando Serena' + +mute_logger('jsonpath_ng') +mute_logger('rdflib') +mute_logger('agora') + + +@click.group() +@click.option('--debug', is_flag=True, default=False) +@click.version_option() +@click.pass_context +def cli(ctx, debug): + config = load_config() + if config is not None: + if debug: + setup_logging(logging.DEBUG) + + gw = Gateway(**config) + ctx.call_on_close(lambda: Agora.close()) + ctx.obj = {'gw': gw, 'config': config, 'repls': load_host_replacements()} diff --git a/agora_cli/show.py b/agora_cli/show.py new file mode 100644 index 0000000..2eba611 --- /dev/null +++ b/agora_cli/show.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import click +from agora_wot.blocks.td import TD + +from agora_cli.root import cli +from agora_cli.utils import jsonify, show_ted, show_td, show_thing, check_init, load_config, error + +__author__ = 'Fernando Serena' + + +@cli.group() +@click.pass_context +def show(ctx): + check_init(ctx) + + +@show.command('extension') +@click.pass_context +@click.argument('name') +def show_extension(ctx, name): + gw = ctx.obj['gw'] + g = gw.get_extension(name) + click.echo(g.serialize(format='turtle')) + + +@show.command('prefixes') +@click.pass_context +def show_prefixes(ctx): + gw = ctx.obj['gw'] + print jsonify(gw.agora.fountain.prefixes) + + +@show.command('type') +@click.pass_context +@click.argument('name') +def show_prefixes(ctx, name): + gw = ctx.obj['gw'] + print jsonify(gw.agora.fountain.get_type(name)) + + +@show.command('property') +@click.pass_context +@click.argument('name') +def show_prefixes(ctx, name): + gw = ctx.obj['gw'] + print jsonify(gw.agora.fountain.get_property(name)) + + +@show.command('paths') +@click.pass_context +@click.argument('source') +@click.argument('dest') +def show_paths(ctx, source, dest): + gw = ctx.obj['gw'] + + print jsonify( + gw.agora.fountain.get_paths(dest, force_seed=[('<{}-uri>'.format(source.lower()).replace(':', '-'), source)])) + + +@show.command('ted') +@click.pass_context +@click.option('--turtle', default=False, is_flag=True) +def _show_ted(ctx, turtle): + ted = ctx.obj['gw'].ted + show_ted(ted, format='text/turtle' if turtle else 'application/ld+json') + + +@show.command('td') +@click.argument('id', type=unicode) +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def _show_td(ctx, id, turtle): + try: + td = ctx.obj['gw'].get_description(id) + show_td(td, format='text/turtle' if turtle else 'application/ld+json') + except Exception as e: + error(u'{},{}'.format(type(e), e.message)) + + +@show.command('thing') +@click.argument('id', type=unicode) +@click.option('--turtle', default=False, is_flag=True) +@click.pass_context +def _show_thing(ctx, id, turtle): + g = ctx.obj['gw'].get_thing(id).to_graph() + show_thing(g, format='text/turtle' if turtle else 'application/ld+json') + + +@show.command('ted-args') +@click.pass_obj +def show_ted_args(obj): + td_roots = list(filter(lambda r: isinstance(r, TD), obj['ted'].ecosystem.roots)) + res = {} + for td in td_roots: + res[td.id] = list(obj['ted'].ecosystem.root_vars(td)) + + click.echo(jsonify(res)) + + +@show.command('config') +@click.pass_context +def show_config(ctx): + click.echo(jsonify(load_config())) diff --git a/agora_cli/utils.py b/agora_cli/utils.py new file mode 100644 index 0000000..cc1a03b --- /dev/null +++ b/agora_cli/utils.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2018 Fernando Serena +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" +import json +import logging + +import click +from agora_gw.data.repository import CORE +from agora_gw.ecosystem.serialize import serialize_graph +from rdflib import URIRef, RDF +import os +import os.path as path + +__author__ = 'Fernando Serena' + + +def split_arg(a): + kv = tuple(a.split('=')) + if len(kv) == 1: + kv = a, '' + elif len(kv) > 2: + kv = kv[:1] + return kv + + +def show_ted(ted, format): + g = ted.to_graph() + ttl = serialize_graph(g, format, frame=CORE.ThingEcosystemDescription, skolem=False) + click.echo(ttl) + + +def error(msg): + click.echo('[FAIL]: ' + msg, err=True) + + +def show_td(td, format): + g = td.to_graph() + ttl = serialize_graph(g, format, frame=CORE.ThingDescription, skolem=False) + click.echo(ttl) + + +def show_thing(g, format): + th_node = g.identifier + th_types = list(g.objects(URIRef(th_node), RDF.type)) + th_type = th_types.pop() if th_types else None + ttl = serialize_graph(g, format, frame=th_type, skolem=False) + click.echo(ttl) + + +def jsonify(obj): + return json.dumps(obj, indent=3, sort_keys=True, ensure_ascii=False) + + +def store_config(**kwargs): + host = kwargs['host'] + port = kwargs['port'] + if host and port: + config = { + 'host': host, + 'port': port + } + else: + remote_repo_cache = all([kwargs['repo_cache_host'], kwargs['repo_cache_db'], kwargs['repo_cache_port']]) + + config = { + "repository": { + "extension_base": kwargs['extension_base'], + "repository_base": kwargs['repository_base'], + "data": { + "persist_mode": True, + "base": ".agora/store", + "path": "ted", + "cache": { + "file": None if remote_repo_cache else ".agora/store/ted/repo.db", + "host": kwargs['repo_cache_host'], + "port": kwargs['repo_cache_port'], + "db": kwargs['repo_cache_db'] + } + } + }, + "engine": { + "persist_mode": True, + "base": ".agora/store", + "path": "fountain", + "redis_file": "fountain.db" + } + } + + with open('.agora/config', 'wb') as f: + json.dump(config, f, indent=3) + store_host_replacements({}) + + +def load_config(): + if is_init(): + with open('.agora/config', 'r') as f: + return json.load(f) + + +def check_init(ctx): + if ctx.obj is None: + click.echo('[FAIL] Agora is not initialized: ', nl=False) + ctx.abort() + + +def is_init(): + return path.exists('.agora') and path.isdir('.agora') and path.exists('.agora/config') + + +def init_base(): + os.makedirs('.agora') + + +def mute_logger(name): + log = logging.getLogger(name) + log.setLevel(logging.CRITICAL) + ch = logging.StreamHandler() + log.addHandler(ch) + + +def load_host_replacements(): + if is_init(): + with open('.agora/repls', 'r') as f: + return json.load(f) + + +def store_host_replacements(repls): + with open('.agora/repls', 'wb') as f: + json.dump(repls, f, indent=3) diff --git a/contributors.txt b/contributors.txt new file mode 100644 index 0000000..eeb65d7 --- /dev/null +++ b/contributors.txt @@ -0,0 +1 @@ +Fernando Serena diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..aa02a44 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +click +rdflib==4.2.1 +SPARQLWrapper +pyld +rdflib-jsonld +shortuuid +agora-py +agora-wot +agora-gw +agora-graphql diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..705a66f --- /dev/null +++ b/setup.py @@ -0,0 +1,53 @@ +""" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Ontology Engineering Group + http://www.oeg-upm.net/ +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Copyright (C) 2017 Ontology Engineering Group. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# +""" + +import json + +from setuptools import setup, find_packages + +__author__ = 'Fernando Serena' + +with open("agora_cli/metadata.json", 'r') as stream: + metadata = json.load(stream) + +setup( + name="agora-cli", + version=metadata['version'], + author=metadata['author'], + author_email=metadata['email'], + description=metadata['description'], + license="Apache 2", + keywords=["agora", "discovery", "linked data"], + url=metadata['github'], + download_url="https://github.com/fserena/agora-cli/tarball/{}".format(metadata['version']), + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + install_requires=['click', 'rdflib==4.2.1', 'SPARQLWrapper', 'pyld', 'rdflib-jsonld', 'shortuuid', 'agora-py', + 'agora-wot', 'agora-gw', 'agora-graphql'], + classifiers=[], + include_package_data=True, + package_dir={'agora_cli': 'agora_cli'}, + package_data={'agora_cli': ['metadata.json']}, + #scripts=['agora'], + entry_points={ + 'console_scripts': ['agora=agora_cli.root:cli'] + } + +) \ No newline at end of file