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.4 2001-11-12 22:01:06 richard Exp $
20 ''' Currently this module provides one function: open. This function opens
21 an instance.
22 '''
24 import imp, os
26 class Opener:
27 def __init__(self):
28 self.number = 0
29 self.instances = {}
31 def open(self, instance_home):
32 '''Open the instance.
34 Raise ValueError if the instance home doesn't exist.
35 '''
36 if not os.path.exists(instance_home):
37 raise ValueError, 'no such directory: "%s"'%instance_home
38 if self.instances.has_key(instance_home):
39 return imp.load_package(self.instances[instance_home],
40 instance_home)
41 self.number = self.number + 1
42 modname = '_roundup_instance_%s'%self.number
43 self.instances[instance_home] = modname
44 return imp.load_package(modname, instance_home)
46 opener = Opener()
47 open = opener.open
49 del Opener
50 del opener
53 #
54 # $Log: not supported by cvs2svn $
55 # Revision 1.3 2001/08/07 00:24:42 richard
56 # stupid typo
57 #
58 # Revision 1.2 2001/08/07 00:15:51 richard
59 # Added the copyright/license notice to (nearly) all files at request of
60 # Bizar Software.
61 #
62 # Revision 1.1 2001/08/05 07:43:52 richard
63 # Instances are now opened by a special function that generates a unique
64 # module name for the instances on import time.
65 #
66 #
67 #
68 # vim: set filetype=python ts=4 sw=4 et si