1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
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"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: instance.py,v 1.9 2002-09-20 01:20:31 richard Exp $
20 __doc__ = '''
21 Tracker handling (open tracker).
23 Currently this module provides one function: open. This function opens
24 a tracker. Note that trackers used to be called instances.
25 '''
27 import imp, os
29 class TrackerError(Exception):
30 pass
32 class Opener:
33 def __init__(self):
34 self.number = 0
35 self.trackers = {}
37 def open(self, tracker_home):
38 ''' Open the tracker.
40 Raise ValueError if the tracker home doesn't exist.
41 '''
42 # sanity check existence of tracker home
43 if not os.path.exists(tracker_home):
44 raise ValueError, 'no such directory: "%s"'%tracker_home
46 # sanity check tracker home contents
47 for reqd in 'config dbinit select_db interfaces'.split():
48 if not os.path.exists(os.path.join(tracker_home, '%s.py'%reqd)):
49 raise TrackerError, 'File "%s.py" missing from tracker '\
50 'home "%s"'%(reqd, tracker_home)
52 if self.trackers.has_key(tracker_home):
53 return imp.load_package(self.trackers[tracker_home],
54 tracker_home)
55 self.number = self.number + 1
56 modname = '_roundup_tracker_%s'%self.number
57 self.trackers[tracker_home] = modname
59 # load the tracker
60 tracker = imp.load_package(modname, tracker_home)
62 # ensure the tracker has all the required bits
63 for required in 'config open init Client MailGW'.split():
64 if not hasattr(tracker, required):
65 raise TrackerError, \
66 'Required tracker attribute "%s" missing'%required
68 return tracker
70 opener = Opener()
71 open = opener.open
73 del Opener
74 del opener
77 # vim: set filetype=python ts=4 sw=4 et si