Code

removed Log
[roundup.git] / roundup / instance.py
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.6 2002-09-10 00:18:20 richard 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 # vim: set filetype=python ts=4 sw=4 et si