From bc27284c712675cc328cb9ceb003ab3fbc52e173 Mon Sep 17 00:00:00 2001 From: John Kristensen Date: Mon, 22 Dec 2014 13:30:20 +1100 Subject: [PATCH] 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. --- doc/upgrading.txt | 24 ++++++++++++++++++++++++ roundup/admin.py | 7 +------ roundup/backends/back_anydbm.py | 4 ++++ roundup/configuration.py | 2 ++ roundup/init.py | 17 ----------------- roundup/instance.py | 8 +------- test/db_test_base.py | 3 +-- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/doc/upgrading.txt b/doc/upgrading.txt index e0216d7385..9f0a9d7794 100644 --- a/doc/upgrading.txt +++ b/doc/upgrading.txt @@ -20,6 +20,30 @@ Contents: .. contents:: :local: +Migrating from 1.5.1 to 1.6.0 +============================= + +The ``db/backend_name`` file is no longer used to configure the database +backend being used for a tracker. The backend is now configured in the +``config.ini`` file using the ``backend`` option located in the ``[rdbms]`` +section. For example if ``db/backend_name`` file contains ``sqlite``, a new +entry in the ``config.ini`` will need to be created:: + + [rdbms] + + ... + + # Database backend. + # Default: + backend = sqlite + +Once the ``config.ini`` file has been updated with the new ``backend`` option, +you can safely delete the ``db/backend_name`` file. + +Note: the ``backend_name`` file may be located in a directory other than +``db/`` if you have configured the ``database`` option in the ``[main]`` +section of the ``config.ini`` file to be something other than ``db``. + Migrating from 1.5.0 to 1.5.1 ============================= diff --git a/roundup/admin.py b/roundup/admin.py index c8e950c1b8..a47ad86fe4 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -421,9 +421,9 @@ Erase it? Y/N: """) % locals()) else: defns = {} + defns['rdbms_backend'] = backend # install! init.install(tracker_home, templates[template]['path'], settings=defns) - init.write_select_db(tracker_home, backend) print _(""" --------------------------------------------------------------------------- @@ -502,14 +502,9 @@ Erase it? Y/N: """)) if ok.strip().lower() != 'y': return 0 - backend = tracker.get_backend_name() - # nuke it tracker.nuke() - # re-write the backend select file - init.write_select_db(tracker_home, backend, tracker.config.DATABASE) - # GO tracker.init(password.Password(adminpw, config=tracker.config)) diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 5ce2b9e9af..3b79b2b967 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -172,6 +172,10 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): self.security = security.Security(self) os.umask(config.UMASK) + # make sure the database directory exists + if not os.path.isdir(self.config.DATABASE): + os.makedirs(self.config.DATABASE) + # lock it lockfilenm = os.path.join(self.dir, 'lock') self.lockfile = locking.acquire_lock(lockfilenm) diff --git a/roundup/configuration.py b/roundup/configuration.py index 4376f88d3a..0c902e2cc1 100644 --- a/roundup/configuration.py +++ b/roundup/configuration.py @@ -620,6 +620,8 @@ SETTINGS = ( (Option, 'name', 'roundup', "Name of the database to use.", ['MYSQL_DBNAME']), + (Option, 'backend', '', + "Database backend."), (NullableOption, 'host', 'localhost', "Database server host.", ['MYSQL_DBHOST']), diff --git a/roundup/init.py b/roundup/init.py index c1ccbe4958..46da271d99 100644 --- a/roundup/init.py +++ b/roundup/init.py @@ -175,21 +175,4 @@ def saveTemplateInfo(dir, info): finally: f.close() -def write_select_db(instance_home, backend, dbdir=None): - ''' Write the file that selects the backend for the tracker - ''' - # dbdir is only supplied when AdminTool.do_initialise() invokes this - # function and the value is fetched from the tracker config which has - # already determined the correct path. This is bit of a hack, but it is - # likely this function will be removed in v1.6 - if not dbdir: - dbdir = os.path.join(instance_home, 'db') - if not os.path.exists(dbdir): - os.makedirs(dbdir) - f = open(os.path.join(dbdir, 'backend_name'), 'w') - f.write(backend+'\n') - f.close() - - - # vim: set filetype=python sts=4 sw=4 et si : diff --git a/roundup/instance.py b/roundup/instance.py index 577c57e172..69c4804986 100644 --- a/roundup/instance.py +++ b/roundup/instance.py @@ -63,7 +63,7 @@ class Tracker: self.load_interfaces() self.templates = templating.get_loader(self.config["TEMPLATES"], self.config["TEMPLATE_ENGINE"]) - self.backend = backends.get_backend(self.get_backend_name()) + self.backend = backends.get_backend(self.config.RDBMS_BACKEND) if self.optimize: self.templates.precompile() @@ -77,12 +77,6 @@ class Tracker: # db_open is set to True after first open() self.db_open = 0 - def get_backend_name(self): - f = file(os.path.join(self.config.DATABASE, 'backend_name')) - name = f.readline().strip() - f.close() - return name - def open(self, name=None): # load the database schema # we cannot skip this part even if self.optimize is set diff --git a/test/db_test_base.py b/test/db_test_base.py index 04f534d8be..84593ecd59 100644 --- a/test/db_test_base.py +++ b/test/db_test_base.py @@ -64,12 +64,11 @@ def setupTracker(dirname, backend="anydbm"): 'roundup', 'templates', 'classic')) - init.write_select_db(dirname, backend) + config.RDBMS_BACKEND = backend config.save(os.path.join(dirname, 'config.ini')) tracker = instance.open(dirname) if tracker.exists(): tracker.nuke() - init.write_select_db(dirname, backend) tracker.init(password.Password('sekrit')) return tracker -- 2.1.3