Added option for plinth --setup

Now plinth --setup could take a list of modules to setup
This commit is contained in:
Hemanth Kumar Veeranki 2016-07-30 16:18:13 +05:30 committed by Sunil Mohan Adapa
parent 1414db64bf
commit 60e808e9bb
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971
2 changed files with 15 additions and 8 deletions

View File

@ -53,7 +53,7 @@ def parse_arguments():
'--debug', action='store_true', default=cfg.debug,
help='enable debugging and run server *insecurely*')
parser.add_argument(
'--setup', action='store_true', default=False,
'--setup', default=False, nargs='*',
help='run setup tasks on all essential modules and exit')
parser.add_argument(
'--diagnose', action='store_true', default=False,
@ -248,11 +248,14 @@ def configure_django():
os.chmod(cfg.store_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
def run_setup_and_exit():
def run_setup_and_exit(module_list):
"""Run setup on all essential modules and exit."""
error_code = 0
try:
setup.setup_all_modules(essential=True)
if not module_list:
setup.setup_modules(essential=True)
else:
setup.setup_modules(module_list)
except Exception as exception:
logger.error('Error running setup - %s', exception)
error_code = 1
@ -297,8 +300,8 @@ def main():
module_loader.load_modules()
if arguments.setup:
run_setup_and_exit()
if arguments.setup is not None:
run_setup_and_exit(arguments.setup)
if arguments.diagnose:
run_diagnostics_and_exit()

View File

@ -150,11 +150,15 @@ def init(module_name, module):
module.setup_helper = Helper(module_name, module)
def setup_all_modules(essential=False):
"""Run setup on all essential modules and exit."""
logger.info('Running setup for all modules, essential - %s', essential)
def setup_modules(module_list=None, essential=False):
"""Run setup on selected or essential modules."""
logger.info('Running setup for modules, essential - %s, '
'selected modules - %s', essential, module_list)
for module_name, module in plinth.module_loader.loaded_modules.items():
if essential and not getattr(module, 'is_essential', False):
continue
if module_list and module_name not in module_list:
continue
module.setup_helper.run()