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.8 2002-09-18 00:02:13 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 if not os.path.exists(tracker_home):
43 raise ValueError, 'no such directory: "%s"'%tracker_home
44 if self.trackers.has_key(tracker_home):
45 return imp.load_package(self.trackers[tracker_home],
46 tracker_home)
47 self.number = self.number + 1
48 modname = '_roundup_tracker_%s'%self.number
49 self.trackers[tracker_home] = modname
51 # load the tracker
52 tracker = imp.load_package(modname, tracker_home)
54 # ensure the tracker has all the required bits
55 for required in 'config open init Client MailGW'.split():
56 if not hasattr(tracker, required):
57 raise TrackerError, 'Required tracker attribute "%s" '\
58 'missing'%required
60 return tracker
62 opener = Opener()
63 open = opener.open
65 del Opener
66 del opener
69 # vim: set filetype=python ts=4 sw=4 et si