From e09018fe9af6f362dd655595a57c0e03c08a0d0a Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 8 Mar 2015 21:34:53 +0530 Subject: [PATCH] Fix issues with configuration/parameters loading - Change default server directory from plinth/ to /plinth as the program expects. - First load the values from configuration file and then override them with command line parameters. - Show default values on the command line help. - Use configuration file values as default values to command line parameters. - Log the value of script prefix (server_dir) for easy debugging. - Make sure the server_dir is properly loaded from configuration files. --- data/etc/plinth/plinth.config | 2 +- plinth/__main__.py | 16 +++++++++------- plinth/cfg.py | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/data/etc/plinth/plinth.config b/data/etc/plinth/plinth.config index 1ec6846a3..356cd3feb 100644 --- a/data/etc/plinth/plinth.config +++ b/data/etc/plinth/plinth.config @@ -9,7 +9,7 @@ config_dir = /etc/plinth data_dir = /var/lib/plinth log_dir = /var/log/plinth pid_dir = /var/run -server_dir = plinth/ +server_dir = /plinth actions_dir = /usr/share/plinth/actions doc_dir = /usr/share/doc/plinth diff --git a/plinth/__main__.py b/plinth/__main__.py index dae4fb278..7ceacca80 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -40,19 +40,20 @@ LOGGER = logging.getLogger(__name__) def parse_arguments(): """Parse command line arguments""" parser = argparse.ArgumentParser( - description='Plinth web interface for FreedomBox') + description='Plinth web interface for FreedomBox', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( - '--pidfile', default='plinth.pid', + '--pidfile', default=cfg.pidfile, help='specify a file in which the server may write its pid') # TODO: server_dir is actually a url prefix; use a better variable name parser.add_argument( - '--server_dir', default='/', + '--server_dir', default=cfg.server_dir, help='web server path under which to serve') parser.add_argument( - '--debug', action='store_true', default=False, + '--debug', action='store_true', default=cfg.debug, help='enable debugging and run server *insecurely*') parser.add_argument( - '--no-daemon', action='store_true', default=False, + '--no-daemon', action='store_true', default=cfg.no_daemon, help='do not start as a daemon') args = parser.parse_args() @@ -239,10 +240,10 @@ def configure_django(): def main(): """Intialize and start the application""" - parse_arguments() - cfg.read() + parse_arguments() + setup_logging() service.init() @@ -250,6 +251,7 @@ def main(): configure_django() LOGGER.info('Configuration loaded from file - %s', cfg.CONFIG_FILE) + LOGGER.info('Script prefix - %s', cfg.server_dir) module_loader.load_modules() diff --git a/plinth/cfg.py b/plinth/cfg.py index 0d1e467cb..70d51e53c 100644 --- a/plinth/cfg.py +++ b/plinth/cfg.py @@ -78,6 +78,7 @@ def read(): ('Path', 'status_log_file'), ('Path', 'access_log_file'), ('Path', 'pidfile'), + ('Path', 'server_dir'), ('Network', 'host'), ('Network', 'port'), ('Network', 'secure_proxy_ssl_header'),