comparison roundup/instance.py @ 1158:30db4a11d700

sanity check instance attributes on open
author Richard Jones <richard@users.sourceforge.net>
date Tue, 17 Sep 2002 23:59:32 +0000
parents 9b910e8d987d
children 86d41c31f9be
comparison
equal deleted inserted replaced
1157:26c8cb2162d7 1158:30db4a11d700
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.6 2002-09-10 00:18:20 richard Exp $ 18 # $Id: instance.py,v 1.7 2002-09-17 23:59:32 richard Exp $
19 19
20 __doc__ = ''' 20 __doc__ = '''
21 Instance handling (open instance). 21 Tracker handling (open tracker).
22 22
23 Currently this module provides one function: open. This function opens 23 Currently this module provides one function: open. This function opens
24 an instance. 24 a tracker. Note that trackers used to be called instances.
25 ''' 25 '''
26 26
27 import imp, os 27 import imp, os
28 28
29 class InstanceError(Exception):
30 pass
31
29 class Opener: 32 class Opener:
30 def __init__(self): 33 def __init__(self):
31 self.number = 0 34 self.number = 0
32 self.instances = {} 35 self.trackers = {}
33 36
34 def open(self, instance_home): 37 def open(self, tracker_home):
35 '''Open the instance. 38 ''' Open the tracker.
36 39
37 Raise ValueError if the instance home doesn't exist. 40 Raise ValueError if the tracker home doesn't exist.
38 ''' 41 '''
39 if not os.path.exists(instance_home): 42 if not os.path.exists(tracker_home):
40 raise ValueError, 'no such directory: "%s"'%instance_home 43 raise ValueError, 'no such directory: "%s"'%tracker_home
41 if self.instances.has_key(instance_home): 44 if self.trackers.has_key(tracker_home):
42 return imp.load_package(self.instances[instance_home], 45 return imp.load_package(self.trackers[tracker_home],
43 instance_home) 46 tracker_home)
44 self.number = self.number + 1 47 self.number = self.number + 1
45 modname = '_roundup_instance_%s'%self.number 48 modname = '_roundup_tracker_%s'%self.number
46 self.instances[instance_home] = modname 49 self.trackers[tracker_home] = modname
47 return imp.load_package(modname, instance_home) 50
51 # load the tracker
52 tracker = imp.load_package(modname, tracker_home)
53
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 InstanceError, 'Required tracker attribute "%s" '\
58 'missing'%required
59
60 return tracker
48 61
49 opener = Opener() 62 opener = Opener()
50 open = opener.open 63 open = opener.open
51 64
52 del Opener 65 del Opener

Roundup Issue Tracker: http://roundup-tracker.org/