Mercurial > p > roundup > code
comparison roundup/instance.py @ 2890:938915fbcb49
get_backend_name() is a lengthy thing (file I/O).
since we are not going to do backend switching at runtime,
compute the backend once in __init__().
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Wed, 10 Nov 2004 08:05:21 +0000 |
| parents | adec352e2ce0 |
| children | bc72b1c7319b |
comparison
equal
deleted
inserted
replaced
| 2889:accb3b411ef6 | 2890:938915fbcb49 |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: instance.py,v 1.28 2004-11-03 01:34:21 richard Exp $ | 18 # $Id: instance.py,v 1.29 2004-11-10 08:05:21 a1s Exp $ |
| 19 | 19 |
| 20 '''Tracker handling (open tracker). | 20 '''Tracker handling (open tracker). |
| 21 | 21 |
| 22 Backwards compatibility for the old-style "imported" trackers. | 22 Backwards compatibility for the old-style "imported" trackers. |
| 23 ''' | 23 ''' |
| 48 self.config = configuration.CoreConfig(tracker_home) | 48 self.config = configuration.CoreConfig(tracker_home) |
| 49 self.cgi_actions = {} | 49 self.cgi_actions = {} |
| 50 self.templating_utils = {} | 50 self.templating_utils = {} |
| 51 self.load_interfaces() | 51 self.load_interfaces() |
| 52 self.templates = templating.Templates(self.config["TEMPLATES"]) | 52 self.templates = templating.Templates(self.config["TEMPLATES"]) |
| 53 self.backend = backends.get_backend(self.get_backend_name()) | |
| 53 if self.optimize: | 54 if self.optimize: |
| 54 self.templates.precompileTemplates() | 55 self.templates.precompileTemplates() |
| 55 | 56 |
| 56 def get_backend_name(self): | 57 def get_backend_name(self): |
| 57 o = __builtins__['open'] | 58 o = __builtins__['open'] |
| 58 f = o(os.path.join(self.tracker_home, 'db', 'backend_name')) | 59 f = o(os.path.join(self.tracker_home, 'db', 'backend_name')) |
| 59 name = f.readline().strip() | 60 name = f.readline().strip() |
| 60 f.close() | 61 f.close() |
| 61 return name | 62 return name |
| 62 | 63 |
| 63 def get_backend(self): | |
| 64 return backends.get_backend(self.get_backend_name()) | |
| 65 | |
| 66 def open(self, name=None): | 64 def open(self, name=None): |
| 67 backend = self.get_backend() | 65 backend = self.backend |
| 68 vars = { | 66 vars = { |
| 69 'Class': backend.Class, | 67 'Class': backend.Class, |
| 70 'FileClass': backend.FileClass, | 68 'FileClass': backend.FileClass, |
| 71 'IssueClass': backend.IssueClass, | 69 'IssueClass': backend.IssueClass, |
| 72 'String': hyperdb.String, | 70 'String': hyperdb.String, |
| 112 'admin_email': self.config['ADMIN_EMAIL']}) | 110 'admin_email': self.config['ADMIN_EMAIL']}) |
| 113 db.commit() | 111 db.commit() |
| 114 db.close() | 112 db.close() |
| 115 | 113 |
| 116 def exists(self): | 114 def exists(self): |
| 117 backend = self.get_backend() | 115 return self.backend.db_exists(self.config) |
| 118 return backend.db_exists(self.config) | |
| 119 | 116 |
| 120 def nuke(self): | 117 def nuke(self): |
| 121 backend = self.get_backend() | 118 self.backend.db_nuke(self.config) |
| 122 backend.db_nuke(self.config) | |
| 123 | 119 |
| 124 def _load_python(self, file, vars): | 120 def _load_python(self, file, vars): |
| 125 file = os.path.join(self.tracker_home, file) | 121 file = os.path.join(self.tracker_home, file) |
| 126 execfile(file, vars) | 122 execfile(file, vars) |
| 127 return vars | 123 return vars |
| 180 raise TrackerError, \ | 176 raise TrackerError, \ |
| 181 'Required tracker attribute "%s" missing'%required | 177 'Required tracker attribute "%s" missing'%required |
| 182 | 178 |
| 183 # load and apply the config | 179 # load and apply the config |
| 184 tracker.config = configuration.CoreConfig(tracker_home) | 180 tracker.config = configuration.CoreConfig(tracker_home) |
| 185 # FIXME! dbinit does "import config". | |
| 186 # What would be the upgrade plan for existing trackers? | |
| 187 tracker.dbinit.config = tracker.config | 181 tracker.dbinit.config = tracker.config |
| 188 | 182 |
| 189 tracker.optimize = optimize | 183 tracker.optimize = optimize |
| 190 tracker.templates = templating.Templates(tracker.config["TEMPLATES"]) | 184 tracker.templates = templating.Templates(tracker.config["TEMPLATES"]) |
| 191 if optimize: | 185 if optimize: |
