dump-things-pyclient 0.1.4__py3-none-any.whl → 0.2.0__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/dtc.py +60 -0
- dump_things_pyclient/commands/dtc_plugins/__init__.py +24 -0
- dump_things_pyclient/commands/dtc_plugins/auto_curate.py +248 -0
- dump_things_pyclient/commands/dtc_plugins/clean_incoming.py +93 -0
- dump_things_pyclient/commands/dtc_plugins/get_records.py +262 -0
- dump_things_pyclient/commands/dtc_plugins/list_incoming.py +86 -0
- dump_things_pyclient/commands/dtc_plugins/post_records.py +116 -0
- dump_things_pyclient/commands/dtc_plugins/read_pages.py +141 -0
- {dump_things_pyclient-0.1.4.dist-info → dump_things_pyclient-0.2.0.dist-info}/METADATA +3 -2
- dump_things_pyclient-0.2.0.dist-info/RECORD +17 -0
- {dump_things_pyclient-0.1.4.dist-info → dump_things_pyclient-0.2.0.dist-info}/WHEEL +1 -1
- dump_things_pyclient-0.2.0.dist-info/entry_points.txt +3 -0
- dump_things_pyclient/commands/auto_curate.py +0 -214
- dump_things_pyclient/commands/get_records.py +0 -171
- dump_things_pyclient/commands/post_records.py +0 -59
- dump_things_pyclient/commands/read_pages.py +0 -87
- dump_things_pyclient-0.1.4.dist-info/RECORD +0 -13
- dump_things_pyclient-0.1.4.dist-info/entry_points.txt +0 -6
- {dump_things_pyclient-0.1.4.dist-info → dump_things_pyclient-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import argparse
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import sys
|
|
7
|
-
from functools import partial
|
|
8
|
-
|
|
9
|
-
from ..communicate import (
|
|
10
|
-
HTTPError,
|
|
11
|
-
collection_read_records,
|
|
12
|
-
collection_read_records_of_class,
|
|
13
|
-
collection_read_record_with_pid,
|
|
14
|
-
curated_read_records,
|
|
15
|
-
curated_read_records_of_class,
|
|
16
|
-
curated_read_record_with_pid,
|
|
17
|
-
incoming_read_labels,
|
|
18
|
-
incoming_read_records,
|
|
19
|
-
incoming_read_records_of_class,
|
|
20
|
-
incoming_read_record_with_pid,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
token_name = 'DUMPTHINGS_TOKEN'
|
|
25
|
-
|
|
26
|
-
description = f"""Get records from a collection on a dump-things-service
|
|
27
|
-
|
|
28
|
-
This command lists records that are stored in a dump-things-service. By
|
|
29
|
-
default all records that are readable with the given token, or the default
|
|
30
|
-
token, will be displayed. The output format is JSONL (JSON lines), where
|
|
31
|
-
every line contains a record or a record with paging information. If `ttl`
|
|
32
|
-
is chosen as format of the output records, the record content will be a string
|
|
33
|
-
that contains a TTL-documents.
|
|
34
|
-
|
|
35
|
-
The command supports to read from the curated area only, to read from incoming
|
|
36
|
-
areas, or to read records with a given PID.
|
|
37
|
-
|
|
38
|
-
Pagination information is returned for paginated results, when requested with
|
|
39
|
-
`-P/--pagination`. All results are paginated except "get a record with a given PID"
|
|
40
|
-
and "get the list of incoming zone labels".
|
|
41
|
-
|
|
42
|
-
If the environment variable "{token_name}" is set, its content will be used
|
|
43
|
-
as token to authenticate against the dump-things-service.
|
|
44
|
-
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def _main():
|
|
49
|
-
argument_parser = argparse.ArgumentParser(
|
|
50
|
-
description=description,
|
|
51
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
52
|
-
)
|
|
53
|
-
argument_parser.add_argument('service_url')
|
|
54
|
-
argument_parser.add_argument('collection')
|
|
55
|
-
argument_parser.add_argument('-C', '--class', dest='class_name', help='only read records of this class, ignored if "--pid" is provided')
|
|
56
|
-
argument_parser.add_argument('-f', '--format', help='format of the output records ("json" or "ttl")')
|
|
57
|
-
argument_parser.add_argument('-p', '--pid', help='the pid of the record that should be read')
|
|
58
|
-
argument_parser.add_argument('-i', '--incoming', metavar='LABEL', help='read from incoming area with the given label in the collection, if LABEL is "-", return the labels')
|
|
59
|
-
argument_parser.add_argument('-c', '--curated', action='store_true', help='read from the curated area of the collection')
|
|
60
|
-
argument_parser.add_argument('-m', '--matching', help='return only records that have a matching value (use % as wildcard). Ignored if "--pid" is provided. (NOTE: not all endpoints and backends support matching.)')
|
|
61
|
-
argument_parser.add_argument('-s', '--page-size', type=int, help='set the page size (1 - 100) (default: 100), ignored if "--pid" is provided')
|
|
62
|
-
argument_parser.add_argument('-F', '--first-page', type=int, help='the first page to return (default: 1), ignored if "--pid" is provided')
|
|
63
|
-
argument_parser.add_argument('-l', '--last-page', type=int, default=None, help='the last page to return (default: None (return all pages), ignored if "--pid" is provided')
|
|
64
|
-
argument_parser.add_argument('--stats', action='store_true', help='show the number of records and pages and exit, ignored if "--pid" is provided')
|
|
65
|
-
argument_parser.add_argument('-P', '--pagination', action='store_true', help='show pagination information (each record from an paginated endpoint is returned as [<record>, <current page number>, <total number of pages>, <page size>, <total number of items>]')
|
|
66
|
-
|
|
67
|
-
arguments = argument_parser.parse_args()
|
|
68
|
-
|
|
69
|
-
token = os.environ.get(token_name)
|
|
70
|
-
if token is None:
|
|
71
|
-
print(f'WARNING: {token_name} not set', file=sys.stderr, flush=True)
|
|
72
|
-
|
|
73
|
-
if arguments.incoming and arguments.curated:
|
|
74
|
-
print(
|
|
75
|
-
'ERROR: -i/--incoming and -c/--curated are mutually exclusive',
|
|
76
|
-
file=sys.stderr,
|
|
77
|
-
flush=True)
|
|
78
|
-
return 1
|
|
79
|
-
|
|
80
|
-
kwargs = dict(
|
|
81
|
-
service_url=arguments.service_url,
|
|
82
|
-
collection=arguments.collection,
|
|
83
|
-
token=token,
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
if arguments.incoming == '-':
|
|
87
|
-
result = incoming_read_labels(**kwargs)
|
|
88
|
-
print('\n'.join(
|
|
89
|
-
map(
|
|
90
|
-
partial(json.dumps, ensure_ascii=False),
|
|
91
|
-
result)))
|
|
92
|
-
return 0
|
|
93
|
-
|
|
94
|
-
elif arguments.pid:
|
|
95
|
-
for argument_value, argument_name in (
|
|
96
|
-
(arguments.matching, '-m/--matching'),
|
|
97
|
-
(arguments.page_size, '-s/--page_size'),
|
|
98
|
-
(arguments.first_page, '-f/--first_page'),
|
|
99
|
-
(arguments.last_page, '-l/--last_page'),
|
|
100
|
-
(arguments.stats, '--stats'),
|
|
101
|
-
(arguments.class_name, '-c/--class'),
|
|
102
|
-
):
|
|
103
|
-
if argument_value:
|
|
104
|
-
print(
|
|
105
|
-
f'WARNING: {argument_name} ignored because "-p/--pid" is provided',
|
|
106
|
-
file=sys.stderr,
|
|
107
|
-
flush=True)
|
|
108
|
-
|
|
109
|
-
kwargs['pid'] = arguments.pid
|
|
110
|
-
if arguments.curated:
|
|
111
|
-
result = curated_read_record_with_pid(**kwargs)
|
|
112
|
-
elif arguments.incoming:
|
|
113
|
-
kwargs['label'] = arguments.incoming
|
|
114
|
-
result = incoming_read_record_with_pid(**kwargs)
|
|
115
|
-
else:
|
|
116
|
-
kwargs['format'] = arguments.format
|
|
117
|
-
result = collection_read_record_with_pid(**kwargs)
|
|
118
|
-
print(json.dumps(result, ensure_ascii=False))
|
|
119
|
-
return 0
|
|
120
|
-
|
|
121
|
-
elif arguments.class_name:
|
|
122
|
-
kwargs.update(dict(
|
|
123
|
-
class_name=arguments.class_name,
|
|
124
|
-
matching=arguments.matching,
|
|
125
|
-
page=arguments.first_page or 1,
|
|
126
|
-
size=arguments.page_size or 100,
|
|
127
|
-
last_page=arguments.last_page,
|
|
128
|
-
))
|
|
129
|
-
if arguments.curated:
|
|
130
|
-
result = curated_read_records_of_class(**kwargs)
|
|
131
|
-
elif arguments.incoming:
|
|
132
|
-
kwargs['label'] = arguments.incoming
|
|
133
|
-
result = incoming_read_records_of_class(**kwargs)
|
|
134
|
-
else:
|
|
135
|
-
kwargs['format'] = arguments.format
|
|
136
|
-
result = collection_read_records_of_class(**kwargs)
|
|
137
|
-
else:
|
|
138
|
-
kwargs.update(dict(
|
|
139
|
-
matching=arguments.matching,
|
|
140
|
-
page=arguments.first_page or 1,
|
|
141
|
-
size=arguments.page_size or 100,
|
|
142
|
-
last_page=arguments.last_page,
|
|
143
|
-
))
|
|
144
|
-
if arguments.curated:
|
|
145
|
-
result = curated_read_records(**kwargs)
|
|
146
|
-
elif arguments.incoming:
|
|
147
|
-
kwargs['label'] = arguments.incoming
|
|
148
|
-
result = incoming_read_records(**kwargs)
|
|
149
|
-
else:
|
|
150
|
-
kwargs['format'] = arguments.format
|
|
151
|
-
result = collection_read_records(**kwargs)
|
|
152
|
-
|
|
153
|
-
if arguments.pagination:
|
|
154
|
-
for record in result:
|
|
155
|
-
print(json.dumps(record, ensure_ascii=False))
|
|
156
|
-
else:
|
|
157
|
-
for record in result:
|
|
158
|
-
print(json.dumps(record[0], ensure_ascii=False))
|
|
159
|
-
return 0
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
def main():
|
|
163
|
-
try:
|
|
164
|
-
return _main()
|
|
165
|
-
except HTTPError as e:
|
|
166
|
-
print(f'ERROR: {e}: {e.response.text}', file=sys.stderr, flush=True)
|
|
167
|
-
return 1
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if __name__ == '__main__':
|
|
171
|
-
sys.exit(main())
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import argparse
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import sys
|
|
7
|
-
|
|
8
|
-
from ..communicate import (
|
|
9
|
-
collection_write_record,
|
|
10
|
-
curated_write_record,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def main():
|
|
15
|
-
argument_parser = argparse.ArgumentParser()
|
|
16
|
-
argument_parser.add_argument('base_url')
|
|
17
|
-
argument_parser.add_argument('collection')
|
|
18
|
-
argument_parser.add_argument('cls', metavar='class')
|
|
19
|
-
argument_parser.add_argument('--curated', action='store_true', help='bypass inbox, requires curator token')
|
|
20
|
-
|
|
21
|
-
arguments = argument_parser.parse_args()
|
|
22
|
-
|
|
23
|
-
token = os.environ.get('DUMPTHINGS_TOKEN')
|
|
24
|
-
if token is None:
|
|
25
|
-
print(
|
|
26
|
-
'WARNING: environment variable DUMPTHINGS_TOKEN not set',
|
|
27
|
-
file=sys.stderr,
|
|
28
|
-
flush=True,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
if arguments.curated:
|
|
32
|
-
write_record = curated_write_record
|
|
33
|
-
else:
|
|
34
|
-
write_record = collection_write_record
|
|
35
|
-
|
|
36
|
-
posted = False
|
|
37
|
-
for line in sys.stdin:
|
|
38
|
-
record = json.loads(line)
|
|
39
|
-
try:
|
|
40
|
-
write_record(
|
|
41
|
-
service_url=arguments.base_url,
|
|
42
|
-
collection=arguments.collection,
|
|
43
|
-
class_name=arguments.cls,
|
|
44
|
-
record=record,
|
|
45
|
-
token=token,
|
|
46
|
-
)
|
|
47
|
-
except Exception as e:
|
|
48
|
-
print(f'Error: {e}', file=sys.stderr, flush=True)
|
|
49
|
-
else:
|
|
50
|
-
posted = True
|
|
51
|
-
print('.', end='', flush=True)
|
|
52
|
-
|
|
53
|
-
if posted:
|
|
54
|
-
# final newline
|
|
55
|
-
print('')
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if __name__ == '__main__':
|
|
59
|
-
sys.exit(main())
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import argparse
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import sys
|
|
7
|
-
|
|
8
|
-
from ..communicate import (
|
|
9
|
-
HTTPError,
|
|
10
|
-
get_paginated,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
token_name = 'DUMPTHINGS_TOKEN'
|
|
15
|
-
|
|
16
|
-
description = f"""Read paginated endpoint
|
|
17
|
-
|
|
18
|
-
This command lists all records that are available via paginated endpoints from
|
|
19
|
-
a dump-things-service, e.g., from:
|
|
20
|
-
|
|
21
|
-
https://<service-location>/<collection>/records/p/
|
|
22
|
-
|
|
23
|
-
If the environment variable "{token_name}" is set, its content will be used
|
|
24
|
-
as token to authenticate against the dump-things-service.
|
|
25
|
-
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def _main():
|
|
30
|
-
argument_parser = argparse.ArgumentParser(
|
|
31
|
-
description=description,
|
|
32
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
33
|
-
)
|
|
34
|
-
argument_parser.add_argument('url', help='url of the paginated endpoint of the dump-things-service')
|
|
35
|
-
argument_parser.add_argument('-s', '--page-size', type=int, default=100, help='set the page size (1 - 100) (default: 100)')
|
|
36
|
-
argument_parser.add_argument('-F', '--first-page', type=int, default=1, help='the first page to return (default: 1)')
|
|
37
|
-
argument_parser.add_argument('-l', '--last-page', type=int, default=None, help='the last page to return (default: None (return all pages)')
|
|
38
|
-
argument_parser.add_argument('--stats', action='store_true', help='show information about the number of records and pages and exit, the format is is returned as [<total number of pages>, <page size>, <total number of items>]')
|
|
39
|
-
argument_parser.add_argument('-f', '--format', help='format of the output records ("json" or "ttl"). (NOTE: not all endpoints support the format parameter.)')
|
|
40
|
-
argument_parser.add_argument('-m', '--matching', help='return only records that have a matching value (use % as wildcard). (NOTE: not all endpoints and backends support matching.)')
|
|
41
|
-
argument_parser.add_argument('-P', '--pagination', action='store_true', help='show pagination information (each record from an paginated endpoint is returned as [<record>, <current page number>, <total number of pages>, <page size>, <total number of items>]')
|
|
42
|
-
|
|
43
|
-
arguments = argument_parser.parse_args()
|
|
44
|
-
|
|
45
|
-
token = os.environ.get(token_name)
|
|
46
|
-
if token is None:
|
|
47
|
-
print(f'WARNING: {token_name} not set', file=sys.stderr, flush=True)
|
|
48
|
-
|
|
49
|
-
result = get_paginated(
|
|
50
|
-
url=arguments.url,
|
|
51
|
-
token=token,
|
|
52
|
-
first_page=arguments.first_page,
|
|
53
|
-
page_size=arguments.page_size,
|
|
54
|
-
last_page=arguments.last_page,
|
|
55
|
-
parameters={
|
|
56
|
-
'format': arguments.format,
|
|
57
|
-
**({'matching': arguments.matching}
|
|
58
|
-
if arguments.matching is not None
|
|
59
|
-
else {}
|
|
60
|
-
),
|
|
61
|
-
}
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
if arguments.stats:
|
|
65
|
-
record = next(result)
|
|
66
|
-
print(json.dumps(record[2:], ensure_ascii=False))
|
|
67
|
-
return 0
|
|
68
|
-
|
|
69
|
-
if arguments.pagination:
|
|
70
|
-
for record in result:
|
|
71
|
-
print(json.dumps(record, ensure_ascii=False))
|
|
72
|
-
else:
|
|
73
|
-
for record in result:
|
|
74
|
-
print(json.dumps(record[0], ensure_ascii=False))
|
|
75
|
-
return 0
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def main():
|
|
79
|
-
try:
|
|
80
|
-
return _main()
|
|
81
|
-
except HTTPError as e:
|
|
82
|
-
print(f'ERROR: {e}: {e.response.text}', file=sys.stderr, flush=True)
|
|
83
|
-
return 1
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if __name__ == '__main__':
|
|
87
|
-
sys.exit(main())
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
dump_things_pyclient/__init__.py,sha256=cn-U3TRIalN6aYHp1cMBRkQm1x98XBwquLFbgFEIf_Q,113
|
|
2
|
-
dump_things_pyclient/communicate.py,sha256=CTkgEigu16BmLrlJScMQKhHLI_W4SywDb4HCwAICWzA,30523
|
|
3
|
-
dump_things_pyclient/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
dump_things_pyclient/commands/auto_curate.py,sha256=T2aUQ1NWWr9OMUw0vQveMen4d18y6-gY4xcyajX9ACY,7716
|
|
5
|
-
dump_things_pyclient/commands/get_records.py,sha256=ErNC75ukrMTlOmKz6y1yF9F7HqJ-KdzksH4qMDnXPBI,6969
|
|
6
|
-
dump_things_pyclient/commands/json2ttl.py,sha256=8BkvdjLWZ_H0L6fTmuR2M2MglKiMUiuNUcuWr_w6_dQ,2133
|
|
7
|
-
dump_things_pyclient/commands/post_records.py,sha256=3Q0aPMVtXG6azRzzVa0pBzZYJaAi3VqkLHjGwK0X6To,1503
|
|
8
|
-
dump_things_pyclient/commands/read_pages.py,sha256=YuJUJeM_YwGR6D2-YJg1HYY2uD6j27QEItFXs5TzvYQ,3214
|
|
9
|
-
dump_things_pyclient-0.1.4.dist-info/METADATA,sha256=PWlmmLd1zo0YKdiu7ZNjOzEVcCuaq8Q6GTT0CGRGSl8,942
|
|
10
|
-
dump_things_pyclient-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
-
dump_things_pyclient-0.1.4.dist-info/entry_points.txt,sha256=-LKTUNP6RJWBrzjXY8xdMhQsTS1zgvRsLJpsO7FipmQ,317
|
|
12
|
-
dump_things_pyclient-0.1.4.dist-info/top_level.txt,sha256=Asvruw-SyLoYhWis1CFOx89RGxpjXoTZVGoq4JSGt88,21
|
|
13
|
-
dump_things_pyclient-0.1.4.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
[console_scripts]
|
|
2
|
-
auto-curate = dump_things_pyclient.commands.auto_curate:main
|
|
3
|
-
get-records = dump_things_pyclient.commands.get_records:main
|
|
4
|
-
json2ttl = dump_things_pyclient.commands.json2ttl:main
|
|
5
|
-
post-records = dump_things_pyclient.commands.post_records:main
|
|
6
|
-
read-pages = dump_things_pyclient.commands.read_pages:main
|
|
File without changes
|