Mercurial > p > roundup > code
comparison roundup/instance.py @ 5041:5251e97b1de0
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.
| author | John Kristensen <john@jerrykan.com> |
|---|---|
| date | Mon, 22 Dec 2014 13:30:20 +1100 |
| parents | 6e9b9743de89 |
| children | e424987d294a |
comparison
equal
deleted
inserted
replaced
| 5040:f52a9fb035d2 | 5041:5251e97b1de0 |
|---|---|
| 28 """ | 28 """ |
| 29 __docformat__ = 'restructuredtext' | 29 __docformat__ = 'restructuredtext' |
| 30 | 30 |
| 31 import os | 31 import os |
| 32 import sys | 32 import sys |
| 33 import warnings | |
| 34 | |
| 33 from roundup import configuration, mailgw | 35 from roundup import configuration, mailgw |
| 34 from roundup import hyperdb, backends, actions | 36 from roundup import hyperdb, backends, actions |
| 35 from roundup.cgi import client, templating | 37 from roundup.cgi import client, templating |
| 36 from roundup.cgi import actions as cgi_actions | 38 from roundup.cgi import actions as cgi_actions |
| 37 | 39 |
| 61 self.libdir = os.path.isdir(libdir) and libdir or '' | 63 self.libdir = os.path.isdir(libdir) and libdir or '' |
| 62 | 64 |
| 63 self.load_interfaces() | 65 self.load_interfaces() |
| 64 self.templates = templating.get_loader(self.config["TEMPLATES"], | 66 self.templates = templating.get_loader(self.config["TEMPLATES"], |
| 65 self.config["TEMPLATE_ENGINE"]) | 67 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) | |
| 67 | 93 |
| 68 if self.optimize: | 94 if self.optimize: |
| 69 self.templates.precompile() | 95 self.templates.precompile() |
| 70 # initialize tracker extensions | 96 # initialize tracker extensions |
| 71 for extension in self.get_extensions('extensions'): | 97 for extension in self.get_extensions('extensions'): |
| 74 self.schema = self._compile('schema.py') | 100 self.schema = self._compile('schema.py') |
| 75 # load database detectors | 101 # load database detectors |
| 76 self.detectors = self.get_extensions('detectors') | 102 self.detectors = self.get_extensions('detectors') |
| 77 # db_open is set to True after first open() | 103 # db_open is set to True after first open() |
| 78 self.db_open = 0 | 104 self.db_open = 0 |
| 79 | |
| 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 | 105 |
| 86 def open(self, name=None): | 106 def open(self, name=None): |
| 87 # load the database schema | 107 # load the database schema |
| 88 # we cannot skip this part even if self.optimize is set | 108 # we cannot skip this part even if self.optimize is set |
| 89 # because the schema has security settings that must be | 109 # because the schema has security settings that must be |
