From 03a805888d08c17832204bd8e736706d917c3514 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 10 Jan 2022 12:04:06 -0800 Subject: [PATCH] help: Fix failing setup when manual directory is not available - It is reported on the mailing list that first setup operation on the help app fails. The logs indicate that /usr/share/freedombox/manual directory is not present on the system. Although this situation does not occur on a normal installation, catch, log and ignore this error to be safe. - Also ensure that this static files component is added in post_init so that basic setup is not at all affected by it. Tests: - In the development directory, move doc/manual to doc/manual.bak. Observe that the error message is printed during initialization but the process continues. - With the manual directory properly restored, the full help manual is displayed properly with images. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/help/__init__.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plinth/modules/help/__init__.py b/plinth/modules/help/__init__.py index 2d748a7de..3517b2c28 100644 --- a/plinth/modules/help/__init__.py +++ b/plinth/modules/help/__init__.py @@ -3,6 +3,7 @@ FreedomBox app for help pages. """ +import logging import os from django.utils.translation import gettext_lazy as _ @@ -11,6 +12,8 @@ from django.utils.translation import pgettext_lazy from plinth import app as app_module from plinth import cfg, menu, web_server +logger = logging.getLogger(__name__) + app = None @@ -54,12 +57,19 @@ class HelpApp(app_module.App): order=100) self.add(menu_item) + def post_init(self): + """Perform post initialization operations.""" directory_map = {} - langs = os.listdir(os.path.join(cfg.doc_dir, 'manual')) - for lang in langs: - manual_dir = os.path.join(cfg.doc_dir, 'manual', lang, 'images') - manual_url = f'/help/manual/{lang}/images' - directory_map[manual_url] = manual_dir + try: + langs = os.listdir(os.path.join(cfg.doc_dir, 'manual')) + for lang in langs: + manual_dir = os.path.join(cfg.doc_dir, 'manual', lang, + 'images') + manual_url = f'/help/manual/{lang}/images' + directory_map[manual_url] = manual_dir + except FileNotFoundError: + logger.error('Unable to find manual directory. Ensure that ' + 'freedombox-doc-* packages are installed') static_files = web_server.StaticFiles('static-files-help', directory_map)