dsp-tools 17.0.0.post29__py3-none-any.whl → 18.0.0.post3__py3-none-any.whl
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.
Potentially problematic release.
This version of dsp-tools might be problematic. Click here for more details.
- dsp_tools/cli/args.py +13 -0
- dsp_tools/cli/call_action.py +34 -330
- dsp_tools/cli/call_action_files_only.py +74 -0
- dsp_tools/cli/call_action_with_network.py +202 -0
- dsp_tools/cli/create_parsers.py +53 -14
- dsp_tools/cli/utils.py +87 -0
- dsp_tools/clients/list_client.py +49 -0
- dsp_tools/clients/list_client_live.py +166 -0
- dsp_tools/clients/{ontology_client.py → ontology_clients.py} +17 -2
- dsp_tools/clients/{ontology_client_live.py → ontology_create_client_live.py} +21 -40
- dsp_tools/clients/ontology_get_client_live.py +66 -0
- dsp_tools/clients/project_client.py +10 -0
- dsp_tools/clients/project_client_live.py +36 -0
- dsp_tools/commands/create/create_on_server/cardinalities.py +14 -8
- dsp_tools/commands/create/create_on_server/lists.py +163 -0
- dsp_tools/commands/create/lists_only.py +45 -0
- dsp_tools/commands/create/models/input_problems.py +13 -0
- dsp_tools/commands/create/models/parsed_project.py +14 -1
- dsp_tools/commands/create/models/rdf_ontology.py +0 -7
- dsp_tools/commands/create/models/server_project_info.py +17 -3
- dsp_tools/commands/create/parsing/parse_lists.py +45 -0
- dsp_tools/commands/create/parsing/parse_project.py +23 -4
- dsp_tools/commands/ingest_xmlupload/create_resources/upload_xml.py +4 -4
- dsp_tools/commands/project/create/project_create_all.py +17 -13
- dsp_tools/commands/project/create/project_create_default_permissions.py +8 -6
- dsp_tools/commands/project/create/project_create_ontologies.py +30 -18
- dsp_tools/commands/project/legacy_models/listnode.py +0 -30
- dsp_tools/commands/validate_data/models/api_responses.py +2 -16
- dsp_tools/commands/validate_data/prepare_data/prepare_data.py +11 -10
- dsp_tools/commands/validate_data/shacl_cli_validator.py +3 -1
- dsp_tools/commands/validate_data/sparql/value_shacl.py +1 -1
- dsp_tools/commands/validate_data/validate_data.py +3 -3
- dsp_tools/commands/validate_data/validation/get_validation_report.py +1 -1
- dsp_tools/commands/validate_data/validation/validate_ontology.py +1 -1
- dsp_tools/commands/xmlupload/models/input_problems.py +1 -1
- dsp_tools/commands/xmlupload/upload_config.py +1 -1
- dsp_tools/commands/xmlupload/xmlupload.py +2 -2
- dsp_tools/error/custom_warnings.py +7 -0
- dsp_tools/error/exceptions.py +25 -2
- dsp_tools/resources/start-stack/docker-compose.yml +23 -23
- dsp_tools/utils/ansi_colors.py +2 -0
- dsp_tools/utils/fuseki_bloating.py +4 -2
- dsp_tools/utils/request_utils.py +31 -0
- dsp_tools/xmllib/models/res.py +2 -0
- {dsp_tools-17.0.0.post29.dist-info → dsp_tools-18.0.0.post3.dist-info}/METADATA +1 -1
- {dsp_tools-17.0.0.post29.dist-info → dsp_tools-18.0.0.post3.dist-info}/RECORD +48 -39
- {dsp_tools-17.0.0.post29.dist-info → dsp_tools-18.0.0.post3.dist-info}/WHEEL +1 -1
- dsp_tools/commands/project/create/project_create_lists.py +0 -200
- dsp_tools/commands/validate_data/api_clients.py +0 -124
- {dsp_tools-17.0.0.post29.dist-info → dsp_tools-18.0.0.post3.dist-info}/entry_points.txt +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import Any
|
|
3
|
-
from typing import cast
|
|
4
|
-
from urllib.parse import quote_plus
|
|
5
|
-
|
|
6
|
-
import requests
|
|
7
|
-
|
|
8
|
-
from dsp_tools.commands.validate_data.models.api_responses import OneList
|
|
9
|
-
from dsp_tools.commands.validate_data.models.api_responses import OneNode
|
|
10
|
-
from dsp_tools.error.exceptions import InternalError
|
|
11
|
-
from dsp_tools.utils.request_utils import RequestParameters
|
|
12
|
-
from dsp_tools.utils.request_utils import log_request
|
|
13
|
-
from dsp_tools.utils.request_utils import log_response
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@dataclass
|
|
17
|
-
class OntologyClient:
|
|
18
|
-
api_url: str
|
|
19
|
-
shortcode: str
|
|
20
|
-
|
|
21
|
-
def get_knora_api(self) -> str:
|
|
22
|
-
url = f"{self.api_url}/ontology/knora-api/v2#"
|
|
23
|
-
headers = {"Accept": "text/turtle"}
|
|
24
|
-
timeout = 60
|
|
25
|
-
log_request(RequestParameters("GET", url, timeout=timeout, headers=headers))
|
|
26
|
-
response = requests.get(url=url, headers=headers, timeout=timeout)
|
|
27
|
-
log_response(response, include_response_content=False)
|
|
28
|
-
if not response.ok:
|
|
29
|
-
raise InternalError(f"Failed Request: {response.status_code} {response.text}")
|
|
30
|
-
return response.text
|
|
31
|
-
|
|
32
|
-
def get_ontologies(self) -> tuple[list[str], list[str]]:
|
|
33
|
-
"""
|
|
34
|
-
Returns a list of project ontologies as a string in turtle format.
|
|
35
|
-
And a list of the ontology IRIs
|
|
36
|
-
|
|
37
|
-
Returns:
|
|
38
|
-
list of ontologies and IRIs
|
|
39
|
-
"""
|
|
40
|
-
ontology_iris = self._get_ontology_iris()
|
|
41
|
-
ontologies = [self._get_one_ontology(x) for x in ontology_iris]
|
|
42
|
-
return ontologies, ontology_iris
|
|
43
|
-
|
|
44
|
-
def _get_ontology_iris(self) -> list[str]:
|
|
45
|
-
url = f"{self.api_url}/admin/projects/shortcode/{self.shortcode}"
|
|
46
|
-
timeout = 10
|
|
47
|
-
log_request(RequestParameters("GET", url, timeout=timeout))
|
|
48
|
-
response = requests.get(url=url, timeout=timeout)
|
|
49
|
-
log_response(response)
|
|
50
|
-
if not response.ok:
|
|
51
|
-
raise InternalError(f"Failed Request: {response.status_code} {response.text}")
|
|
52
|
-
response_json = cast(dict[str, Any], response.json())
|
|
53
|
-
if not (ontos := response_json.get("project", {}).get("ontologies")):
|
|
54
|
-
raise InternalError(f"The response from the API does not contain any ontologies.\nResponse:{response.text}")
|
|
55
|
-
output = cast(list[str], ontos)
|
|
56
|
-
return output
|
|
57
|
-
|
|
58
|
-
def _get_one_ontology(self, ontology_iri: str) -> str:
|
|
59
|
-
url = ontology_iri
|
|
60
|
-
headers = {"Accept": "text/turtle"}
|
|
61
|
-
timeout = 30
|
|
62
|
-
log_request(RequestParameters("GET", url, timeout=timeout, headers=headers))
|
|
63
|
-
response = requests.get(url=url, headers=headers, timeout=timeout)
|
|
64
|
-
log_response(response, include_response_content=False)
|
|
65
|
-
if not response.ok:
|
|
66
|
-
raise InternalError(f"Failed Request: {response.status_code} {response.text}")
|
|
67
|
-
return response.text
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
@dataclass
|
|
71
|
-
class ListClient:
|
|
72
|
-
"""Client to request and reformat the lists of a project."""
|
|
73
|
-
|
|
74
|
-
api_url: str
|
|
75
|
-
shortcode: str
|
|
76
|
-
|
|
77
|
-
def get_lists(self) -> list[OneList]:
|
|
78
|
-
list_json = self._get_all_list_iris()
|
|
79
|
-
all_iris = self._extract_list_iris(list_json)
|
|
80
|
-
all_lists = [self._get_one_list(iri) for iri in all_iris]
|
|
81
|
-
return [self._reformat_one_list(lst) for lst in all_lists]
|
|
82
|
-
|
|
83
|
-
def _get_all_list_iris(self) -> dict[str, Any]:
|
|
84
|
-
url = f"{self.api_url}/admin/lists?projectShortcode={self.shortcode}"
|
|
85
|
-
timeout = 10
|
|
86
|
-
log_request(RequestParameters("GET", url, timeout))
|
|
87
|
-
response = requests.get(url=url, timeout=timeout)
|
|
88
|
-
log_response(response)
|
|
89
|
-
if not response.ok:
|
|
90
|
-
raise InternalError(f"Failed Request: {response.status_code} {response.text}")
|
|
91
|
-
json_response = cast(dict[str, Any], response.json())
|
|
92
|
-
return json_response
|
|
93
|
-
|
|
94
|
-
def _extract_list_iris(self, response_json: dict[str, Any]) -> list[str]:
|
|
95
|
-
return [x["id"] for x in response_json["lists"]]
|
|
96
|
-
|
|
97
|
-
def _get_one_list(self, list_iri: str) -> dict[str, Any]:
|
|
98
|
-
encoded_list_iri = quote_plus(list_iri)
|
|
99
|
-
url = f"{self.api_url}/admin/lists/{encoded_list_iri}"
|
|
100
|
-
timeout = 30
|
|
101
|
-
log_request(RequestParameters("GET", url, timeout))
|
|
102
|
-
response = requests.get(url=url, timeout=timeout)
|
|
103
|
-
log_response(response, include_response_content=False)
|
|
104
|
-
if not response.ok:
|
|
105
|
-
raise InternalError(f"Failed Request: {response.status_code} {response.text}")
|
|
106
|
-
response_json = cast(dict[str, Any], response.json())
|
|
107
|
-
return response_json
|
|
108
|
-
|
|
109
|
-
def _reformat_one_list(self, response_json: dict[str, Any]) -> OneList:
|
|
110
|
-
list_name = response_json["list"]["listinfo"]["name"]
|
|
111
|
-
list_id = response_json["list"]["listinfo"]["id"]
|
|
112
|
-
nodes = response_json["list"]["children"]
|
|
113
|
-
all_nodes = []
|
|
114
|
-
for child in nodes:
|
|
115
|
-
all_nodes.append(OneNode(child["name"], child["id"]))
|
|
116
|
-
if node_child := child.get("children"):
|
|
117
|
-
self._reformat_children(node_child, all_nodes)
|
|
118
|
-
return OneList(list_iri=list_id, list_name=list_name, nodes=all_nodes)
|
|
119
|
-
|
|
120
|
-
def _reformat_children(self, list_child: list[dict[str, Any]], current_nodes: list[OneNode]) -> None:
|
|
121
|
-
for child in list_child:
|
|
122
|
-
current_nodes.append(OneNode(child["name"], child["id"]))
|
|
123
|
-
if grand_child := child.get("children"):
|
|
124
|
-
self._reformat_children(grand_child, current_nodes)
|
|
File without changes
|