X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Finstance.py;h=b87334065a9589cf2a5cc1ea4235b3e752010c0c;hb=4def0a922471eab197908735446ad798faa5f2dc;hp=fb98b76537d1f9199f1efe93a0b1263763e35266;hpb=e8e0c9b06279ec296229fcbe2f1c308f4f67afb8;p=roundup.git diff --git a/roundup/instance.py b/roundup/instance.py index fb98b76..b873340 100644 --- a/roundup/instance.py +++ b/roundup/instance.py @@ -15,36 +15,57 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: instance.py,v 1.6 2002-09-10 00:18:20 richard Exp $ +# $Id: instance.py,v 1.9 2002-09-20 01:20:31 richard Exp $ __doc__ = ''' -Instance handling (open instance). +Tracker handling (open tracker). Currently this module provides one function: open. This function opens -an instance. +a tracker. Note that trackers used to be called instances. ''' import imp, os +class TrackerError(Exception): + pass + class Opener: def __init__(self): self.number = 0 - self.instances = {} + self.trackers = {} - def open(self, instance_home): - '''Open the instance. + def open(self, tracker_home): + ''' Open the tracker. - Raise ValueError if the instance home doesn't exist. + Raise ValueError if the tracker home doesn't exist. ''' - if not os.path.exists(instance_home): - raise ValueError, 'no such directory: "%s"'%instance_home - if self.instances.has_key(instance_home): - return imp.load_package(self.instances[instance_home], - instance_home) + # sanity check existence of tracker home + if not os.path.exists(tracker_home): + raise ValueError, 'no such directory: "%s"'%tracker_home + + # sanity check tracker home contents + for reqd in 'config dbinit select_db interfaces'.split(): + if not os.path.exists(os.path.join(tracker_home, '%s.py'%reqd)): + raise TrackerError, 'File "%s.py" missing from tracker '\ + 'home "%s"'%(reqd, tracker_home) + + if self.trackers.has_key(tracker_home): + return imp.load_package(self.trackers[tracker_home], + tracker_home) self.number = self.number + 1 - modname = '_roundup_instance_%s'%self.number - self.instances[instance_home] = modname - return imp.load_package(modname, instance_home) + modname = '_roundup_tracker_%s'%self.number + self.trackers[tracker_home] = modname + + # load the tracker + tracker = imp.load_package(modname, tracker_home) + + # ensure the tracker has all the required bits + for required in 'config open init Client MailGW'.split(): + if not hasattr(tracker, required): + raise TrackerError, \ + 'Required tracker attribute "%s" missing'%required + + return tracker opener = Opener() open = opener.open