oarepo-runtime 1.4.4__py3-none-any.whl → 1.4.6__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.
- oarepo_runtime/cli/index.py +41 -20
- oarepo_runtime/cli/validate.py +26 -2
- oarepo_runtime/relations/errors.py +5 -0
- oarepo_runtime/relations/pid_relation.py +17 -10
- {oarepo_runtime-1.4.4.dist-info → oarepo_runtime-1.4.6.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.4.4.dist-info → oarepo_runtime-1.4.6.dist-info}/RECORD +10 -9
- {oarepo_runtime-1.4.4.dist-info → oarepo_runtime-1.4.6.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.4.4.dist-info → oarepo_runtime-1.4.6.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.4.4.dist-info → oarepo_runtime-1.4.6.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.4.4.dist-info → oarepo_runtime-1.4.6.dist-info}/top_level.txt +0 -0
oarepo_runtime/cli/index.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import itertools
|
1
2
|
import sys
|
2
3
|
|
3
4
|
import click
|
@@ -85,6 +86,18 @@ def record_or_service(model):
|
|
85
86
|
return record
|
86
87
|
|
87
88
|
|
89
|
+
def model_records_generator(model_class):
|
90
|
+
try:
|
91
|
+
for x in db.session.query(model_class.model_cls.id).filter(
|
92
|
+
model_class.model_cls.is_deleted.is_(False)
|
93
|
+
):
|
94
|
+
rec_id = x[0]
|
95
|
+
yield model_class.get_record(rec_id)
|
96
|
+
except Exception as e:
|
97
|
+
if "Column expression or FROM clause expected" not in str(e):
|
98
|
+
raise
|
99
|
+
|
100
|
+
|
88
101
|
@index.command()
|
89
102
|
@with_appcontext
|
90
103
|
@click.argument("model", required=False)
|
@@ -99,30 +112,38 @@ def reindex(model):
|
|
99
112
|
service = current_service_registry.get(service_id)
|
100
113
|
record_class = getattr(service.config, "record_cls", None)
|
101
114
|
|
102
|
-
|
103
|
-
continue
|
115
|
+
id_generators = []
|
104
116
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
117
|
+
if record_class and hasattr(service, "indexer"):
|
118
|
+
try:
|
119
|
+
id_generators.append(model_records_generator(record_class))
|
120
|
+
except Exception as e:
|
121
|
+
click.secho(
|
122
|
+
f"Could not get record ids for {service_id}, exception {e}",
|
123
|
+
file=sys.stderr,
|
124
|
+
)
|
125
|
+
|
126
|
+
draft_class = getattr(service.config, "draft_cls", None)
|
127
|
+
|
128
|
+
if draft_class and hasattr(service, "indexer"):
|
129
|
+
try:
|
130
|
+
id_generators.append(model_records_generator(draft_class))
|
131
|
+
except Exception as e:
|
132
|
+
click.secho(
|
133
|
+
f"Could not get draft record ids for {service_id}, exception {e}",
|
134
|
+
file=sys.stderr,
|
110
135
|
)
|
111
|
-
)
|
112
|
-
except Exception as e:
|
113
|
-
click.secho(
|
114
|
-
f"Could not get record ids for {service_id}, exception {e}",
|
115
|
-
file=sys.stderr,
|
116
|
-
)
|
117
|
-
continue
|
118
136
|
|
119
137
|
click.secho(f"Indexing {service_id}", file=sys.stderr)
|
120
|
-
|
121
|
-
for
|
122
|
-
record
|
123
|
-
|
124
|
-
|
138
|
+
count = 0
|
139
|
+
for gen in id_generators:
|
140
|
+
for record in gen:
|
141
|
+
service.indexer.index(record)
|
142
|
+
count += 1
|
143
|
+
if count:
|
144
|
+
service.indexer.refresh()
|
145
|
+
|
125
146
|
click.secho(
|
126
|
-
f"Indexing {service_id} finished, indexed {
|
147
|
+
f"Indexing {service_id} finished, indexed {count} records",
|
127
148
|
file=sys.stderr,
|
128
149
|
)
|
oarepo_runtime/cli/validate.py
CHANGED
@@ -22,6 +22,12 @@ class CheckOk(Exception):
|
|
22
22
|
pass
|
23
23
|
|
24
24
|
|
25
|
+
def dump_data(d):
|
26
|
+
io = StringIO()
|
27
|
+
yaml.safe_dump(d, io, allow_unicode=True)
|
28
|
+
return io.getvalue()
|
29
|
+
|
30
|
+
|
25
31
|
@oarepo.command(
|
26
32
|
help="Validate a record. Takes one or two parameters - service name as "
|
27
33
|
"the first one, file name or stdin with record data as the second"
|
@@ -51,12 +57,22 @@ def validate(service_name, record_file, verbose):
|
|
51
57
|
if file_content.startswith("{"):
|
52
58
|
data = json.loads(file_content)
|
53
59
|
else:
|
54
|
-
data = yaml.
|
60
|
+
data = list(yaml.safe_load_all(StringIO(file_content)))
|
55
61
|
|
56
62
|
if not isinstance(data, list):
|
57
63
|
data = [data]
|
58
64
|
for idx, d in enumerate(data):
|
59
|
-
|
65
|
+
try:
|
66
|
+
loaded = schema().load(d)
|
67
|
+
except Exception as e:
|
68
|
+
click.secho(
|
69
|
+
f"Marshmallow validation of record idx {idx + 1} failed",
|
70
|
+
fg="red",
|
71
|
+
)
|
72
|
+
click.secho(dump_data(d))
|
73
|
+
click.secho(e)
|
74
|
+
continue
|
75
|
+
|
60
76
|
click.secho(
|
61
77
|
f"Marshmallow validation of record idx {idx+1} has been successful",
|
62
78
|
fg="green",
|
@@ -74,6 +90,14 @@ def validate(service_name, record_file, verbose):
|
|
74
90
|
click.secho(
|
75
91
|
f"Pre-commit hook of record idx {idx+1} has been successful", fg="green"
|
76
92
|
)
|
93
|
+
except Exception as e:
|
94
|
+
click.secho(
|
95
|
+
f"Pre-commit validation of record idx {idx + 1} failed",
|
96
|
+
fg="red",
|
97
|
+
)
|
98
|
+
click.secho(dump_data(d))
|
99
|
+
click.secho(e)
|
100
|
+
continue
|
77
101
|
|
78
102
|
if verbose:
|
79
103
|
yaml.safe_dump(loaded, sys.stdout, allow_unicode=True)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from invenio_db import db
|
2
2
|
|
3
3
|
from .base import Relation, RelationResult
|
4
|
+
from .errors import InvalidRelationError
|
4
5
|
from .lookup import LookupResult
|
5
6
|
|
6
7
|
|
@@ -8,19 +9,23 @@ class PIDRelationResult(RelationResult):
|
|
8
9
|
def resolve(self, id_):
|
9
10
|
"""Resolve the value using the record class."""
|
10
11
|
# TODO: handle permissions here !!!!!!
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
pid_field_context = self.field.pid_field
|
13
|
+
if hasattr(pid_field_context, "pid_type"):
|
14
|
+
pid_type = pid_field_context.pid_type
|
15
|
+
else:
|
16
|
+
pid_field = pid_field_context.field
|
17
|
+
pid_type = (
|
18
|
+
pid_field._provider.pid_type
|
19
|
+
if pid_field._provider
|
20
|
+
else pid_field._pid_type
|
21
|
+
)
|
22
|
+
cache_key = (pid_type, id_)
|
18
23
|
if cache_key in self.cache:
|
19
24
|
obj = self.cache[cache_key]
|
20
25
|
return obj
|
21
26
|
|
22
27
|
try:
|
23
|
-
obj =
|
28
|
+
obj = pid_field_context.resolve(id_)
|
24
29
|
# We detach the related record model from the database session when
|
25
30
|
# we add it in the cache. Otherwise, accessing the cached record
|
26
31
|
# model, will execute a new select query after a db.session.commit.
|
@@ -28,8 +33,10 @@ class PIDRelationResult(RelationResult):
|
|
28
33
|
self.cache[cache_key] = obj
|
29
34
|
return obj
|
30
35
|
except Exception as e:
|
31
|
-
raise
|
32
|
-
f"Repository object {cache_key} has not been found or there was an exception accessing it"
|
36
|
+
raise InvalidRelationError(
|
37
|
+
f"Repository object {cache_key} has not been found or there was an exception accessing it. Referenced from {self.field.key}.",
|
38
|
+
related_id=id_,
|
39
|
+
location=self.field.key,
|
33
40
|
) from e
|
34
41
|
|
35
42
|
def _needs_update_relation_value(self, relation: LookupResult):
|
@@ -12,8 +12,8 @@ oarepo_runtime/cli/__init__.py,sha256=-WGXmjHoSqiApR_LvYnZTimuL-frR7SynrsSklnjb3
|
|
12
12
|
oarepo_runtime/cli/assets.py,sha256=XLZTnsGb88O5N8R2D3AYpZqtnO4JrbybUtRLKnL1p3w,2430
|
13
13
|
oarepo_runtime/cli/base.py,sha256=xZMsR2rati5Mz0DZzmnlhVI7E6ePCfnOiTayrxT9cWU,259
|
14
14
|
oarepo_runtime/cli/check.py,sha256=zQ6txhfN6LWvdWgRa3ZFdOifbuazoRQd-7ml0qwIBWg,2358
|
15
|
-
oarepo_runtime/cli/index.py,sha256=
|
16
|
-
oarepo_runtime/cli/validate.py,sha256=
|
15
|
+
oarepo_runtime/cli/index.py,sha256=fZMMw0Z4vwJ9fe7g8tb4wyoAMKeushxORvIUgxWQA40,4701
|
16
|
+
oarepo_runtime/cli/validate.py,sha256=HpSvHQCGHlrdgdpKix9cIlzlBoJEiT1vACZdMnOUGEY,2827
|
17
17
|
oarepo_runtime/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
18
|
oarepo_runtime/config/permissions_presets.py,sha256=4gWNYwOi7CmS69PnxpbjHY45sc0q7BcrvkhSFdn1SlU,5786
|
19
19
|
oarepo_runtime/config/service.py,sha256=IDDEQJ3LWYBLTFhE_8jPXiinIDNDY52fI0zigDJ_usQ,1095
|
@@ -60,10 +60,11 @@ oarepo_runtime/i18n/validation.py,sha256=fyMTi2Rw-KiHv7c7HN61zGxRVa9sAjAEEkAL5wU
|
|
60
60
|
oarepo_runtime/relations/__init__.py,sha256=bDAgxl_LdKsqpGG3qluxAkQnn5u2ItJngnHQKkqzlkE,373
|
61
61
|
oarepo_runtime/relations/base.py,sha256=YLfZ_AKGv1uf-d22U01e7OwiBgW00lBmsPQbknhTFLI,8329
|
62
62
|
oarepo_runtime/relations/components.py,sha256=J9rvzaAoRDbSVuA01hIOlXKQP-OE5VJI5w5xuMsFO70,602
|
63
|
+
oarepo_runtime/relations/errors.py,sha256=t-vVyefGPP07-_-YmhWjjGbhXU3GQ3sVtUPt5_IZ-5E,197
|
63
64
|
oarepo_runtime/relations/internal.py,sha256=OTp8iJqyl80sWDk0Q0AK42l6UsxZDABspVU_GwWza9o,1556
|
64
65
|
oarepo_runtime/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfSdpmjK0wvOFsEM,848
|
65
66
|
oarepo_runtime/relations/mapping.py,sha256=jwFCWCnW8hb44ZZBeVf96QR79S9FT2hvm4L8EuCBo5U,1277
|
66
|
-
oarepo_runtime/relations/pid_relation.py,sha256=
|
67
|
+
oarepo_runtime/relations/pid_relation.py,sha256=SEAZ99x9lOj91EPSIDZuVCTWW1a13A5iv9RrO7GRdUY,2424
|
67
68
|
oarepo_runtime/relations/uow.py,sha256=KrN8B-wVbmb0kOErxb7bAhPmOR6-mMRgBr-ab-ir6hQ,151
|
68
69
|
oarepo_runtime/resolvers/__init__.py,sha256=kTlvSiympib59YQV7wEKpIXGprPWRuvxLIwmeeQdUec,89
|
69
70
|
oarepo_runtime/resolvers/proxies.py,sha256=egtT7uXL91KswWI7gqUIaz1vWIHezdsiI_M-xRKXWww,547
|
@@ -80,9 +81,9 @@ oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,
|
|
80
81
|
oarepo_runtime/validation/__init__.py,sha256=lU7DgZq8pGD5Pa-QqL9gvLsib3IYtM-Y56k-NwHrPG0,166
|
81
82
|
oarepo_runtime/validation/dates.py,sha256=fahqKGDdIYWux5ZeoljrEe8VD2fDZR9VpfvYmTYAmpw,1050
|
82
83
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
83
|
-
oarepo_runtime-1.4.
|
84
|
-
oarepo_runtime-1.4.
|
85
|
-
oarepo_runtime-1.4.
|
86
|
-
oarepo_runtime-1.4.
|
87
|
-
oarepo_runtime-1.4.
|
88
|
-
oarepo_runtime-1.4.
|
84
|
+
oarepo_runtime-1.4.6.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
85
|
+
oarepo_runtime-1.4.6.dist-info/METADATA,sha256=Qz4fu5lS2SVdr_-opBBEtzkFsWoGIMF78prI4eW-EyY,2694
|
86
|
+
oarepo_runtime-1.4.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
87
|
+
oarepo_runtime-1.4.6.dist-info/entry_points.txt,sha256=C32W4eT-8OypMCfwOO5WREioVKSneDfY51D78Uvdbp0,231
|
88
|
+
oarepo_runtime-1.4.6.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
89
|
+
oarepo_runtime-1.4.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|