Skip to content

Commit 1a758e9

Browse files
committed
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.
1 parent 7612333 commit 1a758e9

File tree

6 files changed

+129
-2
lines changed

6 files changed

+129
-2
lines changed

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ Fixed:
3434
- issue2551029: Jinja2 template install error. Remove config.ini
3535
from templates to make sure that roundup-admin install writes a new
3636
default config.ini based on configuration.py.
37-
37+
- issue2551029: Jinja2 template install error. Handle issue with
38+
template's config.ini not getting updated. Provide an alternate
39+
file: config_ini.ini for required config settings that are merged
40+
into the default values producing an up to date config.ini on
41+
install.
3842

3943
2018-07-13 1.6.0
4044

doc/tracker_templates.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Templates contain:
2525
- modules ``schema.py`` and ``initial_data.py``
2626
- directories ``html``, ``detectors`` and ``extensions``
2727
(with appropriate contents)
28+
- optional ``config_ini.ini`` file. It is structured like a tracker's
29+
``config.ini`` but contains only headers (e.g. ``[main]``) and
30+
*required* parameters that are different from defaults:
31+
e.g. ``template_engine = jinja2`` and ``static_files =
32+
static``. These settings override the default values saved to the
33+
tracker's ``config.ini``.
2834
- template "marker" file ``TEMPLATE-INFO.txt``, which contains
2935
the name of the template, a description of the template
3036
and its intended audience.

roundup/admin.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from roundup import date, hyperdb, roundupdb, init, password, token
2929
from roundup import __version__ as roundup_version
3030
import roundup.instance
31-
from roundup.configuration import CoreConfig, NoConfigError
31+
from roundup.configuration import CoreConfig, NoConfigError, UserConfig
3232
from roundup.i18n import _
3333
from roundup.exceptions import UsageError
3434

@@ -429,9 +429,31 @@ def do_install(self, tracker_home, args):
429429
defns = {}
430430

431431
defns['rdbms_backend'] = backend
432+
433+
# load config_ini.ini from template if it exists.
434+
# it sets parameters like template_engine that are
435+
# template specific.
436+
template_config=UserConfig(templates[template]['path'] +
437+
"/config_ini.ini")
438+
for k in template_config.keys():
439+
if k == 'HOME': # ignore home. It is a default param.
440+
continue
441+
defns[k] = template_config[k]
442+
432443
# install!
433444
init.install(tracker_home, templates[template]['path'], settings=defns)
434445

446+
# Remove config_ini.ini file from tracker_home (not template dir).
447+
# Ignore file not found - not all templates have
448+
# config_ini.ini files.
449+
try:
450+
os.remove(tracker_home + "/config_ini.ini")
451+
except OSError as e: # FileNotFound exception under py3
452+
if e.errno == 2:
453+
pass
454+
else:
455+
raise
456+
435457
print(_("""
436458
---------------------------------------------------------------------------
437459
You should now edit the tracker configuration file:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[main]
2+
template_engine = jinja2
3+
4+
static_files = static
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[main]
2+
static_files = static

test/test_admin.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#
2+
# Copyright (C) 2007 Stefan Seefeld
3+
# All rights reserved.
4+
# For license terms see the file COPYING.txt.
5+
#
6+
7+
from __future__ import print_function
8+
import unittest, os, shutil, errno, sys, difflib, cgi, re
9+
10+
from roundup.admin import AdminTool
11+
12+
from . import db_test_base
13+
from .test_mysql import skip_mysql
14+
from .test_postgresql import skip_postgresql
15+
16+
17+
class AdminTest(object):
18+
19+
backend = None
20+
21+
def setUp(self):
22+
self.dirname = '_test_admin'
23+
24+
def tearDown(self):
25+
try:
26+
shutil.rmtree(self.dirname)
27+
except OSError as error:
28+
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
29+
30+
def testInit(self):
31+
import sys
32+
self.admin=AdminTool()
33+
sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend]
34+
ret = self.admin.main()
35+
print(ret)
36+
self.assertTrue(ret == 0)
37+
self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
38+
self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
39+
40+
def testInitWithConfig_ini(self):
41+
import sys
42+
from roundup.configuration import CoreConfig
43+
self.admin=AdminTool()
44+
sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend]
45+
# create a config_ini.ini file in classic template
46+
templates=self.admin.listTemplates()
47+
config_ini_content = "[mail]\n# comment\ndebug = SendMail.LOG\n"
48+
config_ini_path = templates['classic']['path'] + '/config_ini.ini'
49+
config_ini_file = open(config_ini_path, "w")
50+
config_ini_file.write(config_ini_content)
51+
config_ini_file.close()
52+
53+
try:
54+
ret = self.admin.main()
55+
finally:
56+
try:
57+
# ignore file not found
58+
os.remove(config_ini_path)
59+
except OSError as e: # FileNotFound exception under py3
60+
if e.errno == 2:
61+
pass
62+
else:
63+
raise
64+
65+
print(ret)
66+
self.assertTrue(ret == 0)
67+
self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
68+
self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
69+
config=CoreConfig(self.dirname)
70+
self.assertEqual(config['MAIL_DEBUG'], self.dirname + "/SendMail.LOG")
71+
72+
73+
74+
class anydbmAdminTest(AdminTest, unittest.TestCase):
75+
backend = 'anydbm'
76+
77+
78+
@skip_mysql
79+
class mysqlAdminTest(AdminTest, unittest.TestCase):
80+
backend = 'mysql'
81+
82+
83+
class sqliteAdminTest(AdminTest, unittest.TestCase):
84+
backend = 'sqlite'
85+
86+
87+
@skip_postgresql
88+
class postgresqlAdminTest(AdminTest, unittest.TestCase):
89+
backend = 'postgresql'

0 commit comments

Comments
 (0)