Skip to content

Commit 0486871

Browse files
committed
Update branch with default.
2 parents 3afb6a0 + a568e70 commit 0486871

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ Fixed:
145145
Change by John Rouillard)
146146
- issue2551030: Roundup fails to start if pytz to access Olson
147147
timezone database not installed. (John Rouillard)
148+
- issue2551029: Jinja2 template install error. Handle issue with
149+
template's config.ini not getting updated. Provide an alternate
150+
file: config_ini.ini for required config settings that are merged
151+
into the default values producing an up to date config.ini on
152+
install.
148153

149154
2018-07-13 1.6.0
150155

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
from roundup.anypy.my_input import my_input
@@ -430,9 +430,31 @@ def do_install(self, tracker_home, args):
430430
defns = {}
431431

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

447+
# Remove config_ini.ini file from tracker_home (not template dir).
448+
# Ignore file not found - not all templates have
449+
# config_ini.ini files.
450+
try:
451+
os.remove(tracker_home + "/config_ini.ini")
452+
except OSError as e: # FileNotFound exception under py3
453+
if e.errno == 2:
454+
pass
455+
else:
456+
raise
457+
436458
print(_("""
437459
---------------------------------------------------------------------------
438460
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ def testInit(self):
3636
self.assertTrue(ret == 0)
3737
self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
3838
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")
3971

4072

4173

0 commit comments

Comments
 (0)