mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 16:36:21 +02:00
Collection management (#520)
* Tech spec * Refactored Cassanda knowledge graph for single table * Collection management, librarian services to manage metadata and collection deletion
This commit is contained in:
parent
48016d8fb2
commit
13ff7d765d
48 changed files with 2941 additions and 425 deletions
85
trustgraph-cli/trustgraph/cli/list_collections.py
Normal file
85
trustgraph-cli/trustgraph/cli/list_collections.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
"""
|
||||
List collections for a user
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_user = "trustgraph"
|
||||
|
||||
def list_collections(url, user, tag_filter):
|
||||
|
||||
api = Api(url).collection()
|
||||
|
||||
collections = api.list_collections(user=user, tag_filter=tag_filter)
|
||||
|
||||
if len(collections) == 0:
|
||||
print("No collections.")
|
||||
return
|
||||
|
||||
table = []
|
||||
for collection in collections:
|
||||
table.append([
|
||||
collection.collection,
|
||||
collection.name,
|
||||
collection.description,
|
||||
", ".join(collection.tags),
|
||||
collection.created_at,
|
||||
collection.updated_at
|
||||
])
|
||||
|
||||
headers = ["Collection", "Name", "Description", "Tags", "Created", "Updated"]
|
||||
|
||||
print(tabulate.tabulate(
|
||||
table,
|
||||
headers=headers,
|
||||
tablefmt="pretty",
|
||||
stralign="left",
|
||||
maxcolwidths=[20, 30, 50, 30, 19, 19],
|
||||
))
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-list-collections',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-U', '--user',
|
||||
default=default_user,
|
||||
help=f'User ID (default: {default_user})'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--tag-filter',
|
||||
action='append',
|
||||
help='Filter by tags (can be specified multiple times)'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
list_collections(
|
||||
url = args.api_url,
|
||||
user = args.user,
|
||||
tag_filter = args.tag_filter
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue