dcicutils 8.14.0.1b5__py3-none-any.whl → 8.14.0.1b7__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dcicutils/scripts/update_portal_object.py +0 -1
- dcicutils/scripts/view_portal_object.py +62 -27
- {dcicutils-8.14.0.1b5.dist-info → dcicutils-8.14.0.1b7.dist-info}/METADATA +1 -1
- {dcicutils-8.14.0.1b5.dist-info → dcicutils-8.14.0.1b7.dist-info}/RECORD +7 -7
- {dcicutils-8.14.0.1b5.dist-info → dcicutils-8.14.0.1b7.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.14.0.1b5.dist-info → dcicutils-8.14.0.1b7.dist-info}/WHEEL +0 -0
- {dcicutils-8.14.0.1b5.dist-info → dcicutils-8.14.0.1b7.dist-info}/entry_points.txt +0 -0
@@ -251,7 +251,6 @@ def _post_or_patch_or_upsert(portal: Portal, file_or_directory: str,
|
|
251
251
|
elif isinstance(data, list):
|
252
252
|
if debug:
|
253
253
|
_print(f"DEBUG: File ({file}) contains a list of objects of type: {schema_name}")
|
254
|
-
import pdb ; pdb.set_trace() # noqa
|
255
254
|
data = _impose_special_ordering(data, schema_name)
|
256
255
|
for index, item in enumerate(data):
|
257
256
|
update_function(portal, item, schema_name, file=file, index=index,
|
@@ -122,11 +122,13 @@ def main():
|
|
122
122
|
parser.add_argument("--force", action="store_true", required=False, default=False, help="Debugging output.")
|
123
123
|
parser.add_argument("--terse", action="store_true", required=False, default=False, help="Terse output.")
|
124
124
|
parser.add_argument("--verbose", action="store_true", required=False, default=False, help="Verbose output.")
|
125
|
+
parser.add_argument("--noheader", action="store_true", required=False, default=False, help="Supress header output.")
|
125
126
|
parser.add_argument("--debug", action="store_true", required=False, default=False, help="Debugging output.")
|
126
127
|
args = parser.parse_args()
|
127
128
|
|
128
129
|
portal = _create_portal(ini=args.ini, env=args.env or os.environ.get("SMAHT_ENV"),
|
129
|
-
server=args.server, app=args.app,
|
130
|
+
server=args.server, app=args.app,
|
131
|
+
verbose=args.verbose and not args.noheader, debug=args.debug)
|
130
132
|
|
131
133
|
if not args.uuid:
|
132
134
|
_print("UUID or schema or path required.")
|
@@ -205,7 +207,8 @@ def main():
|
|
205
207
|
|
206
208
|
data = _get_portal_object(portal=portal, uuid=args.uuid, raw=args.raw, database=args.database,
|
207
209
|
inserts=args.inserts, insert_files=args.insert_files,
|
208
|
-
ignore=args.ignore, check=args.bool,
|
210
|
+
ignore=args.ignore, check=args.bool,
|
211
|
+
force=args.force, verbose=args.verbose, debug=args.debug)
|
209
212
|
if args.insert_files:
|
210
213
|
return
|
211
214
|
|
@@ -261,7 +264,8 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
261
264
|
raw: bool = False, database: bool = False,
|
262
265
|
inserts: bool = False, insert_files: bool = False,
|
263
266
|
ignore: Optional[List[str]] = None,
|
264
|
-
check: bool = False, force: bool = False,
|
267
|
+
check: bool = False, force: bool = False,
|
268
|
+
verbose: bool = False, debug: bool = False) -> dict:
|
265
269
|
|
266
270
|
def prune_data(data: dict) -> dict:
|
267
271
|
nonlocal ignore
|
@@ -269,6 +273,23 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
269
273
|
return data
|
270
274
|
return {key: value for key, value in data.items() if key not in ignore}
|
271
275
|
|
276
|
+
def get_metadata_for_individual_result_type(uuid: str) -> Optional[dict]: # noqa
|
277
|
+
# There can be a lot of individual results for which we may need to get the actual type,
|
278
|
+
# so do this in a function we were can give verbose output feedback.
|
279
|
+
nonlocal portal, results_index, results_total, verbose
|
280
|
+
if verbose:
|
281
|
+
_print(f"Getting actual type for {results_type} result:"
|
282
|
+
f" {uuid} [{results_index} of {results_total}]", end="")
|
283
|
+
result = portal.get_metadata(uuid, raise_exception=False)
|
284
|
+
if (isinstance(result_types := result.get("@type"), list) and
|
285
|
+
result_types and (result_type := result_types[0])): # noqa
|
286
|
+
if verbose:
|
287
|
+
_print(f" -> {result_type}")
|
288
|
+
return result_type
|
289
|
+
if verbose:
|
290
|
+
_print()
|
291
|
+
return None
|
292
|
+
|
272
293
|
response = None
|
273
294
|
try:
|
274
295
|
if not uuid.startswith("/"):
|
@@ -307,27 +328,11 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
307
328
|
response = {}
|
308
329
|
results_index = 0
|
309
330
|
results_total = len(results)
|
310
|
-
def get_metadata_for_individual_result_type(uuid: str) -> Optional[dict]: # noqa
|
311
|
-
# There can be a lot of individual results for which we may need to get the actual type,
|
312
|
-
# so do this in a function we were can give verbose output feedback.
|
313
|
-
nonlocal portal, results_index, results_total, verbose
|
314
|
-
if verbose:
|
315
|
-
_print(f"Getting actual type for {results_type} result:"
|
316
|
-
f" {uuid} [{results_index} of {results_total}]", end="")
|
317
|
-
result = portal.get_metadata(uuid, raise_exception=False)
|
318
|
-
if (isinstance(result_types := result.get("@type"), list) and
|
319
|
-
result_types and (result_type := result_types[0])): # noqa
|
320
|
-
if verbose:
|
321
|
-
_print(f" -> {result_type}")
|
322
|
-
return result_type
|
323
|
-
if verbose:
|
324
|
-
_print()
|
325
|
-
return None
|
326
331
|
for result in results:
|
327
332
|
results_index += 1
|
328
333
|
result.pop("schema_version", None)
|
329
334
|
result = prune_data(result)
|
330
|
-
if (subtypes and
|
335
|
+
if (subtypes and one_or_more_objects_of_types_exists(portal, subtypes, debug=debug) and
|
331
336
|
(result_uuid := result.get("uuid")) and
|
332
337
|
(individual_result_type := get_metadata_for_individual_result_type(result_uuid))): # noqa
|
333
338
|
result_type = individual_result_type
|
@@ -347,19 +352,18 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
347
352
|
schema_data = response[schema_name]
|
348
353
|
file_name = f"{to_snake_case(schema_name)}.json"
|
349
354
|
file_path = os.path.join(output_directory, file_name)
|
355
|
+
message_verb = "Writing"
|
350
356
|
if os.path.exists(file_path):
|
357
|
+
message_verb = "Overwriting"
|
351
358
|
if os.path.isdir(file_path):
|
352
359
|
_print(f"WARNING: Output file already exists as a directory. SKIPPING: {file_path}")
|
353
360
|
continue
|
354
|
-
if force:
|
355
|
-
if verbose:
|
356
|
-
_print(f"Overwriting extant file (per --force option): {file_path}")
|
357
|
-
else:
|
361
|
+
if not force:
|
358
362
|
_print(f"Output file already exists: {file_path}")
|
359
|
-
|
360
|
-
|
363
|
+
if not yes_or_no(f"Overwrite this file?"):
|
364
|
+
continue
|
361
365
|
if verbose:
|
362
|
-
_print(f"
|
366
|
+
_print(f"{message_verb} {schema_name} (object{'s' if len(schema_data) != 1 else ''}:"
|
363
367
|
f" {len(schema_data)}) file: {file_path}")
|
364
368
|
with io.open(file_path, "w") as f:
|
365
369
|
json.dump(schema_data, f, indent=4)
|
@@ -368,6 +372,37 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
368
372
|
return response
|
369
373
|
|
370
374
|
|
375
|
+
def one_or_more_objects_of_types_exists(portal: Portal, schema_types: List[str], debug: bool = False) -> bool:
|
376
|
+
for schema_type in schema_types:
|
377
|
+
try:
|
378
|
+
if one_or_more_objects_of_type_exists(portal, schema_type, debug=debug):
|
379
|
+
return True
|
380
|
+
response = portal.get(f"/{schema_type}")
|
381
|
+
if response and response.status_code == 404:
|
382
|
+
_print(f"There are no objects of sub-type: {schema_type}")
|
383
|
+
return False
|
384
|
+
except Exception:
|
385
|
+
return True
|
386
|
+
return False
|
387
|
+
|
388
|
+
|
389
|
+
@lru_cache(maxsize=64)
|
390
|
+
def one_or_more_objects_of_type_exists(portal: Portal, schema_type: str, debug: bool = False) -> bool:
|
391
|
+
try:
|
392
|
+
if debug:
|
393
|
+
_print(f"Checking if there are actually any objects of type: {schema_type}")
|
394
|
+
if portal.get(f"/{schema_type}").status_code == 404:
|
395
|
+
if debug:
|
396
|
+
_print(f"No any objects of type exist: {schema_type}")
|
397
|
+
else:
|
398
|
+
if debug:
|
399
|
+
_print(f"One or more objects of type exist: {schema_type}")
|
400
|
+
except Exception as e:
|
401
|
+
_print(f"ERROR: Checking if there are actually any objects of type: {schema_type}")
|
402
|
+
_print(e)
|
403
|
+
return False
|
404
|
+
|
405
|
+
|
371
406
|
@lru_cache(maxsize=1)
|
372
407
|
def _get_schemas(portal: Portal) -> Optional[dict]:
|
373
408
|
return portal.get_schemas()
|
@@ -60,8 +60,8 @@ dcicutils/s3_utils.py,sha256=h2B9ftOo-kxqfiKth5ZDC_cAUFy1Pbu7BrVanFnE5Iw,28839
|
|
60
60
|
dcicutils/schema_utils.py,sha256=GmRm-XqZKJ6qine16SQF1txcby9WougDav_sYmKNs9E,12400
|
61
61
|
dcicutils/scripts/publish_to_pypi.py,sha256=sMd4WASQGlxlh7uLrt2eGkFRXYgONVmvIg8mClMS5RQ,13903
|
62
62
|
dcicutils/scripts/run_license_checker.py,sha256=z2keYnRDZsHQbTeo1XORAXSXNJK5axVzL5LjiNqZ7jE,4184
|
63
|
-
dcicutils/scripts/update_portal_object.py,sha256=
|
64
|
-
dcicutils/scripts/view_portal_object.py,sha256=
|
63
|
+
dcicutils/scripts/update_portal_object.py,sha256=5ET0RtwSgIPt5z7WiSf_UuEow-J2Bs-GEpmvria09Pg,22557
|
64
|
+
dcicutils/scripts/view_portal_object.py,sha256=HONEHVu8Qs_ukdv8fHKqlJFLXHQn9xZyRDmcdBIQDqY,37140
|
65
65
|
dcicutils/secrets_utils.py,sha256=8dppXAsiHhJzI6NmOcvJV5ldvKkQZzh3Fl-cb8Wm7MI,19745
|
66
66
|
dcicutils/sheet_utils.py,sha256=VlmzteONW5VF_Q4vo0yA5vesz1ViUah1MZ_yA1rwZ0M,33629
|
67
67
|
dcicutils/snapshot_utils.py,sha256=YDeI3vD-MhAtHwKDzfEm2q-n3l-da2yRpRR3xp0Ah1M,23021
|
@@ -75,8 +75,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
|
|
75
75
|
dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
|
76
76
|
dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
|
77
77
|
dcicutils/zip_utils.py,sha256=_Y9EmL3D2dUZhxucxHvrtmmlbZmK4FpSsHEb7rGSJLU,3265
|
78
|
-
dcicutils-8.14.0.
|
79
|
-
dcicutils-8.14.0.
|
80
|
-
dcicutils-8.14.0.
|
81
|
-
dcicutils-8.14.0.
|
82
|
-
dcicutils-8.14.0.
|
78
|
+
dcicutils-8.14.0.1b7.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
79
|
+
dcicutils-8.14.0.1b7.dist-info/METADATA,sha256=HUAn-3SXVZZktV4SgAoJI5z9h-zZkij9v5QwF-a5WzQ,3439
|
80
|
+
dcicutils-8.14.0.1b7.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
81
|
+
dcicutils-8.14.0.1b7.dist-info/entry_points.txt,sha256=W6kEWdUJk9tQ4myAgpehPdebcwvCAZ7UgB-wyPgDUMg,335
|
82
|
+
dcicutils-8.14.0.1b7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|