Mercurial > p > roundup > code
annotate roundup/instance.py @ 2701:460c07a2dff1
remove unused import
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Wed, 29 Sep 2004 07:26:17 +0000 |
| parents | d138df58b0c3 |
| children | 402d6d556558 |
| rev | line source |
|---|---|
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
1 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
3 # This module is free software, and you may redistribute it and/or modify |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
4 # under the same terms as Python, so long as this copyright message and |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
5 # disclaimer are retained in their original form. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
6 # |
| 214 | 7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
10 # POSSIBILITY OF SUCH DAMAGE. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
11 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
17 # |
|
2701
460c07a2dff1
remove unused import
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2697
diff
changeset
|
18 # $Id: instance.py,v 1.23 2004-09-29 07:26:17 a1s Exp $ |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1953
diff
changeset
|
20 '''Tracker handling (open tracker). |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
21 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
22 Backwards compatibility for the old-style "imported" trackers. |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 ''' |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1953
diff
changeset
|
24 __docformat__ = 'restructuredtext' |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
26 import os |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
27 from roundup import configuration, mailgw, rlog |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
28 from roundup import hyperdb, backends |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
29 from roundup.cgi import client |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
30 |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
31 class Vars: |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
32 def __init__(self, vars): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
33 self.__dict__.update(vars) |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
34 |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
35 class Tracker: |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
36 def __init__(self, tracker_home): |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
37 self.tracker_home = tracker_home |
|
2647
8c46091c36d0
Main Roundup configuration class renamed to CoreConfig.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2638
diff
changeset
|
38 self.config = configuration.CoreConfig(tracker_home) |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
39 self.cgi_actions = {} |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
40 self.templating_utils = {} |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
41 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
42 def get_backend(self): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
43 o = __builtins__['open'] |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
44 f = o(os.path.join(self.tracker_home, 'db', 'backend_name')) |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
45 name = f.readline().strip() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
46 f.close() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
47 return getattr(backends, name) |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
48 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
49 def open(self, name): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
50 backend = self.get_backend() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
51 vars = { |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
52 'Class': backend.Class, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
53 'FileClass': backend.FileClass, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
54 'IssueClass': backend.IssueClass, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
55 'String': hyperdb.String, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
56 'Password': hyperdb.Password, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
57 'Date': hyperdb.Date, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
58 'Link': hyperdb.Link, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
59 'Multilink': hyperdb.Multilink, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
60 'Interval': hyperdb.Interval, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
61 'Boolean': hyperdb.Boolean, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
62 'Number': hyperdb.Number, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
63 'db': backend.Database(self.config, name) |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
64 } |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
65 self._load_python('schema.py', vars) |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
66 db = vars['db'] |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
67 |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
68 self.load_interfaces() |
|
2638
18e86941c950
Load up extensions in the tracker "extensions" directory.
Richard Jones <richard@users.sourceforge.net>
parents:
2633
diff
changeset
|
69 self.load_extensions(db, 'detectors') |
|
18e86941c950
Load up extensions in the tracker "extensions" directory.
Richard Jones <richard@users.sourceforge.net>
parents:
2633
diff
changeset
|
70 self.load_extensions(self, 'extensions') |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
71 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
72 db.post_init() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
73 return db |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
74 |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
75 def load_interfaces(self): |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
76 """load interfaces.py (if any), initialize Client and MailGW attrs""" |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
77 vars = {} |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
78 if os.path.isfile(os.path.join(self.tracker_home, 'interfaces.py')): |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
79 self._load_python('interfaces.py', vars) |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
80 self.Client = vars.get('Client', client.Client) |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
81 self.MailGW = vars.get('MailGW', mailgw.MailGW) |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
82 |
|
2638
18e86941c950
Load up extensions in the tracker "extensions" directory.
Richard Jones <richard@users.sourceforge.net>
parents:
2633
diff
changeset
|
83 def load_extensions(self, parent, dirname): |
|
2688
eb14c12813a0
fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2677
diff
changeset
|
84 dirpath = os.path.join(self.tracker_home, dirname) |
|
eb14c12813a0
fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2677
diff
changeset
|
85 if os.path.isdir(dirpath): |
|
eb14c12813a0
fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2677
diff
changeset
|
86 for name in os.listdir(dirpath): |
|
2677
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
87 if not name.endswith('.py'): |
|
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
88 continue |
|
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
89 vars = {} |
|
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
90 self._load_python(os.path.join(dirname, name), vars) |
|
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
91 vars['init'](parent) |
|
2638
18e86941c950
Load up extensions in the tracker "extensions" directory.
Richard Jones <richard@users.sourceforge.net>
parents:
2633
diff
changeset
|
92 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
93 def init(self, adminpw): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
94 db = self.open('admin') |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
95 self._load_python('initial_data.py', {'db': db, 'adminpw': adminpw, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
96 'admin_email': self.config['ADMIN_EMAIL']}) |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
97 db.commit() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
98 db.close() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
99 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
100 def exists(self): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
101 backend = self.get_backend() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
102 return backend.db_exists(self.config) |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
103 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
104 def nuke(self): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
105 backend = self.get_backend() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
106 backend.db_nuke(self.config) |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
107 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
108 def _load_python(self, file, vars): |
|
2273
c77483d2cda4
merge from maint-0-7
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
109 file = os.path.join(self.tracker_home, file) |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
110 execfile(file, vars) |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
111 return vars |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
112 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
113 def registerAction(self, name, action): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
114 self.cgi_actions[name] = action |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
115 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
116 def registerUtil(self, name, function): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
117 self.templating_utils[name] = function |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
118 |
|
1162
86d41c31f9be
old habits...
Richard Jones <richard@users.sourceforge.net>
parents:
1158
diff
changeset
|
119 class TrackerError(Exception): |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
120 pass |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
121 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
122 |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
123 class OldStyleTrackers: |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 def __init__(self): |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
125 self.number = 0 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
126 self.trackers = {} |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
127 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
128 def open(self, tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
129 ''' Open the tracker. |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
130 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
131 Raise ValueError if the tracker home doesn't exist. |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
132 ''' |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
133 import imp |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
134 # sanity check existence of tracker home |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
135 if not os.path.exists(tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
136 raise ValueError, 'no such directory: "%s"'%tracker_home |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
137 |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
138 # sanity check tracker home contents |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
139 for reqd in 'config dbinit select_db interfaces'.split(): |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
140 if not os.path.exists(os.path.join(tracker_home, '%s.py'%reqd)): |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
141 raise TrackerError, 'File "%s.py" missing from tracker '\ |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
142 'home "%s"'%(reqd, tracker_home) |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
143 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
144 if self.trackers.has_key(tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
145 return imp.load_package(self.trackers[tracker_home], |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
146 tracker_home) |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
147 self.number = self.number + 1 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
148 modname = '_roundup_tracker_%s'%self.number |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
149 self.trackers[tracker_home] = modname |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
150 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
151 # load the tracker |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
152 tracker = imp.load_package(modname, tracker_home) |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
153 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
154 # ensure the tracker has all the required bits |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
155 for required in 'open init Client MailGW'.split(): |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
156 if not hasattr(tracker, required): |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
157 raise TrackerError, \ |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
158 'Required tracker attribute "%s" missing'%required |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
159 |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
160 # load and apply the config |
|
2647
8c46091c36d0
Main Roundup configuration class renamed to CoreConfig.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2638
diff
changeset
|
161 tracker.config = configuration.CoreConfig(tracker_home) |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
162 # FIXME! dbinit does "import config". |
|
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
163 # What would be the upgrade plan for existing trackers? |
|
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
164 tracker.dbinit.config = tracker.config |
|
2397
fa50e1347397
added basic logging support
Richard Jones <richard@users.sourceforge.net>
parents:
2273
diff
changeset
|
165 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
166 return tracker |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
167 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
168 OldStyleTrackers = OldStyleTrackers() |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
169 def open(tracker_home): |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
170 if os.path.exists(os.path.join(tracker_home, 'dbinit.py')): |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
171 # user should upgrade... |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
172 return OldStyleTrackers.open(tracker_home) |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
173 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
174 return Tracker(tracker_home) |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
175 |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
176 # vim: set filetype=python sts=4 sw=4 et si : |
