From bd4bb53298087373923b93996a632d4586d90bda Mon Sep 17 00:00:00 2001 From: richard Date: Sun, 5 Aug 2001 07:44:36 +0000 Subject: [PATCH] Instances are now opened by a special function that generates a unique module name for the instances on import time. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@210 57a73879-2fb5-44c3-a270-3262357dd7e2 --- cgi-bin/roundup.cgi | 10 +++++++--- roundup-admin | 10 +++++++--- roundup-mailgw | 9 ++++++--- roundup-server | 8 ++++++-- roundup/init.py | 11 ++++++++--- roundup/instance.py | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 roundup/instance.py diff --git a/cgi-bin/roundup.cgi b/cgi-bin/roundup.cgi index 2cf8efa..4722f7b 100755 --- a/cgi-bin/roundup.cgi +++ b/cgi-bin/roundup.cgi @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: roundup.cgi,v 1.7 2001-08-03 01:28:33 richard Exp $ +# $Id: roundup.cgi,v 1.8 2001-08-05 07:43:52 richard Exp $ # python version check import sys @@ -86,13 +86,14 @@ def main(instance, out): out, err = sys.stdout, sys.stderr try: sys.stdout = sys.stderr = LOG - import os, string, imp + import os, string + import roundup.instance path = string.split(os.environ['PATH_INFO'], '/') instance = path[1] os.environ['PATH_INFO'] = string.join(path[2:], '/') if ROUNDUP_INSTANCE_HOMES.has_key(instance): instance_home = ROUNDUP_INSTANCE_HOMES[instance] - instance = imp.load_package('instance', instance_home) + instance = roundup.instance.open(instance_home) else: raise ValueError, 'No such instance "%s"'%instance main(instance, out) @@ -105,6 +106,9 @@ sys.stdout, sys.stderr = out, err # # $Log: not supported by cvs2svn $ +# Revision 1.7 2001/08/03 01:28:33 richard +# Used the much nicer load_package, pointed out by Steve Majewski. +# # Revision 1.6 2001/08/03 00:59:34 richard # Instance import now imports the instance using imp.load_module so that # we can have instance homes of "roundup" or other existing python package diff --git a/roundup-admin b/roundup-admin index 47ecd6c..3732165 100755 --- a/roundup-admin +++ b/roundup-admin @@ -1,13 +1,14 @@ #! /usr/bin/python -# $Id: roundup-admin,v 1.12 2001-08-03 01:28:33 richard Exp $ +# $Id: roundup-admin,v 1.13 2001-08-05 07:44:13 richard Exp $ import sys if int(sys.version[0]) < 2: print 'Roundup requires python 2.0 or later.' sys.exit(1) -import string, os, getpass, getopt, re, imp +import string, os, getpass, getopt, re from roundup import date, roundupdb, init +import roundup.instance def usage(message=''): if message: message = 'Problem: '+message+'\n' @@ -381,7 +382,7 @@ def main(): password = getpass.getpass(' password: ') # get the instance - instance = imp.load_package('instance', instance_home) + instance = roundup.instance.open(instance_home) function = figureCommands().get(command, None) @@ -404,6 +405,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.12 2001/08/03 01:28:33 richard +# Used the much nicer load_package, pointed out by Steve Majewski. +# # Revision 1.11 2001/08/03 00:59:34 richard # Instance import now imports the instance using imp.load_module so that # we can have instance homes of "roundup" or other existing python package diff --git a/roundup-mailgw b/roundup-mailgw index f359d5f..f7fd033 100755 --- a/roundup-mailgw +++ b/roundup-mailgw @@ -1,5 +1,5 @@ #! /usr/bin/python -# $Id: roundup-mailgw,v 1.4 2001-08-03 01:28:33 richard Exp $ +# $Id: roundup-mailgw,v 1.5 2001-08-05 07:44:25 richard Exp $ import sys if int(sys.version[0]) < 2: @@ -17,8 +17,8 @@ if not instance_home: sys.exit(1) # get the instance -import imp -instance = imp.load_package('instance', instance_home) +import roundup.instance +instance = roundup.instance.open(instance_home) # invokde the mail handler db = instance.open('admin') @@ -27,6 +27,9 @@ handler.main(sys.stdin) # # $Log: not supported by cvs2svn $ +# Revision 1.4 2001/08/03 01:28:33 richard +# Used the much nicer load_package, pointed out by Steve Majewski. +# # Revision 1.3 2001/08/03 00:59:34 richard # Instance import now imports the instance using imp.load_module so that # we can have instance homes of "roundup" or other existing python package diff --git a/roundup-server b/roundup-server index b4688e0..9b96638 100755 --- a/roundup-server +++ b/roundup-server @@ -3,7 +3,7 @@ Stolen from CGIHTTPServer -$Id: roundup-server,v 1.8 2001-08-03 01:28:33 richard Exp $ +$Id: roundup-server,v 1.9 2001-08-05 07:44:36 richard Exp $ """ import sys @@ -22,6 +22,7 @@ import SimpleHTTPServer # Roundup modules of use here from roundup import cgitb, cgi_client +import roundup.instance # ## Configuration @@ -98,7 +99,7 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): instance = urllib.unquote(l_path[1]) if self.ROUNDUP_INSTANCE_HOMES.has_key(instance): instance_home = self.ROUNDUP_INSTANCE_HOMES[instance] - instance = imp.load_package('instance', instance_home) + instance = roundup.instance.open(instance_home) else: raise ValueError, 'No such instance "%s"'%instance @@ -256,6 +257,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.8 2001/08/03 01:28:33 richard +# Used the much nicer load_package, pointed out by Steve Majewski. +# # Revision 1.7 2001/08/03 00:59:34 richard # Instance import now imports the instance using imp.load_module so that # we can have instance homes of "roundup" or other existing python package diff --git a/roundup/init.py b/roundup/init.py index 1d873d1..837bbcb 100644 --- a/roundup/init.py +++ b/roundup/init.py @@ -1,6 +1,8 @@ -# $Id: init.py,v 1.11 2001-08-04 22:42:43 richard Exp $ +# $Id: init.py,v 1.12 2001-08-05 07:43:52 richard Exp $ -import os, shutil, sys, errno, imp +import os, shutil, sys, errno + +import roundup.instance def copytree(src, dst, symlinks=0): """Recursively copy a directory tree using copy2(). @@ -50,11 +52,14 @@ from roundup.backends.back_%s import Database'''%backend open(os.path.join(instance_home, 'select_db.py'), 'w').write(db) # now import the instance and call its init - instance = imp.load_package('instance', instance_home) + instance = roundup.instance.open(instance_home) instance.init(adminpw) # # $Log: not supported by cvs2svn $ +# Revision 1.11 2001/08/04 22:42:43 richard +# Fixed sf.net bug #447671 - typo +# # Revision 1.10 2001/08/03 01:28:33 richard # Used the much nicer load_package, pointed out by Steve Majewski. # diff --git a/roundup/instance.py b/roundup/instance.py new file mode 100644 index 0000000..d81b938 --- /dev/null +++ b/roundup/instance.py @@ -0,0 +1,34 @@ +# $Id: instance.py,v 1.1 2001-08-05 07:43:52 richard Exp $ + +''' Currently this module provides one function: open. This function opens +an instance. +''' + +import imp + +class Opener: + def __init__(self): + self.number = 0 + self.instances = {} + + def open(self, instance_home): + if self.instances.has_key(instance_home): + return imp.load_package(self.instances[instance_home], + instance_home) + self.number = self.number + 1 + modname = '_roundup_instance_%s'%self.number + self.instances[instance_home] = modname + return imp.load_package(modname, instance_home) + +opener = Opener() +open = opener.open + +del Opener +del opener + + +# +# $Log: not supported by cvs2svn $ +# +# +# vim: set filetype=python ts=4 sw=4 et si -- 2.30.2