Skip to content

Commit 1f518d1

Browse files
committed
Merge branch 'dev'
2 parents c9c9d85 + f1d0822 commit 1f518d1

File tree

15 files changed

+1059
-618
lines changed

15 files changed

+1059
-618
lines changed

cravat/admin_util.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,10 @@ def get_system_conf(file_only=False):
916916
conf[constants.save_metrics_key] = constants.default_save_metrics
917917
if constants.metrics_url_key not in conf:
918918
conf[constants.metrics_url_key] = constants.default_metrics_url
919+
if constants.user_email_key not in conf:
920+
conf[constants.user_email_key] = constants.default_user_email
921+
if constants.user_email_opt_out_key not in conf:
922+
conf[constants.user_email_opt_out_key] = constants.default_user_email_opt_out
919923
if "custom_system_conf" in globals():
920924
global custom_system_conf
921925
for k, v in custom_system_conf.items():
@@ -1615,6 +1619,60 @@ def set_modules_dir(path, overwrite=False):
16151619
overwrite_conf_path = get_main_default_path()
16161620
shutil.copy(overwrite_conf_path, get_main_conf_path())
16171621

1622+
1623+
def request_user_email(args):
1624+
if not sys.stdin.isatty():
1625+
return
1626+
1627+
conf = get_system_conf()
1628+
if constants.user_email_opt_out_key in conf and conf[constants.user_email_opt_out_key] is True:
1629+
return
1630+
if constants.user_email_key in conf and conf[constants.user_email_key] is not None and conf[constants.user_email_key] != constants.default_user_email:
1631+
return
1632+
if args.user_email_opt_out is True:
1633+
update = {
1634+
constants.user_email_key: constants.default_user_email,
1635+
constants.user_email_opt_out_key: True
1636+
}
1637+
update_system_conf_file(update)
1638+
return
1639+
# if publish_username is stored, copy it for the user email
1640+
if 'publish_username' in conf:
1641+
update = {
1642+
constants.user_email_key: conf['publish_username'],
1643+
constants.user_email_opt_out_key: False
1644+
}
1645+
update_system_conf_file(update)
1646+
return
1647+
if args.user_email is not None and args.user_email != constants.default_user_email:
1648+
update = {
1649+
constants.user_email_key: args.user_email,
1650+
constants.user_email_opt_out_key: False
1651+
}
1652+
update_system_conf_file(update)
1653+
return
1654+
1655+
email = input('Please provide your email to support our funding.\n'
1656+
'\t* Used only for usage metrics.\n'
1657+
'\t* No third-party sharing.\n'
1658+
'\t* No mailing lists without consent\n'
1659+
"Enter 'No' or 'Opt Out' to opt out of providing an email address.\n> ")
1660+
opt_outs = ('n', 'no', 'optout', 'opt out', 'opt_out', 'opt-out')
1661+
if email.lower() in opt_outs:
1662+
update = {
1663+
constants.user_email_key: constants.default_user_email,
1664+
constants.user_email_opt_out_key: True
1665+
}
1666+
update_system_conf_file(update)
1667+
print('You can update your email preferences by editing the OpenCravat system configuration.')
1668+
return
1669+
update = {
1670+
constants.user_email_key: email,
1671+
constants.user_email_opt_out_key: False
1672+
}
1673+
update_system_conf_file(update)
1674+
print('You can update your email preferences by editing the OpenCravat system configuration.')
1675+
16181676
def set_metrics_config(value, overwrite=False):
16191677
"""
16201678
Set the save_metrics configuration in the system conf file.

cravat/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
metrics_url_key = 'metrics_url'
117117
default_metrics_url = 'https://metrics.opencravat.org'
118118

119+
# user email
120+
user_email_key = 'user_email'
121+
user_email_opt_out_key = 'user_email_opt_out'
122+
default_user_email = ''
123+
default_user_email_opt_out = False
124+
119125
# liftover
120126
liftover_chains_dir = os.path.join(packagedir, "liftover")
121127
liftover_chain_paths = {

cravat/cravat_admin.py

Lines changed: 96 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ def publish_module (args):
407407
args.password = getpass()
408408
au.publish_module(args.module, args.user, args.password, overwrite=args.overwrite, include_data=args.data)
409409

410+
411+
410412
def install_base (args):
411413
args = SimpleNamespace(modules=constants.base_modules,
412414
force_data=args.force_data,
@@ -417,8 +419,11 @@ def install_base (args):
417419
force=args.force,
418420
skip_data=False,
419421
install_pypi_dependency=args.install_pypi_dependency,
420-
md=args.md
422+
md=args.md,
423+
user_email=args.user_email,
424+
user_email_opt_out=args.user_email_opt_out
421425
)
426+
au.request_user_email(args)
422427
install_modules(args)
423428

424429
def create_account (args):
@@ -535,119 +540,128 @@ def show_version (args):
535540
default=None,
536541
help='Specify the root directory of OpenCRAVAT modules'
537542
)
543+
parser_install_base.add_argument('--user-email',
544+
dest='user_email',
545+
help='User email for OpenCravat metrics'
546+
)
547+
parser_install_base.add_argument('--user-email-opt-out',
548+
dest='user_email_opt_out',
549+
action='store_true',
550+
help='Opt out of providing a user email for OpenCravat metrics'
551+
)
538552
parser_install_base.set_defaults(func=install_base)
539553

540554
# install
541555
parser_install = subparsers.add_parser('install',
542-
help='installs modules.',
543-
description='installs modules.')
556+
help='installs modules.',
557+
description='installs modules.')
544558
parser_install.add_argument('modules',
545-
nargs='+',
546-
help='Modules to install. May be regular expressions.'
559+
nargs='+',
560+
help='Modules to install. May be regular expressions.'
547561
)
548562
parser_install.add_argument('-v','--version',
549-
help='Install a specific version'
563+
help='Install a specific version'
550564
)
551565
parser_install.add_argument('-f','--force',
552-
action='store_true',
553-
help='Install module even if latest version is already installed',
566+
action='store_true',
567+
help='Install module even if latest version is already installed',
554568
)
555569
parser_install.add_argument('-d', '--force-data',
556-
action='store_true',
557-
help='Download data even if latest data is already installed'
570+
action='store_true',
571+
help='Download data even if latest data is already installed'
558572
)
559573
parser_install.add_argument('-y','--yes',
560-
action='store_true',
561-
help='Proceed without prompt'
574+
action='store_true',
575+
help='Proceed without prompt'
562576
)
563577
parser_install.add_argument('--skip-dependencies',
564-
action='store_true',
565-
help='Skip installing dependencies'
578+
action='store_true',
579+
help='Skip installing dependencies'
566580
)
567581
parser_install.add_argument('-p','--private',
568-
action='store_true',
569-
help='Install a private module'
582+
action='store_true',
583+
help='Install a private module'
570584
)
571585
parser_install.add_argument('--skip-data',
572-
action='store_true',
573-
help='Skip installing data'
586+
action='store_true',
587+
help='Skip installing data'
574588
)
575589
parser_install.add_argument('--install-pypi-dependency',
576-
action='store_true',
577-
default=True,
578-
help='Try to install non-OpenCRAVAT package dependency with pip'
590+
action='store_true',
591+
default=True,
592+
help='Try to install non-OpenCRAVAT package dependency with pip'
579593
)
580594
parser_install.add_argument('--md',
581-
default=None,
582-
help='Specify the root directory of OpenCRAVAT modules'
595+
default=None,
596+
help='Specify the root directory of OpenCRAVAT modules'
583597
)
584598
parser_install.set_defaults(func=install_modules)
585599

586600
# update
587601
update_examples = ExampleCommandsFormatter(prefix='cravat-admin update')
588602
update_examples.add_example('',
589-
'''Enter an interactive update process. Cravat
590-
will check to see which modules need to
591-
be updated, and will ask you if you wish to update them.''')
603+
'''Enter an interactive update process. Cravat
604+
will check to see which modules need to
605+
be updated, and will ask you if you wish to update them.''')
592606
update_examples.add_example('hg38 aggregator vcf-converter',
593-
'''Only attempt update on the hg38, aggregator,
594-
and vcf-converter modules.''')
607+
'''Only attempt update on the hg38, aggregator,
608+
and vcf-converter modules.''')
595609
parser_update = subparsers.add_parser('update',
596-
help='updates modules.',
597-
description='updates modules.',
598-
epilog=str(update_examples),
599-
formatter_class=argparse.RawDescriptionHelpFormatter)
610+
help='updates modules.',
611+
description='updates modules.',
612+
epilog=str(update_examples),
613+
formatter_class=argparse.RawDescriptionHelpFormatter)
600614
parser_update.add_argument('modules',
601-
nargs='*',
602-
help='Modules to update.')
615+
nargs='*',
616+
help='Modules to update.')
603617
parser_update.add_argument('-y',
604-
action='store_true',
605-
help='Proceed without prompt'
606-
)
618+
action='store_true',
619+
help='Proceed without prompt'
620+
)
607621
parser_update.add_argument('--strategy',
608-
help='Dependency resolution strategy. "consensus" will attemp to resolve dependencies. "force" will install the highest available version. "skip" will skip modules with constraints.',
609-
default='consensus',
610-
type=str,
611-
choices=('consensus','force','skip')
612-
)
622+
help='Dependency resolution strategy. "consensus" will attemp to resolve dependencies. "force" will install the highest available version. "skip" will skip modules with constraints.',
623+
default='consensus',
624+
type=str,
625+
choices=('consensus','force','skip')
626+
)
613627
parser_update.add_argument('--install-pypi-dependency',
614-
action='store_true',
615-
default=True,
616-
help='Try to install non-OpenCRAVAT package dependency with pip'
628+
action='store_true',
629+
default=True,
630+
help='Try to install non-OpenCRAVAT package dependency with pip'
617631
)
618632
parser_update.add_argument('--md',
619-
default=None,
620-
help='Specify the root directory of OpenCRAVAT modules'
633+
default=None,
634+
help='Specify the root directory of OpenCRAVAT modules'
621635
)
622636
parser_update.set_defaults(func=update_modules)
623637

624638
# uninstall
625639
parser_uninstall = subparsers.add_parser('uninstall',
626-
help='uninstalls modules.')
640+
help='uninstalls modules.')
627641
parser_uninstall.add_argument('modules',
628-
nargs='+',
629-
help='Modules to uninstall')
642+
nargs='+',
643+
help='Modules to uninstall')
630644
parser_uninstall.add_argument('-y','--yes',
631-
action='store_true',
632-
help='Proceed without prompt')
645+
action='store_true',
646+
help='Proceed without prompt')
633647
parser_uninstall.add_argument('--md',
634-
default=None,
635-
help='Specify the root directory of OpenCRAVAT modules'
648+
default=None,
649+
help='Specify the root directory of OpenCRAVAT modules'
636650
)
637651
parser_uninstall.set_defaults(func=uninstall_modules)
638652

639653
# info
640654
parser_info = subparsers.add_parser('info',
641-
help='shows module information.')
655+
help='shows module information.')
642656
parser_info.add_argument('module',
643-
help='Module to get info about')
657+
help='Module to get info about')
644658
parser_info.add_argument('-l','--local',
645-
dest='local',
646-
help='Include local info',
647-
action='store_true')
659+
dest='local',
660+
help='Include local info',
661+
action='store_true')
648662
parser_info.add_argument('--md',
649-
default=None,
650-
help='Specify the root directory of OpenCRAVAT modules'
663+
default=None,
664+
help='Specify the root directory of OpenCRAVAT modules'
651665
)
652666
parser_info.set_defaults(func=print_info)
653667

@@ -658,35 +672,35 @@ def show_version (args):
658672
ls_examples.add_example('-a', 'List all modules available on the store')
659673
ls_examples.add_example('-a -t mapper', 'List all mappers available on the store')
660674
parser_ls = subparsers.add_parser('ls',
661-
help='lists modules.',
662-
description='lists modules.',
663-
epilog=str(ls_examples),
664-
formatter_class=argparse.RawDescriptionHelpFormatter)
675+
help='lists modules.',
676+
description='lists modules.',
677+
epilog=str(ls_examples),
678+
formatter_class=argparse.RawDescriptionHelpFormatter)
665679
parser_ls.add_argument('pattern',
666-
nargs='?',
667-
default=r'.*',
668-
help='Regular expression for module names')
680+
nargs='?',
681+
default=r'.*',
682+
help='Regular expression for module names')
669683
parser_ls.add_argument('-a','--available',
670-
action='store_true',
671-
help='Include available modules')
684+
action='store_true',
685+
help='Include available modules')
672686
parser_ls.add_argument('-t','--types',
673-
nargs='+',
674-
default=[],
675-
help='Only list modules of certain types')
687+
nargs='+',
688+
default=[],
689+
help='Only list modules of certain types')
676690
parser_ls.add_argument('-i','--include-hidden',
677-
action='store_true',
678-
help='Include hidden modules')
691+
action='store_true',
692+
help='Include hidden modules')
679693
parser_ls.add_argument('--tags',
680-
nargs='+',
681-
default=[],
682-
help='Only list modules of given tag(s)'
694+
nargs='+',
695+
default=[],
696+
help='Only list modules of given tag(s)'
683697
)
684698
parser_ls.add_argument('-q','--quiet',
685-
action='store_true',
686-
help='Only list module names')
699+
action='store_true',
700+
help='Only list module names')
687701
parser_ls.add_argument('--bytes',
688-
action='store_true',
689-
dest='raw_bytes',
702+
action='store_true',
703+
dest='raw_bytes',
690704
help='Machine readable data sizes'
691705
)
692706
parser_ls.add_argument('--md',

cravat/cravat_class.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@
269269
nargs="*",
270270
help="System option in key=value syntax. For example, --system-option modules_dir=/home/user/open-cravat/modules",
271271
)
272+
cravat_cmd_parser.add_argument(
273+
"--user-email",
274+
dest="user_email",
275+
help="User email for OpenCravat metrics",
276+
)
277+
cravat_cmd_parser.add_argument(
278+
"--user-email-opt-out",
279+
dest="user_email_opt_out",
280+
default=False,
281+
action="store_true",
282+
help="Opt out of providing an email for OpenCravat metrics",
283+
)
272284
cravat_cmd_parser.add_argument(
273285
"--silent", dest="silent", action="store_true", default=None, help="Runs silently."
274286
)
@@ -294,6 +306,7 @@
294306
def run(cmd_args):
295307
au.ready_resolution_console()
296308
module = Cravat(**vars(cmd_args))
309+
au.request_user_email(module.args)
297310
loop = asyncio.get_event_loop()
298311
response = loop.run_until_complete(module.main())
299312
return response

cravat/cravat_metrics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def __init__(self):
2727
self.gather_machine_data()
2828

2929
def gather_machine_data(self):
30+
sys_conf = au.get_system_conf()
31+
self.machinedata['userEmail'] = sys_conf.get(constants.user_email_key)
32+
self.machinedata['userEmailOptOut'] = sys_conf.get(constants.user_email_opt_out_key)
3033
self.machinedata['OS'] = platform.system()
3134
self.machinedata['OSVersion'] = platform.release()
3235
self.machinedata['totalMemory'] = psutil.virtual_memory().total

0 commit comments

Comments
 (0)