trustgraph-cli 2.6.14__tar.gz → 2.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/PKG-INFO +2 -2
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/pyproject.toml +1 -1
- trustgraph_cli-2.7.0/trustgraph/cli/export_workspace.py +301 -0
- trustgraph_cli-2.7.0/trustgraph/cli/import_workspace.py +420 -0
- trustgraph_cli-2.7.0/trustgraph/cli/nquads.py +137 -0
- trustgraph_cli-2.7.0/trustgraph/cli_version.py +1 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph_cli.egg-info/PKG-INFO +2 -2
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph_cli.egg-info/SOURCES.txt +1 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph_cli.egg-info/requires.txt +1 -1
- trustgraph_cli-2.6.14/trustgraph/cli/export_workspace.py +0 -141
- trustgraph_cli-2.6.14/trustgraph/cli/import_workspace.py +0 -194
- trustgraph_cli-2.6.14/trustgraph/cli_version.py +0 -1
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/README.md +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/setup.cfg +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/__init__.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/_iam.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/add_library_document.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/bootstrap_iam.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/change_password.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/create_api_key.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/create_user.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/create_workspace.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_collection.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_config_item.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_flow_blueprint.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_kg_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_mcp_tool.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_tool.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/delete_user.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/disable_user.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/dump_msgpack.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/dump_queues.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/enable_user.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/export_workspace_config.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/get_config_item.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/get_de_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/get_document_content.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/get_flow_blueprint.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/get_kg_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/graph_to_turtle.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/import_workspace_config.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/init_pulsar_manager.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_agent.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_document_embeddings.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_document_rag.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_embeddings.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_graph_embeddings.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_graph_rag.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_llm.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_mcp_tool.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_nlp_query.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_prompt.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_reranker.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_row_embeddings.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_rows_query.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_sparql_query.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/invoke_structured_query.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_api_keys.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_collections.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_config_items.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_explain_traces.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_my_workspaces.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_users.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/list_workspaces.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/load_doc_embeds.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/load_kg_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/load_knowledge.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/load_sample_documents.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/load_structured_data.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/load_turtle.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/login.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/monitor_prompts.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/put_config_item.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/put_de_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/put_flow_blueprint.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/put_kg_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/query_graph.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/remove_library_document.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/reset_password.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/revoke_api_key.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/__init__.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/belgian-beer.md +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/bronze-age-collapse.pdf +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/corporate-scandals.pdf +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/history-of-pets.md +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/metadata.json +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/mil-fortifications-america-19th-c.md +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/recipes.md +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/sample_documents/trade-routes-europe.md +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/save_doc_embeds.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/set_collection.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/set_mcp_tool.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/set_prompt.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/set_token_costs.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/set_tool.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_config.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_explain_trace.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_extraction_provenance.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_flow_blueprints.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_flow_state.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_flows.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_graph.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_kg_cores.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_library_documents.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_library_processing.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_mcp_tools.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_parameter_types.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_processor_state.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_prompts.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_token_costs.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_token_rate.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/show_tools.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/start_flow.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/start_library_processing.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/stop_flow.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/stop_library_processing.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/unload_kg_core.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/update_user.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/verify_system_status.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph/cli/whoami.py +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph_cli.egg-info/entry_points.txt +0 -0
- {trustgraph_cli-2.6.14 → trustgraph_cli-2.7.0}/trustgraph_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trustgraph-cli
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.7.0
|
|
4
4
|
Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
|
|
5
5
|
Author-email: "trustgraph.ai" <security@trustgraph.ai>
|
|
6
6
|
Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
|
|
@@ -8,7 +8,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
8
8
|
Classifier: Operating System :: OS Independent
|
|
9
9
|
Requires-Python: >=3.8
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
|
-
Requires-Dist: trustgraph-base<2.
|
|
11
|
+
Requires-Dist: trustgraph-base<2.8,>=2.7
|
|
12
12
|
Requires-Dist: requests
|
|
13
13
|
Requires-Dist: pulsar-client
|
|
14
14
|
Requires-Dist: aiohttp
|
|
@@ -10,7 +10,7 @@ description = "TrustGraph provides a means to run a pipeline of flexible AI proc
|
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.8"
|
|
12
12
|
dependencies = [
|
|
13
|
-
"trustgraph-base>=2.
|
|
13
|
+
"trustgraph-base>=2.7,<2.8",
|
|
14
14
|
"requests",
|
|
15
15
|
"pulsar-client",
|
|
16
16
|
"aiohttp",
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exports a workspace's full state as a portable .tgx bundle (a gzipped tar
|
|
3
|
+
archive) for backup, migration between deployments, or sharing a
|
|
4
|
+
pre-configured workspace.
|
|
5
|
+
|
|
6
|
+
The bundle carries the workspace configuration (one pretty-printed JSON
|
|
7
|
+
file per config key) and, by default, its knowledge: per-collection
|
|
8
|
+
knowledge-graph triples as N-Quads (the collection names the graph) and
|
|
9
|
+
the document library (metadata plus content). Pass --config-only to
|
|
10
|
+
export just the configuration. Embedding vectors are not exported —
|
|
11
|
+
re-processing imported documents through a flow regenerates them.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import io
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import tarfile
|
|
20
|
+
import tempfile
|
|
21
|
+
import time
|
|
22
|
+
from urllib.parse import quote
|
|
23
|
+
|
|
24
|
+
from trustgraph.api import Api
|
|
25
|
+
|
|
26
|
+
from . nquads import serialize_nquads
|
|
27
|
+
|
|
28
|
+
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
29
|
+
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
|
30
|
+
default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
|
|
31
|
+
|
|
32
|
+
MANIFEST_FORMAT = "tgx"
|
|
33
|
+
MANIFEST_FORMAT_VERSION = 1
|
|
34
|
+
|
|
35
|
+
# triples_query_stream is bounded by a limit; exports want "everything", so
|
|
36
|
+
# default high and let --triples-limit override for truly huge graphs.
|
|
37
|
+
DEFAULT_TRIPLES_LIMIT = 1_000_000
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _add_bytes(tar, name, data):
|
|
41
|
+
info = tarfile.TarInfo(name=name)
|
|
42
|
+
info.size = len(data)
|
|
43
|
+
info.mtime = int(time.time())
|
|
44
|
+
tar.addfile(info, io.BytesIO(data))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _export_config(tar, config):
|
|
48
|
+
"""Write one self-describing JSON file per config key; return count."""
|
|
49
|
+
count = 0
|
|
50
|
+
for type_, entries in sorted(config.items()):
|
|
51
|
+
for key, raw in sorted(entries.items()):
|
|
52
|
+
|
|
53
|
+
# Config values are stored as JSON strings; parse so the
|
|
54
|
+
# bundle is pretty-printed and hand-editable. A value that
|
|
55
|
+
# isn't valid JSON is preserved verbatim.
|
|
56
|
+
try:
|
|
57
|
+
value = json.loads(raw)
|
|
58
|
+
except (TypeError, json.JSONDecodeError):
|
|
59
|
+
value = raw
|
|
60
|
+
|
|
61
|
+
entry = {"type": type_, "key": key, "value": value}
|
|
62
|
+
|
|
63
|
+
# Keys may contain path-unsafe characters; the entry embeds
|
|
64
|
+
# the real key, so the quoted filename is cosmetic only.
|
|
65
|
+
name = f"config/{quote(type_, safe='')}/{quote(key, safe='')}.json"
|
|
66
|
+
|
|
67
|
+
_add_bytes(
|
|
68
|
+
tar, name,
|
|
69
|
+
json.dumps(entry, indent=2).encode("utf-8"),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
count += 1
|
|
73
|
+
return count
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _export_triples(tar, api, flow_id, collections, triples_limit):
|
|
77
|
+
"""Stream each collection's triples into knowledge/<c>/triples.nq.
|
|
78
|
+
|
|
79
|
+
N-Quads are written to a tempfile first (tar members need their size
|
|
80
|
+
upfront), so memory stays flat regardless of knowledge-base size.
|
|
81
|
+
Returns {collection: written} and a total skipped count.
|
|
82
|
+
"""
|
|
83
|
+
counts = {}
|
|
84
|
+
skipped_total = 0
|
|
85
|
+
socket = api.socket()
|
|
86
|
+
try:
|
|
87
|
+
flow = socket.flow(flow_id)
|
|
88
|
+
for c in collections:
|
|
89
|
+
graph_iri = f"urn:trustgraph:collection:{quote(c, safe='')}"
|
|
90
|
+
tmp = tempfile.NamedTemporaryFile(
|
|
91
|
+
"w", encoding="utf-8", suffix=".nq", delete=False,
|
|
92
|
+
)
|
|
93
|
+
try:
|
|
94
|
+
with tmp:
|
|
95
|
+
written, skipped = serialize_nquads(
|
|
96
|
+
flow.triples_query_stream(
|
|
97
|
+
s=None, p=None, o=None,
|
|
98
|
+
collection=c,
|
|
99
|
+
limit=triples_limit,
|
|
100
|
+
batch_size=100,
|
|
101
|
+
),
|
|
102
|
+
graph_iri,
|
|
103
|
+
tmp,
|
|
104
|
+
)
|
|
105
|
+
if written:
|
|
106
|
+
tar.add(
|
|
107
|
+
tmp.name,
|
|
108
|
+
arcname=(
|
|
109
|
+
f"knowledge/{quote(c, safe='')}/triples.nq"
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
counts[c] = written
|
|
113
|
+
skipped_total += skipped
|
|
114
|
+
finally:
|
|
115
|
+
os.unlink(tmp.name)
|
|
116
|
+
finally:
|
|
117
|
+
socket.close()
|
|
118
|
+
return counts, skipped_total
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _export_library(tar, api):
|
|
122
|
+
"""Write each library document's metadata + content; return count."""
|
|
123
|
+
library = api.library()
|
|
124
|
+
count = 0
|
|
125
|
+
for doc in library.get_documents(include_children=True):
|
|
126
|
+
# Content is fetched one document at a time so memory is bounded
|
|
127
|
+
# by the largest single document, not the whole library.
|
|
128
|
+
content = library.get_document_content(doc.id)
|
|
129
|
+
meta = {
|
|
130
|
+
"id": doc.id,
|
|
131
|
+
"time": doc.time.isoformat() if doc.time else None,
|
|
132
|
+
"kind": doc.kind,
|
|
133
|
+
"title": doc.title,
|
|
134
|
+
"comments": doc.comments,
|
|
135
|
+
"metadata": [
|
|
136
|
+
{"s": t.s, "p": t.p, "o": t.o} for t in (doc.metadata or [])
|
|
137
|
+
],
|
|
138
|
+
"tags": list(doc.tags or []),
|
|
139
|
+
"parent_id": doc.parent_id or "",
|
|
140
|
+
"document_type": getattr(doc, "document_type", "") or "",
|
|
141
|
+
}
|
|
142
|
+
base = f"knowledge/library/{quote(doc.id, safe='')}"
|
|
143
|
+
_add_bytes(
|
|
144
|
+
tar, f"{base}.meta.json",
|
|
145
|
+
json.dumps(meta, indent=2).encode("utf-8"),
|
|
146
|
+
)
|
|
147
|
+
_add_bytes(tar, f"{base}.content", content or b"")
|
|
148
|
+
count += 1
|
|
149
|
+
return count
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def export_workspace(
|
|
153
|
+
url, workspace, output, token=None, config_only=False,
|
|
154
|
+
flow_id="default", triples_limit=DEFAULT_TRIPLES_LIMIT,
|
|
155
|
+
extra_collections=(),
|
|
156
|
+
):
|
|
157
|
+
|
|
158
|
+
api = Api(url, token=token, workspace=workspace)
|
|
159
|
+
|
|
160
|
+
config, version = api.config().all()
|
|
161
|
+
|
|
162
|
+
# Collection discovery is registry-based: collections created implicitly
|
|
163
|
+
# by raw triple loads (e.g. tg-load-knowledge) are queryable but not
|
|
164
|
+
# listed, so they would silently drop out of the bundle. --collection
|
|
165
|
+
# names them explicitly; the enumeration is printed so what's included
|
|
166
|
+
# is never a guess.
|
|
167
|
+
collections = []
|
|
168
|
+
if not config_only:
|
|
169
|
+
registered = [c.collection for c in api.collection().list_collections()]
|
|
170
|
+
collections = sorted(set(registered) | set(extra_collections))
|
|
171
|
+
print(f"Exporting collections: {', '.join(collections)}", flush=True)
|
|
172
|
+
|
|
173
|
+
with tarfile.open(output, "w:gz") as tar:
|
|
174
|
+
|
|
175
|
+
config_count = _export_config(tar, config)
|
|
176
|
+
|
|
177
|
+
triple_counts = {}
|
|
178
|
+
skipped = 0
|
|
179
|
+
doc_count = 0
|
|
180
|
+
if not config_only:
|
|
181
|
+
triple_counts, skipped = _export_triples(
|
|
182
|
+
tar, api, flow_id, collections, triples_limit,
|
|
183
|
+
)
|
|
184
|
+
doc_count = _export_library(tar, api)
|
|
185
|
+
|
|
186
|
+
manifest = {
|
|
187
|
+
"format": MANIFEST_FORMAT,
|
|
188
|
+
"format_version": MANIFEST_FORMAT_VERSION,
|
|
189
|
+
"workspace": workspace,
|
|
190
|
+
"config_version": version,
|
|
191
|
+
"exported_at": time.strftime(
|
|
192
|
+
"%Y-%m-%dT%H:%M:%SZ", time.gmtime(),
|
|
193
|
+
),
|
|
194
|
+
"contents": {"config": True, "knowledge": not config_only},
|
|
195
|
+
}
|
|
196
|
+
if not config_only:
|
|
197
|
+
manifest["knowledge"] = {
|
|
198
|
+
"collections": collections,
|
|
199
|
+
"documents": doc_count,
|
|
200
|
+
"triples": triple_counts,
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
_add_bytes(
|
|
204
|
+
tar, "manifest.json",
|
|
205
|
+
json.dumps(manifest, indent=2).encode("utf-8"),
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
summary = f"Exported {config_count} config item(s)"
|
|
209
|
+
if not config_only:
|
|
210
|
+
summary += (
|
|
211
|
+
f", {sum(triple_counts.values())} triple(s) across "
|
|
212
|
+
f"{len(triple_counts)} collection(s), {doc_count} document(s)"
|
|
213
|
+
)
|
|
214
|
+
if skipped:
|
|
215
|
+
summary += f" ({skipped} triple(s) not representable, skipped)"
|
|
216
|
+
print(f"{summary} from workspace '{workspace}' to {output}", flush=True)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def main():
|
|
220
|
+
|
|
221
|
+
parser = argparse.ArgumentParser(
|
|
222
|
+
prog='tg-export-workspace',
|
|
223
|
+
description=__doc__,
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
parser.add_argument(
|
|
227
|
+
'-u', '--api-url',
|
|
228
|
+
default=default_url,
|
|
229
|
+
help=f'API URL (default: {default_url})',
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
parser.add_argument(
|
|
233
|
+
'-t', '--token',
|
|
234
|
+
default=default_token,
|
|
235
|
+
help='API token (default: TRUSTGRAPH_TOKEN environment variable)',
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
parser.add_argument(
|
|
239
|
+
'-w', '--workspace',
|
|
240
|
+
default=default_workspace,
|
|
241
|
+
help=f'Workspace to export (default: {default_workspace})',
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
parser.add_argument(
|
|
245
|
+
'-c', '--collection',
|
|
246
|
+
action='append',
|
|
247
|
+
default=[],
|
|
248
|
+
help='Additionally export this collection even if it is not '
|
|
249
|
+
'registered in collection management (repeatable)',
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
parser.add_argument(
|
|
253
|
+
'-o', '--output',
|
|
254
|
+
required=True,
|
|
255
|
+
help='Output bundle path, e.g. workspace-default.tgx',
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
parser.add_argument(
|
|
259
|
+
'-f', '--flow-id',
|
|
260
|
+
default="default",
|
|
261
|
+
help='Flow to query triples through (default: default)',
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
parser.add_argument(
|
|
265
|
+
'--config-only',
|
|
266
|
+
action='store_true',
|
|
267
|
+
help='Export only the configuration, skipping knowledge '
|
|
268
|
+
'(triples and library documents)',
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
parser.add_argument(
|
|
272
|
+
'--triples-limit',
|
|
273
|
+
type=int,
|
|
274
|
+
default=DEFAULT_TRIPLES_LIMIT,
|
|
275
|
+
help='Maximum triples to export per collection '
|
|
276
|
+
f'(default: {DEFAULT_TRIPLES_LIMIT})',
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
args = parser.parse_args()
|
|
280
|
+
|
|
281
|
+
try:
|
|
282
|
+
|
|
283
|
+
export_workspace(
|
|
284
|
+
url=args.api_url,
|
|
285
|
+
workspace=args.workspace,
|
|
286
|
+
output=args.output,
|
|
287
|
+
token=args.token,
|
|
288
|
+
config_only=args.config_only,
|
|
289
|
+
flow_id=args.flow_id,
|
|
290
|
+
triples_limit=args.triples_limit,
|
|
291
|
+
extra_collections=args.collection,
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
except Exception as e:
|
|
295
|
+
|
|
296
|
+
print("Exception:", e, flush=True)
|
|
297
|
+
sys.exit(1)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
if __name__ == "__main__":
|
|
301
|
+
main()
|