mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-21 03:01:03 +02:00
More CLI supportt
This commit is contained in:
parent
57d8d47d2f
commit
573f14e67b
5 changed files with 238 additions and 7 deletions
|
|
@ -108,7 +108,7 @@ class Library:
|
|||
input = {
|
||||
"operation": "get-document",
|
||||
"user": user,
|
||||
"document-id", id,
|
||||
"document-id": id,
|
||||
}
|
||||
|
||||
object = self.request(input)
|
||||
|
|
@ -137,19 +137,16 @@ class Library:
|
|||
raise ProtocolException(f"Response not formatted correctly")
|
||||
|
||||
def update_document(self, user, id, metadata):
|
||||
"s": { "v": t["s"], "e": isinstance(t["s"], Uri) },
|
||||
"p": { "v": t["p"], "e": isinstance(t["p"], Uri) },
|
||||
"o": { "v": t["o"], "e": isinstance(t["o"], Uri) }
|
||||
|
||||
input = {
|
||||
"operation": "update-document",
|
||||
"document-metadata": {
|
||||
"user": user,
|
||||
"document-id", id,
|
||||
"document-id": id,
|
||||
"time": metadata.time,
|
||||
"title": metadata.title,
|
||||
"comments": metadata.comments,
|
||||
metadata = [
|
||||
"metadata": [
|
||||
{
|
||||
"s": { "v": t["s"], "e": isinstance(t["s"], Uri) },
|
||||
"p": { "v": t["p"], "e": isinstance(t["p"], Uri) },
|
||||
|
|
@ -250,8 +247,9 @@ class Library:
|
|||
document_id = v["document-id"],
|
||||
time = datetime.datetime.fromtimestamp(v["time"]),
|
||||
flow = v["flow"],
|
||||
user = v["user"],
|
||||
collection = v["collection"],
|
||||
tags = v["tags"]
|
||||
tags = v["tags"],
|
||||
)
|
||||
for v in object["processing-metadatas"]
|
||||
]
|
||||
|
|
|
|||
74
trustgraph-cli/scripts/tg-show-library-processing
Normal file
74
trustgraph-cli/scripts/tg-show-library-processing
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api, ConfigKey
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_user = "trustgraph"
|
||||
|
||||
def show_procs(url, user):
|
||||
|
||||
api = Api(url).library()
|
||||
|
||||
procs = api.get_processings(user = user)
|
||||
|
||||
if len(procs) == 0:
|
||||
print("No processing objects.")
|
||||
return
|
||||
|
||||
for proc in procs:
|
||||
|
||||
table = []
|
||||
table.append(("id", proc.id))
|
||||
table.append(("document-id", proc.document_id))
|
||||
table.append(("time", proc.time))
|
||||
table.append(("flow", proc.flow))
|
||||
table.append(("collection", proc.collection))
|
||||
table.append(("tags", ", ".join(proc.tags)))
|
||||
|
||||
print(tabulate.tabulate(
|
||||
table,
|
||||
tablefmt="pretty",
|
||||
stralign="left",
|
||||
))
|
||||
print()
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-show-library-processing',
|
||||
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})'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_procs(
|
||||
url = args.api_url, user = args.user
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
93
trustgraph-cli/scripts/tg-start-library-processing
Normal file
93
trustgraph-cli/scripts/tg-start-library-processing
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api, ConfigKey
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_user = "trustgraph"
|
||||
|
||||
def start_processing(
|
||||
url, user, document_id, processing_id, flow, collection, tags
|
||||
):
|
||||
|
||||
api = Api(url).library()
|
||||
|
||||
tags = tags.split(",")
|
||||
|
||||
api.start_processing(document_id, processing_id, flow, user,
|
||||
collection, tags)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-start-library-processing',
|
||||
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(
|
||||
'-i', '--flow-id',
|
||||
default="0000",
|
||||
help=f'Flow ID (default: 0000)',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-d', '--did', '--document-id',
|
||||
required=True,
|
||||
help=f'Document ID',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--id', '--processing-id',
|
||||
required=True,
|
||||
help=f'Processing ID',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--collection',
|
||||
default='default',
|
||||
help=f'Collection (default: default)'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--tags',
|
||||
help=f'Tags, command separated'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
start_processing(
|
||||
url = args.api_url,
|
||||
user = args.user,
|
||||
document_id = args.document_id,
|
||||
processing_id = args.id,
|
||||
flow = args.flow_id,
|
||||
collection = args.collection,
|
||||
tags = args.tags
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
63
trustgraph-cli/scripts/tg-stop-library-processing
Normal file
63
trustgraph-cli/scripts/tg-stop-library-processing
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api, ConfigKey
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_user = "trustgraph"
|
||||
|
||||
def stop_processing(
|
||||
url, user, id
|
||||
):
|
||||
|
||||
api = Api(url).library()
|
||||
|
||||
api.stop_processing(user, id)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-stop-library-processing',
|
||||
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(
|
||||
'--id', '--processing-id',
|
||||
required=True,
|
||||
help=f'Processing ID',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
stop_processing(
|
||||
url = args.api_url,
|
||||
user = args.user,
|
||||
id = args.id,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
|
|
@ -71,6 +71,9 @@ setuptools.setup(
|
|||
"scripts/tg-show-flow-state",
|
||||
"scripts/tg-show-flows",
|
||||
"scripts/tg-show-library-documents",
|
||||
"scripts/tg-show-library-processing",
|
||||
"scripts/tg-start-library-processing",
|
||||
"scripts/tg-stop-library-processing",
|
||||
"scripts/tg-add-library-document",
|
||||
"scripts/tg-remove-library-document",
|
||||
"scripts/tg-show-processor-state",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue