dump-things-pyclient 0.1.0__py3-none-any.whl → 0.1.1__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.
- dump_things_pyclient/commands/json2ttl.py +64 -0
- dump_things_pyclient/communicate.py +37 -7
- {dump_things_pyclient-0.1.0.dist-info → dump_things_pyclient-0.1.1.dist-info}/METADATA +3 -1
- dump_things_pyclient-0.1.1.dist-info/RECORD +12 -0
- {dump_things_pyclient-0.1.0.dist-info → dump_things_pyclient-0.1.1.dist-info}/entry_points.txt +1 -0
- dump_things_pyclient-0.1.0.dist-info/RECORD +0 -11
- {dump_things_pyclient-0.1.0.dist-info → dump_things_pyclient-0.1.1.dist-info}/WHEEL +0 -0
- {dump_things_pyclient-0.1.0.dist-info → dump_things_pyclient-0.1.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from dump_things_service.converter import (
|
|
9
|
+
Format,
|
|
10
|
+
FormatConverter,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
description = f"""Read JSON records from stdin and convert them to TTL
|
|
15
|
+
|
|
16
|
+
This command reads one record per line, either JSON format or a JSON-string
|
|
17
|
+
with a TTL-document from stdin, converts them to TTL or JSON and prints them
|
|
18
|
+
to stdout.
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
argument_parser = argparse.ArgumentParser(
|
|
25
|
+
description=description,
|
|
26
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
27
|
+
)
|
|
28
|
+
argument_parser.add_argument('schema', help='URL of the schema that should be used')
|
|
29
|
+
|
|
30
|
+
arguments = argument_parser.parse_args()
|
|
31
|
+
|
|
32
|
+
print(f'Creating converter for schema {arguments.schema} ...', file=sys.stderr, end='', flush=True)
|
|
33
|
+
converter = FormatConverter(
|
|
34
|
+
arguments.schema,
|
|
35
|
+
input_format=Format.json,
|
|
36
|
+
output_format=Format.ttl,
|
|
37
|
+
)
|
|
38
|
+
print(' done', file=sys.stderr, flush=True)
|
|
39
|
+
|
|
40
|
+
error = False
|
|
41
|
+
for line in sys.stdin:
|
|
42
|
+
json_object = json.loads(line)
|
|
43
|
+
|
|
44
|
+
object_class = json_object.get('schema_type')
|
|
45
|
+
if object_class is None:
|
|
46
|
+
error = True
|
|
47
|
+
print(f'ERROR: No schema_type in {json_object}', file=sys.stderr, flush=True)
|
|
48
|
+
continue
|
|
49
|
+
|
|
50
|
+
class_name = re.search('([_A-Za-z0-9]*$)', object_class).group(0)
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
ttl = converter.convert(json_object, class_name)
|
|
54
|
+
except ValueError as ve:
|
|
55
|
+
print(f'ERROR: conversion failed for {json_object}: {ve}', file=sys.stderr, flush=True)
|
|
56
|
+
continue
|
|
57
|
+
|
|
58
|
+
print(json.dumps(ttl))
|
|
59
|
+
|
|
60
|
+
return 1 if error else 0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == '__main__':
|
|
64
|
+
sys.exit(main())
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
+
import re
|
|
4
5
|
from itertools import count
|
|
5
6
|
from typing import (
|
|
6
7
|
Callable,
|
|
@@ -99,6 +100,29 @@ def get(url: str,
|
|
|
99
100
|
return _get_from_url(url, token, parameters)
|
|
100
101
|
|
|
101
102
|
|
|
103
|
+
def collection_get_classes(service_url: str,
|
|
104
|
+
collection: str,
|
|
105
|
+
) -> Generator[str, None, None]:
|
|
106
|
+
"""Read classes that are supported by the collection
|
|
107
|
+
|
|
108
|
+
Get the name of the classes that are known in the collection. If the
|
|
109
|
+
collection does not exist on the server, no class names are returned.
|
|
110
|
+
|
|
111
|
+
:param service_url: the base URL of the service, i.e., the URL up to
|
|
112
|
+
`/<collection>/...` or `/server`
|
|
113
|
+
:param collection: the name of the collection
|
|
114
|
+
|
|
115
|
+
:return: a generator yielding names of the supported classes
|
|
116
|
+
"""
|
|
117
|
+
service_url = f'{service_url[:-1]}' if service_url.endswith('/') else service_url
|
|
118
|
+
matcher = re.compile(f'/{collection}/record/([A-Z][_a-zA-Z0-9]*)$')
|
|
119
|
+
open_api_spec = _get_from_url(service_url + '/openapi.json', None)
|
|
120
|
+
for path in open_api_spec['paths']:
|
|
121
|
+
match = matcher.match(path)
|
|
122
|
+
if match:
|
|
123
|
+
yield match.group(1)
|
|
124
|
+
|
|
125
|
+
|
|
102
126
|
def collection_read_record_with_pid(service_url: str,
|
|
103
127
|
collection: str,
|
|
104
128
|
pid: str,
|
|
@@ -236,11 +260,12 @@ def collection_write_record(
|
|
|
236
260
|
than one record due to inlined-relations extraction. The individual
|
|
237
261
|
records might have annotations added
|
|
238
262
|
"""
|
|
263
|
+
_check_format_value(format)
|
|
239
264
|
return _post_to_url(
|
|
240
265
|
url=_build_url(service_url, collection, f'record/{class_name}'),
|
|
241
266
|
token=token,
|
|
242
|
-
|
|
243
|
-
|
|
267
|
+
params={'format': format},
|
|
268
|
+
**(dict(json=record) if format == 'json' else dict(data=record)))
|
|
244
269
|
|
|
245
270
|
|
|
246
271
|
def collection_validate_record(
|
|
@@ -269,12 +294,12 @@ def collection_validate_record(
|
|
|
269
294
|
|
|
270
295
|
:return: True
|
|
271
296
|
"""
|
|
272
|
-
|
|
297
|
+
_check_format_value(format)
|
|
273
298
|
return _post_to_url(
|
|
274
299
|
url=_build_url(service_url, collection, f'validate/{class_name}'),
|
|
275
300
|
token=token,
|
|
276
|
-
|
|
277
|
-
|
|
301
|
+
params={'format': format},
|
|
302
|
+
**(dict(json=record) if format == 'json' else dict(data=record)))
|
|
278
303
|
|
|
279
304
|
|
|
280
305
|
def collection_delete_record(
|
|
@@ -660,10 +685,10 @@ def _get_from_url(url: str,
|
|
|
660
685
|
|
|
661
686
|
def _post_to_url(url: str,
|
|
662
687
|
token: str | None,
|
|
663
|
-
json: JSON,
|
|
664
688
|
params: dict[str, str] | None = None,
|
|
689
|
+
**kwargs,
|
|
665
690
|
) -> JSON:
|
|
666
|
-
return _do_request(requests.post, url, token, params,
|
|
691
|
+
return _do_request(requests.post, url, token, params, **kwargs)
|
|
667
692
|
|
|
668
693
|
|
|
669
694
|
def _delete_url(url: str,
|
|
@@ -717,3 +742,8 @@ def _get_page(url_base: str,
|
|
|
717
742
|
parameters['page'] = first_page
|
|
718
743
|
parameters['size'] = page_size
|
|
719
744
|
return _get_from_url(url_base, token, parameters)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def _check_format_value(format: str) -> None:
|
|
748
|
+
if format not in ('json', 'ttl'):
|
|
749
|
+
raise ValueError('Format must be either "json" or "ttl"')
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dump-things-pyclient
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: A client library and some CLI command for dump-things-services
|
|
5
|
+
Author-email: Christian Mönch <christian.moench@web.de>
|
|
5
6
|
Requires-Python: >=3.11
|
|
6
7
|
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: dump-things-service>=5.3.0
|
|
7
9
|
Requires-Dist: requests>=2.32.5
|
|
8
10
|
|
|
9
11
|
# Dump Things Python Client
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
dump_things_pyclient/__init__.py,sha256=cn-U3TRIalN6aYHp1cMBRkQm1x98XBwquLFbgFEIf_Q,113
|
|
2
|
+
dump_things_pyclient/communicate.py,sha256=9UtH-pvcOaUWc5HLiDuAxN2qfm-IuKzBO4DvqSDIbeQ,30493
|
|
3
|
+
dump_things_pyclient/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
dump_things_pyclient/commands/auto_curate.py,sha256=nq3aM5Kyj4f_CPELxsS5PVBCPwc0RvrCbPUCpEOYZu8,6797
|
|
5
|
+
dump_things_pyclient/commands/get_records.py,sha256=ErNC75ukrMTlOmKz6y1yF9F7HqJ-KdzksH4qMDnXPBI,6969
|
|
6
|
+
dump_things_pyclient/commands/json2ttl.py,sha256=LDt-F0p3MpXjx9SRiRMyGJo1BrQnnt7U_BJfOLJz8xo,1716
|
|
7
|
+
dump_things_pyclient/commands/read_pages.py,sha256=Td94LrXFucGhxfmew5gHieVGVVGfkNKeI-r5c3S15FU,3193
|
|
8
|
+
dump_things_pyclient-0.1.1.dist-info/METADATA,sha256=fmuBP-3YgebuPJdbTZ893bEtWgFycPDSsH2BECblbIY,837
|
|
9
|
+
dump_things_pyclient-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
dump_things_pyclient-0.1.1.dist-info/entry_points.txt,sha256=8LekJ3KnljruMHXAvjQa2Or7A26_DO-aoxA78Kgxij8,254
|
|
11
|
+
dump_things_pyclient-0.1.1.dist-info/top_level.txt,sha256=Asvruw-SyLoYhWis1CFOx89RGxpjXoTZVGoq4JSGt88,21
|
|
12
|
+
dump_things_pyclient-0.1.1.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
dump_things_pyclient/__init__.py,sha256=cn-U3TRIalN6aYHp1cMBRkQm1x98XBwquLFbgFEIf_Q,113
|
|
2
|
-
dump_things_pyclient/communicate.py,sha256=xIi_NqlfybeBLt4-fW0gf8yMQi2uV8IerrsMNFAYCNI,29296
|
|
3
|
-
dump_things_pyclient/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
dump_things_pyclient/commands/auto_curate.py,sha256=nq3aM5Kyj4f_CPELxsS5PVBCPwc0RvrCbPUCpEOYZu8,6797
|
|
5
|
-
dump_things_pyclient/commands/get_records.py,sha256=ErNC75ukrMTlOmKz6y1yF9F7HqJ-KdzksH4qMDnXPBI,6969
|
|
6
|
-
dump_things_pyclient/commands/read_pages.py,sha256=Td94LrXFucGhxfmew5gHieVGVVGfkNKeI-r5c3S15FU,3193
|
|
7
|
-
dump_things_pyclient-0.1.0.dist-info/METADATA,sha256=vytaO9PP0dOIvhAdLp4Volt_YREVssYtg6EJh-fIM0g,738
|
|
8
|
-
dump_things_pyclient-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
dump_things_pyclient-0.1.0.dist-info/entry_points.txt,sha256=VTkyzhm1ohkr5DNu4Zncismw3LWWmE9din5ZVlwr0HM,199
|
|
10
|
-
dump_things_pyclient-0.1.0.dist-info/top_level.txt,sha256=Asvruw-SyLoYhWis1CFOx89RGxpjXoTZVGoq4JSGt88,21
|
|
11
|
-
dump_things_pyclient-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|