2024-07-10 23:20:06 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2024-07-12 15:06:51 +01:00
|
|
|
"""
|
2024-08-14 09:06:33 +01:00
|
|
|
Connects to the graph query service and dumps all graph edges.
|
2024-07-12 15:06:51 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import argparse
|
2024-08-14 09:06:33 +01:00
|
|
|
import os
|
2024-09-30 16:16:20 +01:00
|
|
|
from trustgraph.clients.triples_query_client import TriplesQueryClient
|
2024-07-12 15:06:51 +01:00
|
|
|
|
2024-09-09 22:03:10 +01:00
|
|
|
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
2024-10-02 18:14:29 +01:00
|
|
|
default_user = 'trustgraph'
|
|
|
|
|
default_collection = 'default'
|
2024-07-10 23:20:06 +01:00
|
|
|
|
2024-10-02 18:14:29 +01:00
|
|
|
def show_graph(pulsar, user, collection):
|
2024-07-12 15:06:51 +01:00
|
|
|
|
2024-09-09 17:16:50 +01:00
|
|
|
tq = TriplesQueryClient(pulsar_host=pulsar)
|
2024-07-12 15:06:51 +01:00
|
|
|
|
2024-10-02 18:14:29 +01:00
|
|
|
rows = tq.request(
|
|
|
|
|
user=user, collection=collection,
|
|
|
|
|
s=None, p=None, o=None, limit=10_000_000
|
|
|
|
|
)
|
2024-07-12 15:06:51 +01:00
|
|
|
|
2024-08-14 09:06:33 +01:00
|
|
|
for row in rows:
|
|
|
|
|
print(row.s.value, row.p.value, row.o.value)
|
2024-07-12 15:06:51 +01:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
prog='graph-show',
|
|
|
|
|
description=__doc__,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2024-08-14 09:06:33 +01:00
|
|
|
'-p', '--pulsar-host',
|
|
|
|
|
default=default_pulsar_host,
|
|
|
|
|
help=f'Pulsar host (default: {default_pulsar_host})',
|
2024-07-12 15:06:51 +01:00
|
|
|
)
|
|
|
|
|
|
2024-10-02 18:14:29 +01:00
|
|
|
parser.add_argument(
|
|
|
|
|
'-u', '--user',
|
|
|
|
|
default=default_user,
|
|
|
|
|
help=f'User ID (default: {default_user})'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'-c', '--collection',
|
|
|
|
|
default=default_collection,
|
|
|
|
|
help=f'Collection ID (default: {default_collection})'
|
|
|
|
|
)
|
|
|
|
|
|
2024-07-12 15:06:51 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
2024-10-02 18:14:29 +01:00
|
|
|
show_graph(
|
|
|
|
|
pulsar=args.pulsar_host, user=args.user,
|
|
|
|
|
collection=args.collection,
|
|
|
|
|
)
|
2024-07-12 15:06:51 +01:00
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
|
|
print("Exception:", e, flush=True)
|
2024-07-10 23:20:06 +01:00
|
|
|
|
2024-07-12 15:06:51 +01:00
|
|
|
main()
|
2024-07-10 23:20:06 +01:00
|
|
|
|