Skip to content

Commit 795773c

Browse files
committed
Configure the database backend in the config.ini
The database backend is currently configured in the 'db/backend_name' file which is just another file that needs to be configured when setting up or migrating a tracker instance. By moving this setting into the config.ini it helps to reduce the number of files that need to be configured and is more logical place for users to find the setting.
1 parent 419bd64 commit 795773c

File tree

8 files changed

+63
-32
lines changed

8 files changed

+63
-32
lines changed

doc/upgrading.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ Contents:
2020
.. contents::
2121
:local:
2222

23+
Migrating from 1.5.1 to 1.6.0
24+
=============================
25+
26+
The ``db/backend_name`` file is no longer used to configure the database
27+
backend being used for a tracker. The backend is now configured in the
28+
``config.ini`` file using the ``backend`` option located in the ``[rdbms]``
29+
section. For example if ``db/backend_name`` file contains ``sqlite``, a new
30+
entry in the ``config.ini`` will need to be created::
31+
32+
[rdbms]
33+
34+
...
35+
36+
# Database backend.
37+
# Default:
38+
backend = sqlite
39+
40+
Once the ``config.ini`` file has been updated with the new ``backend`` option,
41+
you can safely delete the ``db/backend_name`` file.
42+
43+
Note: the ``backend_name`` file may be located in a directory other than
44+
``db/`` if you have configured the ``database`` option in the ``[main]``
45+
section of the ``config.ini`` file to be something other than ``db``.
46+
2347
Migrating from 1.5.0 to 1.5.1
2448
=============================
2549

roundup/admin.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ def do_install(self, tracker_home, args):
421421
else:
422422
defns = {}
423423

424+
defns['rdbms_backend'] = backend
424425
# install!
425426
init.install(tracker_home, templates[template]['path'], settings=defns)
426-
init.write_select_db(tracker_home, backend)
427427

428428
print _("""
429429
---------------------------------------------------------------------------
@@ -502,14 +502,9 @@ def do_initialise(self, tracker_home, args):
502502
if ok.strip().lower() != 'y':
503503
return 0
504504

505-
backend = tracker.get_backend_name()
506-
507505
# nuke it
508506
tracker.nuke()
509507

510-
# re-write the backend select file
511-
init.write_select_db(tracker_home, backend, tracker.config.DATABASE)
512-
513508
# GO
514509
tracker.init(password.Password(adminpw, config=tracker.config))
515510

roundup/backends/back_anydbm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def __init__(self, config, journaltag=None):
171171
self.security = security.Security(self)
172172
os.umask(config.UMASK)
173173

174+
# make sure the database directory exists
175+
if not os.path.isdir(self.config.DATABASE):
176+
os.makedirs(self.config.DATABASE)
177+
174178
# lock it
175179
lockfilenm = os.path.join(self.dir, 'lock')
176180
self.lockfile = locking.acquire_lock(lockfilenm)

roundup/backends/rdbms_common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ def __init__(self, config, journaltag=None):
185185
self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0,
186186
'filtering': 0}
187187

188+
# make sure the database directory exists
189+
if not os.path.isdir(self.config.DATABASE):
190+
os.makedirs(self.config.DATABASE)
191+
188192
# database lock
189193
self.lockfile = None
190194

roundup/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ def str2value(self, value):
620620
(Option, 'name', 'roundup',
621621
"Name of the database to use.",
622622
['MYSQL_DBNAME']),
623+
(Option, 'backend', '',
624+
"Database backend."),
623625
(NullableOption, 'host', 'localhost',
624626
"Database server host.",
625627
['MYSQL_DBHOST']),

roundup/init.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,4 @@ def saveTemplateInfo(dir, info):
175175
finally:
176176
f.close()
177177

178-
def write_select_db(instance_home, backend, dbdir=None):
179-
''' Write the file that selects the backend for the tracker
180-
'''
181-
# dbdir is only supplied when AdminTool.do_initialise() invokes this
182-
# function and the value is fetched from the tracker config which has
183-
# already determined the correct path. This is bit of a hack, but it is
184-
# likely this function will be removed in v1.6
185-
if not dbdir:
186-
dbdir = os.path.join(instance_home, 'db')
187-
if not os.path.exists(dbdir):
188-
os.makedirs(dbdir)
189-
f = open(os.path.join(dbdir, 'backend_name'), 'w')
190-
f.write(backend+'\n')
191-
f.close()
192-
193-
194-
195178
# vim: set filetype=python sts=4 sw=4 et si :

roundup/instance.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import os
3232
import sys
33+
import warnings
34+
3335
from roundup import configuration, mailgw
3436
from roundup import hyperdb, backends, actions
3537
from roundup.cgi import client, templating
@@ -63,7 +65,31 @@ def __init__(self, tracker_home, optimize=0):
6365
self.load_interfaces()
6466
self.templates = templating.get_loader(self.config["TEMPLATES"],
6567
self.config["TEMPLATE_ENGINE"])
66-
self.backend = backends.get_backend(self.get_backend_name())
68+
69+
rdbms_backend = self.config.RDBMS_BACKEND
70+
71+
# TODO: Remove in v1.7
72+
# Provide some backwards compatability for existing Roundup instances
73+
# that still define the backend type in 'db/backend_name' and warn the
74+
# users they need to update their config.ini
75+
if rdbms_backend == '':
76+
filename = os.path.join(self.config.DATABASE, 'backend_name')
77+
msg = """\n
78+
The 'backend_name' file is no longer used to configure the database backend
79+
used for the tracker. Please read 'doc/upgrading.txt' to find out how to
80+
update your config.ini
81+
"""
82+
try:
83+
with file(filename) as backend_file:
84+
rdbms_backend = backend_file.readline().strip()
85+
86+
with warnings.catch_warnings():
87+
warnings.simplefilter("once", DeprecationWarning)
88+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
89+
except IOError:
90+
pass
91+
92+
self.backend = backends.get_backend(rdbms_backend)
6793

6894
if self.optimize:
6995
self.templates.precompile()
@@ -77,12 +103,6 @@ def __init__(self, tracker_home, optimize=0):
77103
# db_open is set to True after first open()
78104
self.db_open = 0
79105

80-
def get_backend_name(self):
81-
f = file(os.path.join(self.config.DATABASE, 'backend_name'))
82-
name = f.readline().strip()
83-
f.close()
84-
return name
85-
86106
def open(self, name=None):
87107
# load the database schema
88108
# we cannot skip this part even if self.optimize is set

test/db_test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ def setupTracker(dirname, backend="anydbm"):
6565
'roundup',
6666
'templates',
6767
'classic'))
68-
init.write_select_db(dirname, backend)
68+
config.RDBMS_BACKEND = backend
6969
config.save(os.path.join(dirname, 'config.ini'))
7070
tracker = instance.open(dirname)
7171
if tracker.exists():
7272
tracker.nuke()
73-
init.write_select_db(dirname, backend)
7473
tracker.init(password.Password('sekrit'))
7574
return tracker
7675

0 commit comments

Comments
 (0)