dcicutils 8.14.0.1b27__py3-none-any.whl → 8.14.0.1b29__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 +5 -2
- dcicutils/scripts/view_portal_object.py +91 -42
- {dcicutils-8.14.0.1b27.dist-info → dcicutils-8.14.0.1b29.dist-info}/METADATA +1 -1
- {dcicutils-8.14.0.1b27.dist-info → dcicutils-8.14.0.1b29.dist-info}/RECORD +7 -7
- {dcicutils-8.14.0.1b27.dist-info → dcicutils-8.14.0.1b29.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.14.0.1b27.dist-info → dcicutils-8.14.0.1b29.dist-info}/WHEEL +0 -0
- {dcicutils-8.14.0.1b27.dist-info → dcicutils-8.14.0.1b29.dist-info}/entry_points.txt +0 -0
@@ -562,8 +562,11 @@ def _load_data(portal: Portal, load: str, ini_file: str, explicit_schema_name: O
|
|
562
562
|
else:
|
563
563
|
data = {schema_name: [data]}
|
564
564
|
if not _is_schema_name_list(portal, schema_names := list(data.keys())):
|
565
|
-
|
566
|
-
|
565
|
+
if not (schema_name := _get_schema_name_from_schema_named_json_file_name(portal, inserts_file)):
|
566
|
+
_print(f"Unrecognized types in JSON data file: {inserts_file}")
|
567
|
+
# Assume simple object of type from the JSON file name.
|
568
|
+
schema_names = [schema_name]
|
569
|
+
data = {schema_name: [data]}
|
567
570
|
with temporary_directory() as tmpdir:
|
568
571
|
nfiles = 0
|
569
572
|
for schema_name in schema_names:
|
@@ -307,28 +307,76 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
307
307
|
return None
|
308
308
|
return metadata_types
|
309
309
|
|
310
|
-
response
|
311
|
-
|
312
|
-
if
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
310
|
+
def write_insert_files(response: dict) -> None:
|
311
|
+
nonlocal insert_files, force
|
312
|
+
output_directory = insert_files if isinstance(insert_files, str) else os.getcwd()
|
313
|
+
for schema_name in response:
|
314
|
+
schema_data = response[schema_name]
|
315
|
+
file_name = f"{to_snake_case(schema_name)}.json"
|
316
|
+
file_path = os.path.join(output_directory, file_name)
|
317
|
+
message_verb = "Writing"
|
318
|
+
if os.path.exists(file_path):
|
319
|
+
message_verb = "Overwriting"
|
320
|
+
if os.path.isdir(file_path):
|
321
|
+
_print(f"WARNING: Output file already exists as a directory. SKIPPING: {file_path}")
|
322
|
+
continue
|
323
|
+
if not force:
|
324
|
+
_print(f"Output file already exists: {file_path}")
|
325
|
+
if not yes_or_no(f"Overwrite this file?"):
|
326
|
+
continue
|
327
|
+
if verbose:
|
328
|
+
_print(f"{message_verb} {schema_name} (object{'s' if len(schema_data) != 1 else ''}:"
|
329
|
+
f" {len(schema_data)}) file: {file_path}")
|
330
|
+
with io.open(file_path, "w") as f:
|
331
|
+
json.dump(schema_data, f, indent=4)
|
332
|
+
|
333
|
+
if os.path.exists(uuid) and inserts:
|
334
|
+
# Very special case: If given "uuid" (or other path) as actually a file then assume it
|
335
|
+
# contains a list of references (e.g. /Donor/3039a6ca-9849-432d-ad49-2c5630bcbee7) to fetch.
|
336
|
+
response = {}
|
337
|
+
if verbose:
|
338
|
+
_print(f"Reading references from file: {uuid}")
|
339
|
+
with io.open(uuid) as f:
|
340
|
+
for line in f:
|
341
|
+
if ((line := line.strip()) and (components := line.split("/")) and (len(components) > 1) and
|
342
|
+
(schema_name := components[1]) and (schema_name := _get_schema(portal, schema_name)[1])): # noqa
|
343
|
+
try:
|
344
|
+
if ((result := portal.get(line, raw=True, database=database)) and
|
345
|
+
(result.status_code in [200, 307]) and (result := result.json())): # noqa
|
346
|
+
if not response.get(schema_name):
|
347
|
+
response[schema_name] = []
|
348
|
+
response[schema_name].append(result)
|
349
|
+
continue
|
350
|
+
except Exception:
|
351
|
+
pass
|
352
|
+
_print(f"Cannot get reference: {line}")
|
353
|
+
if insert_files:
|
354
|
+
write_insert_files(response)
|
355
|
+
return response
|
356
|
+
else:
|
357
|
+
response = None
|
358
|
+
try:
|
359
|
+
if not uuid.startswith("/"):
|
360
|
+
path = f"/{uuid}"
|
361
|
+
else:
|
362
|
+
path = uuid
|
363
|
+
response = portal.get(path, raw=raw or inserts, database=database)
|
364
|
+
except Exception as e:
|
365
|
+
if "404" in str(e) and "not found" in str(e).lower():
|
366
|
+
_print(f"Portal object not found at {portal.server}: {uuid}")
|
367
|
+
_exit()
|
368
|
+
_exit(f"Exception getting Portal object from {portal.server}: {uuid}\n{get_error_message(e)}")
|
369
|
+
if not response:
|
370
|
+
if check:
|
371
|
+
return None
|
372
|
+
_exit(f"Null response getting Portal object from {portal.server}: {uuid}")
|
373
|
+
if response.status_code not in [200, 307]:
|
374
|
+
# TODO: Understand why the /me endpoint returns HTTP status code 307, which is only why we mention it above.
|
375
|
+
_exit(f"Invalid status code ({response.status_code}) getting Portal object from {portal.server}: {uuid}")
|
376
|
+
if not response.json:
|
377
|
+
_exit(f"Invalid JSON getting Portal object: {uuid}")
|
378
|
+
response = response.json()
|
379
|
+
|
332
380
|
response_types = {}
|
333
381
|
if inserts:
|
334
382
|
# Format results as suitable for inserts (e.g. via update-portal-object).
|
@@ -376,26 +424,27 @@ def _get_portal_object(portal: Portal, uuid: str,
|
|
376
424
|
(isinstance(response_type := response_cooked.json().get("@type"), list) and response_type)):
|
377
425
|
response = {f"{response_type[0]}": [prune_data(response)]}
|
378
426
|
if insert_files:
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
427
|
+
write_insert_files(response)
|
428
|
+
# output_directory = insert_files if isinstance(insert_files, str) else os.getcwd()
|
429
|
+
# for schema_name in response:
|
430
|
+
# schema_data = response[schema_name]
|
431
|
+
# file_name = f"{to_snake_case(schema_name)}.json"
|
432
|
+
# file_path = os.path.join(output_directory, file_name)
|
433
|
+
# message_verb = "Writing"
|
434
|
+
# if os.path.exists(file_path):
|
435
|
+
# message_verb = "Overwriting"
|
436
|
+
# if os.path.isdir(file_path):
|
437
|
+
# _print(f"WARNING: Output file already exists as a directory. SKIPPING: {file_path}")
|
438
|
+
# continue
|
439
|
+
# if not force:
|
440
|
+
# _print(f"Output file already exists: {file_path}")
|
441
|
+
# if not yes_or_no(f"Overwrite this file?"):
|
442
|
+
# continue
|
443
|
+
# if verbose:
|
444
|
+
# _print(f"{message_verb} {schema_name} (object{'s' if len(schema_data) != 1 else ''}:"
|
445
|
+
# f" {len(schema_data)}) file: {file_path}")
|
446
|
+
# with io.open(file_path, "w") as f:
|
447
|
+
# json.dump(schema_data, f, indent=4)
|
399
448
|
elif raw:
|
400
449
|
response.pop("schema_version", None)
|
401
450
|
return response
|
@@ -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=BwZw1cZx2zhzp1ivn_DXUxfnmUyC5A9fAotjHV0fXf4,41875
|
64
|
+
dcicutils/scripts/view_portal_object.py,sha256=mfaWIjVD_dtLNl8Gfue-9Xo1zBrfChe2Tr9J6aoA7sA,41274
|
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.1b29.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
79
|
+
dcicutils-8.14.0.1b29.dist-info/METADATA,sha256=ht8DVYhzxCHVincEsvta3kwooBimQ6Iei03TjAYL24k,3440
|
80
|
+
dcicutils-8.14.0.1b29.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
81
|
+
dcicutils-8.14.0.1b29.dist-info/entry_points.txt,sha256=W6kEWdUJk9tQ4myAgpehPdebcwvCAZ7UgB-wyPgDUMg,335
|
82
|
+
dcicutils-8.14.0.1b29.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|