oarepo-runtime 1.5.32__py3-none-any.whl → 1.5.33__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,17 +95,6 @@ def record_or_service(model):
95
95
  return record
96
96
 
97
97
 
98
- def model_records_generator(model_class):
99
- try:
100
- for x in db.session.query(model_class.model_cls.id).filter(
101
- model_class.model_cls.is_deleted.is_(False)
102
- ):
103
- rec_id = x[0]
104
- yield model_class.get_record(rec_id)
105
- except Exception as e:
106
- click.secho(f"Could not index {model_class}: {e}", fg="red", file=sys.stderr)
107
-
108
-
109
98
  @index.command()
110
99
  @with_appcontext
111
100
  @click.argument("model", required=False)
@@ -119,14 +108,22 @@ def reindex(model, bulk_size, verbose):
119
108
  for service_id in services:
120
109
  click.secho(f"Preparing to index {service_id}", file=sys.stderr)
121
110
 
122
- service = current_service_registry.get(service_id)
111
+ try:
112
+ service = current_service_registry.get(service_id)
113
+ except KeyError:
114
+ click.secho(f"Service {service_id} not in known services:", color="red")
115
+ for known_service_id, known_service in sorted(current_service_registry._services.items()):
116
+ click.secho(f" {known_service_id} -> {type(known_service).__module__}.{type(known_service).__name__}", color="red")
117
+ sys.exit(1)
123
118
  record_class = getattr(service.config, "record_cls", None)
124
119
 
125
120
  id_generators = []
126
121
 
122
+ record_generator = RECORD_GENERATORS.get(service_id, model_records_generator)
123
+
127
124
  if record_class and hasattr(service, "indexer"):
128
125
  try:
129
- id_generators.append(model_records_generator(record_class))
126
+ id_generators.append(record_generator(record_class))
130
127
  except Exception as e:
131
128
  click.secho(
132
129
  f"Could not get record ids for {service_id}, exception {e}",
@@ -137,7 +134,7 @@ def reindex(model, bulk_size, verbose):
137
134
 
138
135
  if draft_class and hasattr(service, "indexer"):
139
136
  try:
140
- id_generators.append(model_records_generator(draft_class))
137
+ id_generators.append(record_generator(draft_class))
141
138
  except Exception as e:
142
139
  click.secho(
143
140
  f"Could not get draft record ids for {service_id}, exception {e}",
@@ -151,7 +148,6 @@ def reindex(model, bulk_size, verbose):
151
148
  for bulk in generate_bulk_data(gen, service.indexer, bulk_size=bulk_size):
152
149
  index_result = service.indexer.client.bulk(bulk)
153
150
  count += len(bulk) // 2
154
-
155
151
  for index_item_result in index_result["items"]:
156
152
  result = index_item_result["index"]
157
153
  if result["status"] != 200:
@@ -215,3 +211,28 @@ def dump_yaml(data):
215
211
  io = StringIO()
216
212
  yaml.dump(data, io, allow_unicode=True)
217
213
  return io.getvalue()
214
+
215
+
216
+ def model_records_generator(model_class):
217
+ try:
218
+ for x in db.session.query(model_class.model_cls.id).filter(
219
+ model_class.model_cls.is_deleted.is_(False)
220
+ ):
221
+ rec_id = x[0]
222
+ yield model_class.get_record(rec_id)
223
+ except Exception as e:
224
+ click.secho(f"Could not index {model_class}: {e}", fg="red", file=sys.stderr)
225
+
226
+ def users_record_generator(model_class):
227
+ from invenio_accounts.models import User
228
+ from invenio_users_resources.records.api import UserAggregate
229
+ try:
230
+ for x in db.session.query(User.id):
231
+ rec_id = x[0]
232
+ yield UserAggregate.get_record(rec_id)
233
+ except Exception as e:
234
+ click.secho(f"Could not index {model_class}: {e}", fg="red", file=sys.stderr)
235
+
236
+ RECORD_GENERATORS = {
237
+ 'users': users_record_generator
238
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.32
3
+ Version: 1.5.33
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -11,7 +11,7 @@ oarepo_runtime/cli/cf.py,sha256=W0JEJK2JqKubQw8qtZJxohmADDRUBode4JZAqYLDGvc,339
11
11
  oarepo_runtime/cli/check.py,sha256=AvC5VHAnwmtCd8R-Caj8v6nCAREKjObTdNtLJ24aJO8,4935
12
12
  oarepo_runtime/cli/configuration.py,sha256=cLXoGDtjuA5uv9ZfYFcH0C4wcadj0qWC3P_E4Bf5-z0,1061
13
13
  oarepo_runtime/cli/fixtures.py,sha256=teMbU-ocrSOmmCJvK-ICl6lMTAOWxJ5Tpkg6JQc0Y0s,5486
14
- oarepo_runtime/cli/index.py,sha256=H4nSZnClnlCSI8Thlz_jx-uPpgNVVQyagpWIPtQoIr4,7239
14
+ oarepo_runtime/cli/index.py,sha256=6SaM3Ml6qCRakXbGz3afBAYM9hFRYrPIa6vw3pwqR_Q,8158
15
15
  oarepo_runtime/cli/validate.py,sha256=HpSvHQCGHlrdgdpKix9cIlzlBoJEiT1vACZdMnOUGEY,2827
16
16
  oarepo_runtime/datastreams/__init__.py,sha256=_i52Ek9J8DMARST0ejZAZPzUKm55xrrlKlCSO7dl6y4,1008
17
17
  oarepo_runtime/datastreams/asynchronous.py,sha256=1I1mEaTxyrcHD7LK6O9z2QX37AgeejflxynGmLreLQ0,7396
@@ -115,9 +115,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
115
115
  oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
116
116
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
117
117
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
118
- oarepo_runtime-1.5.32.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
119
- oarepo_runtime-1.5.32.dist-info/METADATA,sha256=_PPldeHNddy89KosMLaNCm1xzAEjET1eHnno3M-31PU,4680
120
- oarepo_runtime-1.5.32.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
121
- oarepo_runtime-1.5.32.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
122
- oarepo_runtime-1.5.32.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
123
- oarepo_runtime-1.5.32.dist-info/RECORD,,
118
+ oarepo_runtime-1.5.33.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
119
+ oarepo_runtime-1.5.33.dist-info/METADATA,sha256=8SWJONfiL0aijLAY7T3HCmdN4RegicsAM3feIB68qRU,4680
120
+ oarepo_runtime-1.5.33.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
121
+ oarepo_runtime-1.5.33.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
122
+ oarepo_runtime-1.5.33.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
123
+ oarepo_runtime-1.5.33.dist-info/RECORD,,