From: richard Date: Fri, 3 Aug 2001 00:59:34 +0000 (+0000) Subject: Instance import now imports the instance using imp.load_module so that X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ab21371d43bccbe5dfdce37cb45d7f33ad13f21c;p=roundup.git Instance import now imports the instance using imp.load_module so that we can have instance homes of "roundup" or other existing python package names. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@196 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/cgi-bin/roundup.cgi b/cgi-bin/roundup.cgi index e55dfbc..c1c0c0d 100755 --- a/cgi-bin/roundup.cgi +++ b/cgi-bin/roundup.cgi @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: roundup.cgi,v 1.5 2001-07-29 07:01:39 richard Exp $ +# $Id: roundup.cgi,v 1.6 2001-08-03 00:59:34 richard Exp $ # python version check import sys @@ -86,18 +86,14 @@ def main(instance, out): out, err = sys.stdout, sys.stderr try: sys.stdout = sys.stderr = LOG - import os, string + import os, string, imp 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] - module_path, instance = os.path.split(instance_home) - sys.path.insert(0, module_path) - try: - instance = __import__(instance) - finally: - del sys.path[0] + instance = imp.load_module('instance', None, instance_home, + ('', '', 5)) else: raise ValueError, 'No such instance "%s"'%instance main(instance, out) @@ -110,6 +106,9 @@ sys.stdout, sys.stderr = out, err # # $Log: not supported by cvs2svn $ +# Revision 1.5 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.4 2001/07/23 04:47:27 anthonybaxter # renamed ROUNDUPS to ROUNDUP_INSTANCE_HOMES # sys.exit(0) if python version wrong. diff --git a/roundup-admin b/roundup-admin index 9a39bc6..fbf6cac 100755 --- a/roundup-admin +++ b/roundup-admin @@ -1,12 +1,12 @@ #! /usr/bin/python -# $Id: roundup-admin,v 1.10 2001-07-30 08:12:17 richard Exp $ +# $Id: roundup-admin,v 1.11 2001-08-03 00:59:34 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 +import string, os, getpass, getopt, re, imp from roundup import date, roundupdb, init def usage(message=''): @@ -381,12 +381,7 @@ def main(): password = getpass.getpass(' password: ') # get the instance - path, instance = os.path.split(instance_home) - sys.path.insert(0, path) - try: - instance = __import__(instance) - finally: - del sys.path[0] + instance = imp.load_module('instance', None, instance_home, ('', '', 5)) function = figureCommands().get(command, None) @@ -409,6 +404,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.10 2001/07/30 08:12:17 richard +# Added time logging and file uploading to the templates. +# # Revision 1.9 2001/07/30 03:52:55 richard # init help now lists templates and backends # diff --git a/roundup-mailgw b/roundup-mailgw index 639dfe5..94a1d38 100755 --- a/roundup-mailgw +++ b/roundup-mailgw @@ -1,5 +1,5 @@ #! /usr/bin/python -# $Id: roundup-mailgw,v 1.2 2001-07-29 07:01:39 richard Exp $ +# $Id: roundup-mailgw,v 1.3 2001-08-03 00:59:34 richard Exp $ import sys if int(sys.version[0]) < 2: @@ -17,10 +17,8 @@ if not instance_home: sys.exit(1) # get the instance -path, instance = os.path.split(instance_home) -sys.path.insert(0, path) -instance = __import__(instance) -sys.path[0] +import imp +instance = imp.load_module('instance', None, instance_home, ('', '', 5)) # invokde the mail handler db = instance.open('admin') @@ -29,6 +27,9 @@ handler.main(sys.stdin) # # $Log: not supported by cvs2svn $ +# Revision 1.2 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.1 2001/07/23 03:46:48 richard # moving the bin files to facilitate out-of-the-boxness # diff --git a/roundup-server b/roundup-server index 9bebf8e..52f977f 100755 --- a/roundup-server +++ b/roundup-server @@ -3,7 +3,7 @@ Stolen from CGIHTTPServer -$Id: roundup-server,v 1.6 2001-07-29 07:01:39 richard Exp $ +$Id: roundup-server,v 1.7 2001-08-03 00:59:34 richard Exp $ """ import sys @@ -16,7 +16,7 @@ __version__ = "0.1" __all__ = ["RoundupRequestHandler"] -import os, urllib, StringIO, traceback, cgi, binascii, string, getopt +import os, urllib, StringIO, traceback, cgi, binascii, string, getopt, imp import BaseHTTPServer import SimpleHTTPServer @@ -98,12 +98,8 @@ 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] - module_path, instance = os.path.split(instance_home) - sys.path.insert(0, module_path) - try: - instance = __import__(instance) - finally: - del sys.path[0] + instance = imp.load_module('instance', None, instance_home, + ('', '', 5)) else: raise ValueError, 'No such instance "%s"'%instance @@ -261,6 +257,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.6 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.5 2001/07/24 01:07:59 richard # Added command-line arg handling to roundup-server so it's more useful # out-of-the-box. diff --git a/roundup/init.py b/roundup/init.py index b2300c8..11b69ba 100644 --- a/roundup/init.py +++ b/roundup/init.py @@ -1,6 +1,6 @@ -# $Id: init.py,v 1.8 2001-07-29 07:01:39 richard Exp $ +# $Id: init.py,v 1.9 2001-08-03 00:59:34 richard Exp $ -import os, shutil, sys, errno +import os, shutil, sys, errno, imp def copytree(src, dst, symlinks=0): """Recursively copy a directory tree using copy2(). @@ -31,7 +31,7 @@ def copytree(src, dst, symlinks=0): else: shutil.copy2(srcname, dstname) -def init(instance, template, backend, adminpw): +def init(instance_home, template, backend, adminpw): ''' initialise an instance using the named template ''' # first, copy the template dir over @@ -40,23 +40,24 @@ def init(instance, template, backend, adminpw): template_dir = os.path.split(__file__)[0] template_name = template template = os.path.join(template_dir, 'templates', template) - copytree(template, instance) + copytree(template, instance_home) - roundup.templatebuilder.installHtmlBase(template_name, instance) + roundup.templatebuilder.installHtmlBase(template_name, instance_home) # now select database db = '''# WARNING: DO NOT EDIT THIS FILE!!! from roundup.backends.back_%s import Database'''%backend - open(os.path.join(instance, 'select_db.py'), 'w').write(db) + open(os.path.join(instance_home, 'select_db.py'), 'w').write(db) # now import the instance and call its init - path, instance = os.path.split(instance) - sys.path.insert(0, path) - instance = __import__(instance) + instance = imp.load_module('instance', None, instance_home, ('', '', 5)) instance.init(adminpw) # # $Log: not supported by cvs2svn $ +# Revision 1.8 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.7 2001/07/28 07:59:53 richard # Replaced errno integers with their module values. # De-tabbed templatebuilder.py