From 486f4fce8b935224286aea04f09ea56bf85576b5 Mon Sep 17 00:00:00 2001 From: John Kristensen Date: Wed, 18 Jun 2014 14:37:41 +1000 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/configuration.py | 2 ++ roundup/init.py | 14 -------------- roundup/instance.py | 8 +------- test/db_test_base.py | 3 +-- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/doc/upgrading.txt b/doc/upgrading.txt index a5e9816..f7dfe5b 100644 --- a/doc/upgrading.txt +++ b/doc/upgrading.txt @@ -16,6 +16,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 90fafaa..7471b43 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/configuration.py b/roundup/configuration.py index 4376f88..0c902e2 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 bfbf6a4..46da271 100644 --- a/roundup/init.py +++ b/roundup/init.py @@ -175,18 +175,4 @@ def saveTemplateInfo(dir, info): finally: f.close() -def write_select_db(instance_home, backend, dbdir = 'db'): - ''' Write the file that selects the backend for the tracker - ''' - # dbdir may be a relative pathname, os.path.join does the right - # thing when the second component of a join is an absolute path - dbdir = os.path.join (instance_home, dbdir) - 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 577c57e..69c4804 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 04f534d..84593ec 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.0.0