diff roundup/demo.py @ 6545:5a3a386aa8e7

issue2551179 Load config_ini.ini ... recognize minimal template demo.py Mostly taken from patch by John Kristensen (jerrykan). Tests for python3 and 2 created for minimal and jinja2 templates. Removed FIXME for special case config settings for jinja and responsive templates. config_ini.ini mechanism makes it obsolete. Demo removes config_ini.ini file in home directory. Also remove encoding of utf-8 from initial_data.py to remove SyntaxError: encoding declaration in Unicode string under python2.
author John Rouillard <rouilj@ieee.org>
date Thu, 09 Dec 2021 15:26:39 -0500
parents d8d046749b5b
children 7147a4c833e9
line wrap: on
line diff
--- a/roundup/demo.py	Tue Dec 07 11:15:04 2021 -0500
+++ b/roundup/demo.py	Thu Dec 09 15:26:39 2021 -0500
@@ -39,7 +39,13 @@
     from roundup import init, instance, password
 
     # set up the config for this tracker
-    config = configuration.CoreConfig()
+    template_dir = os.path.join('share', 'roundup', 'templates', template)
+
+    # Load optional override ini file. Missing ini file is ignored.
+    template_cfg = configuration.UserConfig(template_dir + "/config_ini.ini")
+    config = configuration.CoreConfig(settings={
+        i.name: i.get() for i in template_cfg.items()
+    })
     config['TRACKER_HOME'] = home
     config['MAIL_DOMAIN'] = 'localhost'
     config['DATABASE'] = 'db'
@@ -64,8 +70,18 @@
             print("    %s" % home)
             sys.exit(1)
 
-    template_dir = os.path.join('share', 'roundup', 'templates', template)
     init.install(home, template_dir)
+    # 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(home + "/config_ini.ini")
+    except OSError as e:  # FileNotFound exception under py3
+        if e.errno == 2:
+            pass
+        else:
+            raise
+
     # don't have email flying around
     nosyreaction = os.path.join(home, 'detectors', 'nosyreaction.py')
     if os.path.exists(nosyreaction):
@@ -97,12 +113,6 @@
 
     # write the config
     config['INSTANT_REGISTRATION'] = 1
-    # FIXME: Move template-specific demo initialization into the templates.
-    if template == 'responsive':
-        config['STATIC_FILES'] = "static"
-    if template == 'jinja2':
-        config['TEMPLATE_ENGINE'] = 'jinja2'
-        config['STATIC_FILES'] = "static"
     config.save(os.path.join(home, config.INI_FILE))
 
     # open the tracker and initialise
@@ -113,7 +123,7 @@
     db = tracker.open('admin')
     # FIXME: Move tracker-specific demo initialization into the tracker
     # templates.
-    if template == 'minimal':
+    if os.path.basename(template) == 'minimal':
         db.user.create(username='demo', password=password.Password('demo'),
                        roles='User')
     else:

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