Source code for schrodinger.utils.postinstall
"""
This file contains post-installation steps common to all platforms.
This allows post installation steps to be tested and used in and outside
the installers. Migrate more post-installation steps here in the future.
"""
import argparse
import glob
import os
import shutil
import sys
from . import installation_check
from . import mmutil
STEP_ARG = 'step'
STEP_COPY_FEATUREFLAGS = 'copy-featureflags'
[docs]def copy_featureflags(featureflags_dir):
'''
Checks the specified directory for a featureflags.json and deploys it to
$SCHRODINGER/config.
:type featureflags_dir: str
:param featureflags_dir: path to the directory where the custom
featureflags.json is located
'''
file_name = 'featureflags.json'
source_file = os.path.join(featureflags_dir, file_name)
target_file = mmutil.get_feature_flags_site_state_file()
if not os.path.isfile(source_file):
print(f'No custom feature flags found in {source_file}, using defaults')
return
# Ensure that config directory exists
os.makedirs(os.path.dirname(target_file), exist_ok=True)
shutil.copy(source_file, target_file)
[docs]def get_lib_dir():
# Don't use hunt because we are getting rid of and it requires feature
# flags which requires licenses
return glob.glob(os.environ["SCHRODINGER"] + "/mmshare-v*/lib/*")[0]
[docs]def create_config_dir():
"""
Create $SCHRODINGER/config
"""
target_directory = mmutil.mmfile_get_config_dir()
os.makedirs(target_directory, exist_ok=True)
[docs]def get_disabled_lib_dir():
lib_directory = get_lib_dir()
deconstructed_path = lib_directory.split(os.path.sep)
deconstructed_path[-2] = "disabled_lib"
disabled_lib_directory = os.path.sep.join(deconstructed_path)
return disabled_lib_directory
[docs]def should_copy_featureflags(args):
if STEP_ARG not in args:
return False
return getattr(args, STEP_ARG) == STEP_COPY_FEATUREFLAGS
[docs]def parse_args(argv=None):
parser = argparse.ArgumentParser(__doc__)
# Add common parameters here
subparsers = parser.add_subparsers(
dest=STEP_ARG,
help='steps',
description='available post-installation steps')
# Subcommands
featureflags_parser = subparsers.add_parser(
STEP_COPY_FEATUREFLAGS, help='deploy custom featureflags')
featureflags_parser.add_argument(
'featureflags_dir',
help='Directory where the custom featureflags.json file is located.')
return parser.parse_args(argv)
[docs]def main(argv=None):
args = parse_args(argv)
create_config_dir()
if should_copy_featureflags(args):
copy_featureflags(args.featureflags_dir)
return args
if __name__ == '__main__':
main()