dcicutils 8.14.0.1b15__py3-none-any.whl → 8.14.0.1b16__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 +88 -60
- {dcicutils-8.14.0.1b15.dist-info → dcicutils-8.14.0.1b16.dist-info}/METADATA +1 -1
- {dcicutils-8.14.0.1b15.dist-info → dcicutils-8.14.0.1b16.dist-info}/RECORD +6 -6
- {dcicutils-8.14.0.1b15.dist-info → dcicutils-8.14.0.1b16.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.14.0.1b15.dist-info → dcicutils-8.14.0.1b16.dist-info}/WHEEL +0 -0
- {dcicutils-8.14.0.1b15.dist-info → dcicutils-8.14.0.1b16.dist-info}/entry_points.txt +0 -0
@@ -17,8 +17,9 @@ import re
|
|
17
17
|
import shutil
|
18
18
|
import sys
|
19
19
|
from typing import Callable, List, Optional, Tuple, Union
|
20
|
+
from dcicutils.captured_output import captured_output
|
20
21
|
from dcicutils.command_utils import yes_or_no
|
21
|
-
from dcicutils.common import ORCHESTRATED_APPS, APP_SMAHT
|
22
|
+
from dcicutils.common import ORCHESTRATED_APPS, APP_CGAP, APP_FOURFRONT, APP_SMAHT
|
22
23
|
from dcicutils.ff_utils import delete_metadata, purge_metadata
|
23
24
|
from dcicutils.misc_utils import get_error_message, ignored, PRINT, to_camel_case, to_snake_case
|
24
25
|
from dcicutils.portal_utils import Portal as PortalFromUtils
|
@@ -145,30 +146,16 @@ def main():
|
|
145
146
|
parser.print_help()
|
146
147
|
sys.exit(1)
|
147
148
|
|
148
|
-
if app := args.app:
|
149
|
-
if (app not in ORCHESTRATED_APPS) and ((app := app.lower()) not in ORCHESTRATED_APPS):
|
150
|
-
usage(f"ERROR: Unknown app name; must be one of: {' | '.join(ORCHESTRATED_APPS)}")
|
151
|
-
else:
|
152
|
-
app = APP_SMAHT
|
153
|
-
|
154
149
|
if not (args.post or args.patch or args.upsert or args.delete or args.purge or args.load):
|
155
150
|
usage()
|
156
151
|
|
152
|
+
if not (portal := _create_portal(env=args.env, ini=args.ini, app=args.app, load=args.load,
|
153
|
+
verbose=args.verbose, debug=args.debug, quiet=args.quiet)):
|
154
|
+
exit(1)
|
155
|
+
|
157
156
|
if args.load:
|
158
|
-
|
159
|
-
|
160
|
-
"when using the --load option (to load data via snovault.loadxl).")
|
161
|
-
exit(1)
|
162
|
-
if args.env:
|
163
|
-
if args.ini:
|
164
|
-
_print("The --env is not used for the --load option (to load data via snovault.loadxl).")
|
165
|
-
args.ini = args.env
|
166
|
-
if not _load_data(load=args.load, ini_file=args.ini, explicit_schema_name=args.schema,
|
167
|
-
verbose=args.verbose, debug=args.debug, noprogress=args.noprogress):
|
168
|
-
exit(1)
|
169
|
-
exit(0)
|
170
|
-
|
171
|
-
portal = _create_portal(env=args.env, app=app, verbose=args.verbose, debug=args.debug)
|
157
|
+
_load_data(portal=portal, load=args.load, ini_file=args.ini, explicit_schema_name=args.schema,
|
158
|
+
verbose=args.verbose, debug=args.debug, noprogress=args.noprogress)
|
172
159
|
|
173
160
|
if explicit_schema_name := args.schema:
|
174
161
|
schema, explicit_schema_name = _get_schema(portal, explicit_schema_name)
|
@@ -402,17 +389,18 @@ def _upsert_data(portal: Portal, data: dict, schema_name: str,
|
|
402
389
|
return
|
403
390
|
|
404
391
|
|
405
|
-
def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = None,
|
392
|
+
def _load_data(portal: Portal, load: str, ini_file: str, explicit_schema_name: Optional[str] = None,
|
406
393
|
verbose: bool = False, debug: bool = False, noprogress: bool = False,
|
407
|
-
|
394
|
+
_single_insert_file: Optional[str] = None) -> bool:
|
408
395
|
|
409
396
|
from snovault.loadxl import load_all_gen, LoadGenWrapper
|
410
|
-
from dcicutils.captured_output import captured_output
|
411
397
|
from dcicutils.progress_bar import ProgressBar
|
412
398
|
|
399
|
+
loadxl_summary = {}
|
400
|
+
|
413
401
|
def loadxl(portal: Portal, inserts_directory: str, schema_names_to_load: dict):
|
414
402
|
|
415
|
-
nonlocal LoadGenWrapper, load_all_gen, verbose, debug
|
403
|
+
nonlocal LoadGenWrapper, load_all_gen, loadxl_summary, verbose, debug
|
416
404
|
progress_total = sum(schema_names_to_load.values()) * 2 # loadxl does two passes
|
417
405
|
progress_bar = ProgressBar(progress_total, interrupt_exit=True) if not noprogress else None
|
418
406
|
|
@@ -452,6 +440,9 @@ def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = N
|
|
452
440
|
if progress_bar:
|
453
441
|
progress_bar.set_description(f"▶ {to_camel_case(current_item_type)}: {action}")
|
454
442
|
current_item_count += 1
|
443
|
+
if loadxl_summary.get(current_item_type, None) is None:
|
444
|
+
loadxl_summary[current_item_type] = 0
|
445
|
+
loadxl_summary[current_item_type] += 1
|
455
446
|
if progress_bar:
|
456
447
|
progress_bar.set_progress(total_item_count)
|
457
448
|
elif debug:
|
@@ -460,14 +451,9 @@ def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = N
|
|
460
451
|
progress_bar.set_description("▶ Load Complete")
|
461
452
|
print()
|
462
453
|
|
463
|
-
if not
|
464
|
-
|
465
|
-
|
466
|
-
ini_file = os.path.normpath(os.path.join(os.getcwd(), ini_file))
|
467
|
-
if not os.path.exists(ini_file):
|
468
|
-
_print(f"The INI file required for --load is not found: {ini_file}")
|
469
|
-
exit(1)
|
470
|
-
|
454
|
+
if not portal.vapp:
|
455
|
+
_print("Must using INI based Portal object with --load (use --ini option to specify an INI file).")
|
456
|
+
return False
|
471
457
|
if not os.path.isabs(load := os.path.normpath(os.path.expanduser(load))):
|
472
458
|
load = os.path.normpath(os.path.join(os.getcwd(), load))
|
473
459
|
if not os.path.exists(load):
|
@@ -480,10 +466,6 @@ def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = N
|
|
480
466
|
inserts_directory = None
|
481
467
|
inserts_file = load
|
482
468
|
|
483
|
-
if not (portal := _portal):
|
484
|
-
with captured_output(not debug):
|
485
|
-
portal = Portal(ini_file)
|
486
|
-
|
487
469
|
if inserts_file:
|
488
470
|
with io.open(inserts_file, "r") as f:
|
489
471
|
try:
|
@@ -503,9 +485,9 @@ def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = N
|
|
503
485
|
file_name = os.path.join(tmpdir, f"{to_snake_case(schema_name)}.json")
|
504
486
|
with io.open(file_name, "w") as f:
|
505
487
|
json.dump(data, f)
|
506
|
-
return _load_data(load=tmpdir, ini_file=ini_file, explicit_schema_name=schema_name,
|
488
|
+
return _load_data(portal=portal, load=tmpdir, ini_file=ini_file, explicit_schema_name=schema_name,
|
507
489
|
verbose=verbose, debug=debug, noprogress=noprogress,
|
508
|
-
|
490
|
+
_single_insert_file=inserts_file)
|
509
491
|
elif isinstance(data, dict):
|
510
492
|
if schema_name := explicit_schema_name:
|
511
493
|
if _is_schema_name_list(portal, schema_names := list(data.keys())):
|
@@ -530,20 +512,20 @@ def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = N
|
|
530
512
|
json.dump(schema_data, f)
|
531
513
|
nfiles += 1
|
532
514
|
if nfiles > 0:
|
533
|
-
return _load_data(load=tmpdir, ini_file=ini_file,
|
515
|
+
return _load_data(portal=portal, load=tmpdir, ini_file=ini_file,
|
534
516
|
verbose=verbose, debug=debug, noprogress=noprogress,
|
535
|
-
|
517
|
+
_single_insert_file=inserts_file)
|
536
518
|
return True
|
537
519
|
else:
|
538
520
|
_print(f"Unrecognized JSON data in file: {inserts_file}")
|
539
521
|
return False
|
540
522
|
return True
|
523
|
+
|
541
524
|
if verbose:
|
542
525
|
if _single_insert_file:
|
543
526
|
_print(f"Loading data into Portal (via snovault.loadxl) from file: {_single_insert_file}")
|
544
527
|
else:
|
545
528
|
_print(f"Loading data into Portal (via snovault.loadxl) from directory: {inserts_directory}")
|
546
|
-
_print(f"Portal INI file for load is: {ini_file}")
|
547
529
|
|
548
530
|
schema_names = list(_get_schemas(portal).keys())
|
549
531
|
schema_snake_case_names = [to_snake_case(item) for item in schema_names]
|
@@ -585,11 +567,15 @@ def _load_data(load: str, ini_file: str, explicit_schema_name: Optional[str] = N
|
|
585
567
|
loadxl(portal=portal, inserts_directory=tmpdir, schema_names_to_load=schema_names_to_load)
|
586
568
|
else:
|
587
569
|
loadxl(portal=portal, inserts_directory=inserts_directory, schema_names_to_load=schema_names_to_load)
|
570
|
+
|
588
571
|
if verbose:
|
589
572
|
if _single_insert_file:
|
590
573
|
_print(f"Done loading data into Portal (via snovault.loadxl) from file: {_single_insert_file}")
|
591
574
|
else:
|
592
575
|
_print(f"Done loading data into Portal (via snovault.loadxl) from directory: {inserts_directory}")
|
576
|
+
for item in sorted(loadxl_summary.keys()):
|
577
|
+
_print(f"▷ {to_camel_case(item)}: {loadxl_summary[item]}")
|
578
|
+
|
593
579
|
return True
|
594
580
|
|
595
581
|
|
@@ -611,25 +597,67 @@ def _prune_data_for_update(data: dict, noignore: bool = False, ignore: Optional[
|
|
611
597
|
return {key: value for key, value in data.items() if key not in ignore_these_properties}
|
612
598
|
|
613
599
|
|
614
|
-
def _create_portal(env: Optional[str] = None, app: Optional[str] = None,
|
615
|
-
verbose: bool = False, debug: bool = False
|
600
|
+
def _create_portal(env: Optional[str] = None, ini: Optional[str] = None, app: Optional[str] = None,
|
601
|
+
load: Optional[str] = None, verbose: bool = False, debug: bool = False,
|
602
|
+
quiet: bool = False) -> Optional[Portal]:
|
603
|
+
|
604
|
+
if app:
|
605
|
+
if (app not in ORCHESTRATED_APPS) and ((app := app.lower()) not in ORCHESTRATED_APPS):
|
606
|
+
_print(f"Unknown app name; must be one of: {' | '.join(ORCHESTRATED_APPS)}")
|
607
|
+
return None
|
608
|
+
elif APP_SMAHT in (env or os.environ.get(_SMAHT_ENV_ENVIRON_NAME) or ""):
|
609
|
+
app = APP_SMAHT
|
610
|
+
elif APP_CGAP in (env or ""):
|
611
|
+
app = APP_CGAP
|
612
|
+
elif APP_FOURFRONT in (env or ""):
|
613
|
+
app = APP_FOURFRONT
|
614
|
+
|
615
|
+
if ini:
|
616
|
+
if env:
|
617
|
+
if not quiet:
|
618
|
+
_print("Ignoring --env option when --ini option is given.")
|
619
|
+
elif (app == _SMAHT_ENV_ENVIRON_NAME) and (env := os.environ.get(_SMAHT_ENV_ENVIRON_NAME)):
|
620
|
+
if not quiet:
|
621
|
+
_print(f"Ignoring SMAHT_ENV environment variable ({env}) when --ini option is given.")
|
622
|
+
if not os.path.isabs(ini_file := os.path.normpath(os.path.expanduser(ini))):
|
623
|
+
ini_file = os.path.normpath(os.path.join(os.getcwd(), ini_file))
|
624
|
+
if not os.path.exists(ini_file):
|
625
|
+
_print(f"Specified Portal INI file not found: {ini_file}")
|
626
|
+
return None
|
627
|
+
with captured_output(not debug):
|
628
|
+
if not (portal := Portal(ini_file, app=app)):
|
629
|
+
_print(f"Cannot create INI based Portal object: {env} ({app})")
|
630
|
+
return None
|
631
|
+
else:
|
632
|
+
env_from_environ = False
|
633
|
+
if not env and app:
|
634
|
+
# If the --load option is specified, and no --ini option is specified, then do NOT default
|
635
|
+
# to using the SMAHT_ENV environment variable (if set) for an access-key based Portal
|
636
|
+
# object; rather default to the default INI file (i.e. development.ini).
|
637
|
+
if (not load) and (app == APP_SMAHT) and (env := os.environ.get(_SMAHT_ENV_ENVIRON_NAME)):
|
638
|
+
env_from_environ = True
|
639
|
+
if not env:
|
640
|
+
if os.path.exists(ini_file := os.path.normpath(os.path.join(os.getcwd(), _DEFAULT_INI_FILE_FOR_LOAD))):
|
641
|
+
return _create_portal(ini=ini_file, app=app, verbose=verbose, debug=debug)
|
642
|
+
return None
|
643
|
+
if not (portal := Portal(env, app=app) if env or app else None):
|
644
|
+
_print(f"Cannot create access-key based Portal object: {env}{f' ({app})' if app else ''}")
|
645
|
+
return None
|
646
|
+
|
647
|
+
if (ini_file := portal.ini_file):
|
648
|
+
if not quiet:
|
649
|
+
_print(f"Portal environment: {ini_file}")
|
650
|
+
elif (env := portal.env) or (env := os.environ.get(_SMAHT_ENV_ENVIRON_NAME)):
|
651
|
+
_print(f"Portal environment"
|
652
|
+
f"{f' (from {_SMAHT_ENV_ENVIRON_NAME})' if env_from_environ else ''}: {portal.env}")
|
653
|
+
if verbose:
|
654
|
+
if portal.keys_file:
|
655
|
+
_print(f"Portal keys file: {portal.keys_file}")
|
656
|
+
if portal.key_id:
|
657
|
+
_print(f"Portal key prefix: {portal.key_id[0:2]}******")
|
658
|
+
if portal.server:
|
659
|
+
_print(f"Portal server: {portal.server}")
|
616
660
|
|
617
|
-
env_from_environ = None
|
618
|
-
if not env and (app == APP_SMAHT):
|
619
|
-
if env := os.environ.get(_SMAHT_ENV_ENVIRON_NAME):
|
620
|
-
env_from_environ = True
|
621
|
-
if not (portal := Portal(env, app=app) if env or app else None):
|
622
|
-
return None
|
623
|
-
if verbose:
|
624
|
-
if (env := portal.env) or (env := os.environ(_SMAHT_ENV_ENVIRON_NAME)):
|
625
|
-
_print(f"Portal environment"
|
626
|
-
f"{f' (from {_SMAHT_ENV_ENVIRON_NAME})' if env_from_environ else ''}: {portal.env}")
|
627
|
-
if portal.keys_file:
|
628
|
-
_print(f"Portal keys file: {portal.keys_file}")
|
629
|
-
if portal.key_id:
|
630
|
-
_print(f"Portal key prefix: {portal.key_id[0:2]}******")
|
631
|
-
if portal.server:
|
632
|
-
_print(f"Portal server: {portal.server}")
|
633
661
|
return portal
|
634
662
|
|
635
663
|
|
@@ -60,7 +60,7 @@ 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=
|
63
|
+
dcicutils/scripts/update_portal_object.py,sha256=lRF40toLSGjqlbeHDxKIyx2XaasLKEmvSn_ZnCpKm_A,35566
|
64
64
|
dcicutils/scripts/view_portal_object.py,sha256=lcgXWH9ooVf7tJDIRnoFGOgT0wYLGhiJlJW3a9w6A_c,36983
|
65
65
|
dcicutils/secrets_utils.py,sha256=8dppXAsiHhJzI6NmOcvJV5ldvKkQZzh3Fl-cb8Wm7MI,19745
|
66
66
|
dcicutils/sheet_utils.py,sha256=VlmzteONW5VF_Q4vo0yA5vesz1ViUah1MZ_yA1rwZ0M,33629
|
@@ -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.1b16.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
79
|
+
dcicutils-8.14.0.1b16.dist-info/METADATA,sha256=9KI830ZNINFtzrJ1PCSrGZG6UB_zOjnvTeRU0cmlJhk,3440
|
80
|
+
dcicutils-8.14.0.1b16.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
81
|
+
dcicutils-8.14.0.1b16.dist-info/entry_points.txt,sha256=W6kEWdUJk9tQ4myAgpehPdebcwvCAZ7UgB-wyPgDUMg,335
|
82
|
+
dcicutils-8.14.0.1b16.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|