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