Mercurial > p > roundup > code
comparison roundup/instance.py @ 2633:a9e1fff1e793
I thought I committed this last night. Ho hum.
- This implements most of the rest of the new tracker config layout:
- dbinit.py split between schema.py and initial_data.py
- interfaces.py gone
- tracker and detectors __init__.py gone
- Added some missing functionality to backends: db_exists test and db_nuke.
- Implemented configuration file options in postgresql backend.
- Cleaned up tracker initialisation a lot.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 27 Jul 2004 00:57:19 +0000 |
| parents | d344419d599d |
| children | 18e86941c950 |
comparison
equal
deleted
inserted
replaced
| 2632:9c55f2bc5961 | 2633:a9e1fff1e793 |
|---|---|
| 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.16 2004-07-25 13:14:57 a1s Exp $ | 18 # $Id: instance.py,v 1.17 2004-07-27 00:57:18 richard 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 ''' |
| 24 __docformat__ = 'restructuredtext' | 24 __docformat__ = 'restructuredtext' |
| 25 | 25 |
| 26 import os | 26 import os |
| 27 from roundup import configuration, rlog | 27 from roundup import configuration, rlog |
| 28 from roundup import hyperdb, backends | |
| 28 | 29 |
| 29 class Vars: | 30 class Vars: |
| 30 ''' I'm just a container ''' | 31 def __init__(self, vars): |
| 32 self.__dict__.update(vars) | |
| 31 | 33 |
| 32 class Tracker: | 34 class Tracker: |
| 33 def __init__(self, tracker_home): | 35 def __init__(self, tracker_home): |
| 34 self.tracker_home = tracker_home | 36 self.tracker_home = tracker_home |
| 35 self.select_db = self._load_python('select_db.py') | 37 self.config = configuration.Config(tracker_home) |
| 36 self.config = self._load_config('config.py') | 38 self.cgi_actions = {} |
| 37 raise NotImplemented, 'this is *so* not finished' | 39 self.templating_utils = {} |
| 38 self.init = XXX | |
| 39 self.Client = XXX | |
| 40 self.MailGW = XXX | |
| 41 | 40 |
| 42 def open(self): | 41 def get_backend(self): |
| 43 return self._load_config('schema.py').db | 42 o = __builtins__['open'] |
| 44 self._load_config('security.py', db=db) | 43 f = o(os.path.join(self.tracker_home, 'db', 'backend_name')) |
| 44 name = f.readline().strip() | |
| 45 f.close() | |
| 46 return getattr(backends, name) | |
| 45 | 47 |
| 48 def open(self, name): | |
| 49 backend = self.get_backend() | |
| 50 vars = { | |
| 51 'Class': backend.Class, | |
| 52 'FileClass': backend.FileClass, | |
| 53 'IssueClass': backend.IssueClass, | |
| 54 'String': hyperdb.String, | |
| 55 'Password': hyperdb.Password, | |
| 56 'Date': hyperdb.Date, | |
| 57 'Link': hyperdb.Link, | |
| 58 'Multilink': hyperdb.Multilink, | |
| 59 'Interval': hyperdb.Interval, | |
| 60 'Boolean': hyperdb.Boolean, | |
| 61 'Number': hyperdb.Number, | |
| 62 'db': backend.Database(self.config, name) | |
| 63 } | |
| 64 self._load_python('schema.py', vars) | |
| 65 db = vars['db'] | |
| 46 | 66 |
| 47 def _load_python(self, file): | 67 detectors_dir = os.path.join(self.tracker_home, 'detectors') |
| 68 for name in os.listdir(detectors_dir): | |
| 69 if not name.endswith('.py'): | |
| 70 continue | |
| 71 self._load_python(os.path.join('detectors', name), vars) | |
| 72 vars['init'](db) | |
| 73 | |
| 74 db.post_init() | |
| 75 return db | |
| 76 | |
| 77 def init(self, adminpw): | |
| 78 db = self.open('admin') | |
| 79 self._load_python('initial_data.py', {'db': db, 'adminpw': adminpw, | |
| 80 'admin_email': self.config['ADMIN_EMAIL']}) | |
| 81 db.commit() | |
| 82 db.close() | |
| 83 | |
| 84 def exists(self): | |
| 85 backend = self.get_backend() | |
| 86 return backend.db_exists(self.config) | |
| 87 | |
| 88 def nuke(self): | |
| 89 backend = self.get_backend() | |
| 90 backend.db_nuke(self.config) | |
| 91 | |
| 92 def _load_python(self, file, vars): | |
| 48 file = os.path.join(self.tracker_home, file) | 93 file = os.path.join(self.tracker_home, file) |
| 49 vars = Vars() | 94 execfile(file, vars) |
| 50 execfile(file, vars.__dict__) | |
| 51 return vars | 95 return vars |
| 52 | 96 |
| 97 def registerAction(self, name, action): | |
| 98 self.cgi_actions[name] = action | |
| 99 | |
| 100 def registerUtil(self, name, function): | |
| 101 self.templating_utils[name] = function | |
| 53 | 102 |
| 54 class TrackerError(Exception): | 103 class TrackerError(Exception): |
| 55 pass | 104 pass |
| 56 | 105 |
| 57 | 106 |
