Mercurial > p > roundup > code
annotate roundup/instance.py @ 1643:41dbd406a79c 0.6.0a1
*** empty log message ***
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 09 May 2003 05:28:42 +0000 |
| parents | 8e318dfaf479 |
| children | d2801a2b0a77 c4968040459e |
| 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. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
17 # |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
18 # $Id: instance.py,v 1.9 2002-09-20 01:20:31 richard Exp $ |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
20 __doc__ = ''' |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
21 Tracker handling (open tracker). |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
22 |
|
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
23 Currently this module provides one function: open. This function opens |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
24 a tracker. Note that trackers used to be called instances. |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 ''' |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
27 import imp, os |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 |
|
1162
86d41c31f9be
old habits...
Richard Jones <richard@users.sourceforge.net>
parents:
1158
diff
changeset
|
29 class TrackerError(Exception): |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
30 pass |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
31 |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 class Opener: |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 def __init__(self): |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 self.number = 0 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
35 self.trackers = {} |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
37 def open(self, tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
38 ''' Open the tracker. |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
39 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
40 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
|
41 ''' |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
42 # sanity check existence of tracker home |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
43 if not os.path.exists(tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
44 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
|
45 |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
46 # 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
|
47 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
|
48 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
|
49 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
|
50 '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
|
51 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
52 if self.trackers.has_key(tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
53 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
|
54 tracker_home) |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
55 self.number = self.number + 1 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
56 modname = '_roundup_tracker_%s'%self.number |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
57 self.trackers[tracker_home] = modname |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
58 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
59 # load the tracker |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
60 tracker = imp.load_package(modname, tracker_home) |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
61 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
62 # ensure the tracker has all the required bits |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
63 for required in 'config open init Client MailGW'.split(): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
64 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
|
65 raise TrackerError, \ |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
66 'Required tracker attribute "%s" missing'%required |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
67 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
68 return tracker |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 opener = Opener() |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
71 open = opener.open |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
72 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 del Opener |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 del opener |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
77 # vim: set filetype=python ts=4 sw=4 et si |
