Skip to content
Snippets Groups Projects
Unverified Commit 01136333 authored by Feanil Patel's avatar Feanil Patel Committed by GitHub
Browse files

Merge pull request #24818 from edly-io/zubair/BD-18-optimize-paver-settings-call

[BD-18] Optimize paver settings call
parents 66297177 169b8226
No related branches found
Tags release-2021-06-07-11.14
No related merge requests found
......@@ -22,14 +22,15 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
'setting',
help='Specifies the setting to be printed.'
'settings_to_print',
nargs='+',
help='Specifies the list of settings to be printed.'
)
def handle(self, *args, **options):
setting = options.get('setting')
settings_to_print = options.get('settings_to_print')
if not hasattr(settings, setting):
raise CommandError(u'%s not found in settings.' % setting)
print(getattr(settings, setting))
for setting in settings_to_print:
if not hasattr(settings, setting):
raise CommandError('%s not found in settings.' % setting)
print(getattr(settings, setting))
......@@ -762,9 +762,9 @@ def webpack(options):
Run a Webpack build.
"""
settings = getattr(options, 'settings', Env.DEVSTACK_SETTINGS)
static_root_lms = Env.get_django_setting("STATIC_ROOT", "lms", settings=settings)
static_root_cms = Env.get_django_setting("STATIC_ROOT", "cms", settings=settings)
config_path = Env.get_django_setting("WEBPACK_CONFIG_PATH", "lms", settings=settings)
result = Env.get_django_settings(['STATIC_ROOT', 'WEBPACK_CONFIG_PATH'], "lms", settings=settings)
static_root_lms, config_path = result
static_root_cms, = Env.get_django_settings(["STATIC_ROOT"], "cms", settings=settings)
environment = 'NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms}'.format(
node_env="development" if config_path == 'webpack.dev.config.js' else "production",
static_root_lms=static_root_lms,
......@@ -787,13 +787,17 @@ def execute_webpack_watch(settings=None):
# We only want Webpack to re-run on changes to its own entry points,
# not all JS files, so we use its own watcher instead of subclassing
# from Watchdog like the other watchers do.
result = Env.get_django_settings(["STATIC_ROOT", "WEBPACK_CONFIG_PATH"], "lms", settings=settings)
static_root_lms, config_path = result
static_root_cms, = Env.get_django_settings(["STATIC_ROOT"], "cms", settings=settings)
run_background_process(
'STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm bin)/webpack {options}'.format(
options='--watch --config={config_path}'.format(
config_path=Env.get_django_setting("WEBPACK_CONFIG_PATH", "lms", settings=settings)
config_path=config_path
),
static_root_lms=Env.get_django_setting("STATIC_ROOT", "lms", settings=settings),
static_root_cms=Env.get_django_setting("STATIC_ROOT", "cms", settings=settings),
static_root_lms=static_root_lms,
static_root_cms=static_root_cms,
)
)
......
......@@ -44,9 +44,8 @@ EXPECTED_INDEX_COURSE_COMMAND = (
"python manage.py {system} --settings={settings} reindex_course --setup"
)
EXPECTED_PRINT_SETTINGS_COMMAND = [
"python manage.py lms --settings={settings} print_setting STATIC_ROOT 2>{log_file}",
"python manage.py cms --settings={settings} print_setting STATIC_ROOT 2>{log_file}",
"python manage.py lms --settings={settings} print_setting WEBPACK_CONFIG_PATH 2>{log_file}"
"python manage.py lms --settings={settings} print_setting STATIC_ROOT WEBPACK_CONFIG_PATH 2>{log_file}",
"python manage.py cms --settings={settings} print_setting STATIC_ROOT 2>{log_file}"
]
EXPECTED_WEBPACK_COMMAND = (
"NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} "
......
......@@ -236,10 +236,10 @@ class Env:
SERVICE_VARIANT = 'lms'
@classmethod
def get_django_setting(cls, django_setting, system, settings=None):
def get_django_settings(cls, django_settings, system, settings=None):
"""
Interrogate Django environment for specific settings values
:param django_setting: the django setting to get
:param django_settings: list of django settings values to get
:param system: the django app to use when asking for the setting (lms | cms)
:param settings: the settings file to use when asking for the value
:return: unicode value of the django setting
......@@ -249,21 +249,24 @@ class Env:
log_dir = os.path.dirname(cls.PRINT_SETTINGS_LOG_FILE)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
settings_length = len(django_settings)
django_settings = ' '.join(django_settings) # parse_known_args makes a list again
try:
value = sh(
django_cmd(
system,
settings,
"print_setting {django_setting} 2>{log_file}".format(
django_setting=django_setting,
"print_setting {django_settings} 2>{log_file}".format(
django_settings=django_settings,
log_file=cls.PRINT_SETTINGS_LOG_FILE
)
),
capture=True
)
return str(value).strip()
# else for cases where values are not found & sh returns one None value
return tuple(str(value).splitlines()) if value else tuple(None for _ in range(settings_length))
except BuildFailure:
print("Unable to print the value of the {} setting:".format(django_setting))
print("Unable to print the value of the {} setting:".format(django_settings))
with open(cls.PRINT_SETTINGS_LOG_FILE, 'r') as f:
print(f.read())
sys.exit(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment