Merge ./run --debug into --develop option

Signed-off-by: Michael Pimmer <info@fonfon.at>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Michael Pimmer 2018-06-13 02:26:44 +00:00 committed by James Valleroy
parent b0e09736d0
commit 00ac068133
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
5 changed files with 32 additions and 43 deletions

View File

@ -68,13 +68,16 @@ However, for some reason, you wish setup manually, the following tips will help:
as possible). Simply run it as: as possible). Simply run it as:
``` ```
$ sudo ./run --debug --develop $ sudo ./run --develop
``` ```
In this mode, FreedomBox Service (Plinth) runs in working directory without In this mode, FreedomBox Service (Plinth) runs from the working directory
need for installation. The `plinth.conf` config file and the action without need for installation. The server restarts automatically when any
python file changes. The `plinth.conf` config file and the action
scripts of the working directory are used. It creates all that data and scripts of the working directory are used. It creates all that data and
runtime files in `data/var/*`. runtime files in `data/var/*`.
More extensive debugging is enabled, Django security features are disabled
and module initialization errors will not pass silently.
*Note:* This mode is supported only in a limited manner. The following are *Note:* This mode is supported only in a limited manner. The following are
the unknown issues with it: the unknown issues with it:

View File

@ -38,7 +38,6 @@
<command>plinth</command> <command>plinth</command>
<arg><option>-h, </option><option>--help</option></arg> <arg><option>-h, </option><option>--help</option></arg>
<arg><option>--server_dir</option><arg choice="req">SERVER_DIR</arg></arg> <arg><option>--server_dir</option><arg choice="req">SERVER_DIR</arg></arg>
<arg><option>--debug</option></arg>
<arg><option>--develop</option></arg> <arg><option>--develop</option></arg>
<arg><option>--diagnose</option></arg> <arg><option>--diagnose</option></arg>
<arg> <arg>
@ -101,25 +100,16 @@
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--debug</option></term>
<listitem>
<para>
Enable debug mode. Turn off Django security features.
Print extra debug messages. Monitor source files for
changes and restart Plinth on modifications. Turn on
Django debug mode to show details on error pages. Die if
there is an error during module initialization.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--develop</option></term> <term><option>--develop</option></term>
<listitem> <listitem>
<para> <para>
Enable development mode. Use plinth.config and the actions_dir Enable development mode. Use plinth.config and the actions_dir
of the current working directory, opposed to the actions_dir of the current working directory. Enables extra debug messages,
and plinth.config file of the operating system installation. enable Django debug mode for detailed error pages and and turn off
Django security features. Monitor source files for changes and
restart Plinth on modifications. Die if there is an error during
module initialization.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@ -222,12 +212,10 @@
<example> <example>
<title>Run Plinth in development mode</title> <title>Run Plinth in development mode</title>
<synopsis>$ plinth --debug --develop</synopsis> <synopsis>$ plinth --develop</synopsis>
<para> <para>
Enable debug and development mode and run on terminal. This uses Run in development mode on the terminal. Enable auto-reloading and
the configuration and action files of the current working directory and more extensive debugging.
gives debugging information like extended error pages, or not failing
silently on module initialization errors.
</para> </para>
</example> </example>
</refsect1> </refsect1>

View File

@ -34,7 +34,7 @@ import cherrypy
from plinth import cfg, menu, module_loader, service, setup from plinth import cfg, menu, module_loader, service, setup
axes.default_app_config = "plinth.axes_app_config.AppConfig" axes.default_app_config = "plinth.axes_app_config.AppConfig"
precedence_commandline_arguments = ["server_dir", "debug", "develop"] precedence_commandline_arguments = ["server_dir", "develop"]
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -47,11 +47,9 @@ def parse_arguments():
# TODO: server_dir is actually a url prefix; use a better variable name # TODO: server_dir is actually a url prefix; use a better variable name
parser.add_argument('--server_dir', default=None, parser.add_argument('--server_dir', default=None,
help='web server path under which to serve') help='web server path under which to serve')
parser.add_argument('--debug', action='store_true', default=None,
help='enable debugging and run server *insecurely*')
parser.add_argument('--develop', action='store_true', default=None, parser.add_argument('--develop', action='store_true', default=None,
help=('use files from current source code folder ' help=('run Plinth *insecurely* from current folder; '
'instead of system-installed plinth files')) 'enable auto-reloading and debugging options'))
parser.add_argument( parser.add_argument(
'--setup', default=False, nargs='*', '--setup', default=False, nargs='*',
help='run setup tasks on all essential modules and exit') help='run setup tasks on all essential modules and exit')
@ -79,8 +77,8 @@ def setup_logging():
# Capture all Python warnings such as deprecation warnings # Capture all Python warnings such as deprecation warnings
logging.captureWarnings(True) logging.captureWarnings(True)
# Log all deprecation warnings when in debug mode # Log all deprecation warnings when in develop mode
if cfg.debug: if cfg.develop:
warnings.filterwarnings('default', '', DeprecationWarning) warnings.filterwarnings('default', '', DeprecationWarning)
warnings.filterwarnings('default', '', PendingDeprecationWarning) warnings.filterwarnings('default', '', PendingDeprecationWarning)
warnings.filterwarnings('default', '', ImportWarning) warnings.filterwarnings('default', '', ImportWarning)
@ -96,7 +94,7 @@ def setup_server():
'server.socket_port': cfg.port, 'server.socket_port': cfg.port,
'server.thread_pool': 10, 'server.thread_pool': 10,
# Avoid stating files once per second in production # Avoid stating files once per second in production
'engine.autoreload.on': cfg.debug, 'engine.autoreload.on': cfg.develop,
}) })
application = django.core.wsgi.get_wsgi_application() application = django.core.wsgi.get_wsgi_application()
@ -189,7 +187,7 @@ def configure_django():
}, },
'root': { 'root': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file'],
'level': 'DEBUG' if cfg.debug else 'INFO' 'level': 'DEBUG' if cfg.develop else 'INFO'
} }
} }
@ -269,7 +267,7 @@ def configure_django():
'NAME': cfg.store_file 'NAME': cfg.store_file
} }
}, },
DEBUG=cfg.debug, DEBUG=cfg.develop,
FORCE_SCRIPT_NAME=cfg.server_dir, FORCE_SCRIPT_NAME=cfg.server_dir,
INSTALLED_APPS=applications, INSTALLED_APPS=applications,
IPWARE_META_PRECEDENCE_ORDER=('HTTP_X_FORWARDED_FOR',), IPWARE_META_PRECEDENCE_ORDER=('HTTP_X_FORWARDED_FOR',),
@ -312,7 +310,7 @@ def configure_django():
logger.debug('Configured Django with applications - %s', applications) logger.debug('Configured Django with applications - %s', applications)
logger.debug('Creating or adding new tables to data file') logger.debug('Creating or adding new tables to data file')
verbosity = 1 if cfg.debug else 0 verbosity = 1 if cfg.develop else 0
django.core.management.call_command('migrate', '--fake-initial', django.core.management.call_command('migrate', '--fake-initial',
interactive=False, verbosity=verbosity) interactive=False, verbosity=verbosity)
os.chmod(cfg.store_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) os.chmod(cfg.store_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
@ -387,14 +385,14 @@ def adapt_config(arguments):
def main(): def main():
"""Intialize and start the application""" """Intialize and start the application"""
arguments = parse_arguments() arguments = parse_arguments()
config_paths = {}
if arguments.develop: if arguments.develop:
# use the root and plinth.config of the current working directory # use the root and plinth.config of the current working directory
file_path, root_directory = cfg.get_fallback_config_paths() config_path, root_directory = cfg.get_fallback_config_paths()
config_paths['file_path'] = file_path cfg.read(config_path, root_directory)
config_paths['root_directory'] = root_directory else:
cfg.read()
cfg.read(**config_paths)
adapt_config(arguments) adapt_config(arguments)
setup_logging() setup_logging()

View File

@ -35,7 +35,7 @@ host = None
port = None port = None
use_x_forwarded_host = False use_x_forwarded_host = False
secure_proxy_ssl_header = None secure_proxy_ssl_header = None
debug = False develop = False
server_dir = '/' server_dir = '/'
danube_edition = False danube_edition = False

View File

@ -57,7 +57,7 @@ def load_modules():
except Exception as exception: except Exception as exception:
logger.exception('Could not import %s: %s', module_import_path, logger.exception('Could not import %s: %s', module_import_path,
exception) exception)
if cfg.debug: if cfg.develop:
raise raise
ordered_modules = [] ordered_modules = []
@ -120,7 +120,7 @@ def _include_module_urls(module_import_path, module_name):
r'', django.conf.urls.include((url_module, module_name)))] r'', django.conf.urls.include((url_module, module_name)))]
except ImportError: except ImportError:
logger.debug('No URLs for %s', module_name) logger.debug('No URLs for %s', module_name)
if cfg.debug: if cfg.develop:
raise raise
@ -140,7 +140,7 @@ def _initialize_module(module_name, module):
except Exception as exception: except Exception as exception:
logger.exception('Exception while running init for %s: %s', logger.exception('Exception while running init for %s: %s',
module, exception) module, exception)
if cfg.debug: if cfg.develop:
raise raise