From 9721eeac2bdb9bf1be1bea55df267f80b3e4a8c8 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Fri, 28 Sep 2018 11:04:21 +0530 Subject: [PATCH] customization: Serve static files from customization directory - Static files are directly served by the CherryPy web server. - .gitignore file placed as a placeholder to be able to commit the directory Signed-off-by: Joseph Nuthalapati Reviewed-by: James Valleroy --- data/etc/plinth/plinth.config | 1 + data/var/www/plinth/custom/static/theme | 1 + .../custom/static/themes/default/icons/.gitignore | 5 +++++ plinth.config | 1 + plinth/__main__.py | 13 +++++++++++++ plinth/cfg.py | 9 +++++---- 6 files changed, 26 insertions(+), 4 deletions(-) create mode 120000 data/var/www/plinth/custom/static/theme create mode 100644 data/var/www/plinth/custom/static/themes/default/icons/.gitignore diff --git a/data/etc/plinth/plinth.config b/data/etc/plinth/plinth.config index f99f679bf..86d7766f4 100644 --- a/data/etc/plinth/plinth.config +++ b/data/etc/plinth/plinth.config @@ -7,6 +7,7 @@ log_dir = /var/log/plinth server_dir = /plinth actions_dir = /usr/share/plinth/actions doc_dir = /usr/share/doc/plinth +custom_static_dir = /var/www/plinth/custom/static # file locations store_file = %(data_dir)s/plinth.sqlite3 diff --git a/data/var/www/plinth/custom/static/theme b/data/var/www/plinth/custom/static/theme new file mode 120000 index 000000000..932f05ef2 --- /dev/null +++ b/data/var/www/plinth/custom/static/theme @@ -0,0 +1 @@ +themes/default/ \ No newline at end of file diff --git a/data/var/www/plinth/custom/static/themes/default/icons/.gitignore b/data/var/www/plinth/custom/static/themes/default/icons/.gitignore new file mode 100644 index 000000000..76bedaeab --- /dev/null +++ b/data/var/www/plinth/custom/static/themes/default/icons/.gitignore @@ -0,0 +1,5 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore + diff --git a/plinth.config b/plinth.config index 4efb0ac45..e428bd3f6 100644 --- a/plinth.config +++ b/plinth.config @@ -7,6 +7,7 @@ log_dir = %(file_root)s/data/var/log/plinth server_dir = /plinth actions_dir = %(file_root)s/actions doc_dir = %(file_root)s/doc +custom_static_dir = %(file_root)s/data/var/www/plinth/custom/static # file locations store_file = %(data_dir)s/plinth.sqlite3 diff --git a/plinth/__main__.py b/plinth/__main__.py index 541a004da..dc189411d 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -112,6 +112,19 @@ def setup_server(): logger.debug('Serving static directory %s on %s', static_dir, django.conf.settings.STATIC_URL) + custom_static_dir = cfg.custom_static_dir + custom_static_url = '/plinth/custom/static' + config = { + '/': { + 'tools.staticdir.root': custom_static_dir, + 'tools.staticdir.on': True, + 'tools.staticdir.dir': '.' + } + } + cherrypy.tree.mount(None, custom_static_url, config) + logger.debug('Serving custom static directory %s on %s', custom_static_dir, + custom_static_url) + js_dir = '/usr/share/javascript' js_url = '/javascript' config = { diff --git a/plinth/cfg.py b/plinth/cfg.py index 22753198c..38f47918b 100644 --- a/plinth/cfg.py +++ b/plinth/cfg.py @@ -26,6 +26,7 @@ root = None file_root = None config_dir = None data_dir = None +custom_static_dir = None store_file = None actions_dir = None doc_dir = None @@ -81,10 +82,9 @@ def read(config_path=None, root_directory=None): global config_file # pylint: disable-msg=invalid-name,global-statement config_file = config_path - parser = configparser.ConfigParser( - defaults={ - 'root': os.path.realpath(root_directory), - }) + parser = configparser.ConfigParser(defaults={ + 'root': os.path.realpath(root_directory), + }) parser.read(config_file) config_items = ( @@ -92,6 +92,7 @@ def read(config_path=None, root_directory=None): ('Path', 'file_root', 'string'), ('Path', 'config_dir', 'string'), ('Path', 'data_dir', 'string'), + ('Path', 'custom_static_dir', 'string'), ('Path', 'store_file', 'string'), ('Path', 'actions_dir', 'string'), ('Path', 'doc_dir', 'string'),