changeset 5762:b76be13e027e

issue2551029: Jinja2 template install error. Issue where template's config.ini not getting updated. Change do_install in admin.py to load config_ini.ini from template before writing tracker's config.ini. This generates an updated config file for the user on install preserving values required tomake tracker work. Added config_ini.ini files to jinja2 and responsive templates to set required values (template_engine and static_files; static_files resp.). Documented new file in doc/tracker_templates.txt and added tests for new admin.py code.
author John Rouillard <rouilj@ieee.org>
date Tue, 04 Jun 2019 18:42:05 -0400
parents f0ca4daf6a18
children d4152c2e9039 9cc3257d0f43
files CHANGES.txt doc/tracker_templates.txt roundup/admin.py share/roundup/templates/jinja2/config_ini.ini share/roundup/templates/responsive/config_ini.ini test/test_admin.py
diffstat 6 files changed, 72 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sun Jun 02 17:15:23 2019 -0400
+++ b/CHANGES.txt	Tue Jun 04 18:42:05 2019 -0400
@@ -145,6 +145,11 @@
   Change by John Rouillard)
 - issue2551030: Roundup fails to start if pytz to access Olson
   timezone database not installed. (John Rouillard)
+- issue2551029: Jinja2 template install error. Handle issue with
+  template's config.ini not getting updated. Provide an alternate
+  file: config_ini.ini for required config settings that are merged
+  into the default values producing an up to date config.ini on
+  install.
 
 2018-07-13 1.6.0
 
--- a/doc/tracker_templates.txt	Sun Jun 02 17:15:23 2019 -0400
+++ b/doc/tracker_templates.txt	Tue Jun 04 18:42:05 2019 -0400
@@ -25,6 +25,12 @@
 - modules ``schema.py`` and ``initial_data.py``
 - directories ``html``, ``detectors`` and ``extensions``
   (with appropriate contents)
+- optional ``config_ini.ini`` file. It is structured like a tracker's
+  ``config.ini`` but contains only headers (e.g. ``[main]``) and
+  *required* parameters that are different from defaults:
+  e.g. ``template_engine = jinja2`` and ``static_files =
+  static``. These settings override the default values saved to the
+  tracker's ``config.ini``.
 - template "marker" file ``TEMPLATE-INFO.txt``, which contains
   the name of the template, a description of the template
   and its intended audience.
--- a/roundup/admin.py	Sun Jun 02 17:15:23 2019 -0400
+++ b/roundup/admin.py	Tue Jun 04 18:42:05 2019 -0400
@@ -28,7 +28,7 @@
 from roundup import date, hyperdb, roundupdb, init, password, token
 from roundup import __version__ as roundup_version
 import roundup.instance
-from roundup.configuration import CoreConfig, NoConfigError
+from roundup.configuration import CoreConfig, NoConfigError, UserConfig
 from roundup.i18n import _
 from roundup.exceptions import UsageError
 from roundup.anypy.my_input import my_input
@@ -430,9 +430,31 @@
             defns = {}
 
         defns['rdbms_backend'] = backend
+
+        # load config_ini.ini from template if it exists.
+        # it sets parameters like template_engine that are
+        # template specific.
+        template_config=UserConfig(templates[template]['path'] +
+                                   "/config_ini.ini")
+        for k in template_config.keys():
+            if k == 'HOME': # ignore home. It is a default param.
+                continue
+            defns[k] = template_config[k]
+
         # install!
         init.install(tracker_home, templates[template]['path'], settings=defns)
 
+        # Remove config_ini.ini file from tracker_home (not template dir).
+        # Ignore file not found - not all templates have
+        #   config_ini.ini files.
+        try:
+            os.remove(tracker_home + "/config_ini.ini")
+        except OSError as e:  # FileNotFound exception under py3
+            if e.errno == 2:
+                pass
+            else:
+                raise
+
         print(_("""
 ---------------------------------------------------------------------------
  You should now edit the tracker configuration file:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/roundup/templates/jinja2/config_ini.ini	Tue Jun 04 18:42:05 2019 -0400
@@ -0,0 +1,4 @@
+[main]
+template_engine = jinja2
+
+static_files = static
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/roundup/templates/responsive/config_ini.ini	Tue Jun 04 18:42:05 2019 -0400
@@ -0,0 +1,2 @@
+[main]
+static_files = static
--- a/test/test_admin.py	Sun Jun 02 17:15:23 2019 -0400
+++ b/test/test_admin.py	Tue Jun 04 18:42:05 2019 -0400
@@ -36,6 +36,38 @@
         self.assertTrue(ret == 0)
         self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
         self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
+
+    def testInitWithConfig_ini(self):
+        import sys
+        from roundup.configuration import CoreConfig
+        self.admin=AdminTool()
+        sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend]
+        # create a config_ini.ini file in classic template
+        templates=self.admin.listTemplates()
+        config_ini_content = "[mail]\n# comment\ndebug = SendMail.LOG\n"
+        config_ini_path = templates['classic']['path'] + '/config_ini.ini'
+        config_ini_file = open(config_ini_path, "w")
+        config_ini_file.write(config_ini_content)
+        config_ini_file.close()
+
+        try:
+            ret = self.admin.main()
+        finally:
+            try:
+                # ignore file not found
+                os.remove(config_ini_path)
+            except OSError as e:  # FileNotFound exception under py3
+                if e.errno == 2:
+                    pass
+                else:
+                    raise
+
+        print(ret)
+        self.assertTrue(ret == 0)
+        self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
+        self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
+        config=CoreConfig(self.dirname)
+        self.assertEqual(config['MAIL_DEBUG'], self.dirname + "/SendMail.LOG")
         
 
 

Roundup Issue Tracker: http://roundup-tracker.org/