Skip to content

Commit bcfa9db

Browse files
author
Richard Jones
committed
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.
1 parent 1f795af commit bcfa9db

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

cgi-bin/roundup.cgi

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# $Id: roundup.cgi,v 1.5 2001-07-29 07:01:39 richard Exp $
2+
# $Id: roundup.cgi,v 1.6 2001-08-03 00:59:34 richard Exp $
33

44
# python version check
55
import sys
@@ -86,18 +86,14 @@ def main(instance, out):
8686
out, err = sys.stdout, sys.stderr
8787
try:
8888
sys.stdout = sys.stderr = LOG
89-
import os, string
89+
import os, string, imp
9090
path = string.split(os.environ['PATH_INFO'], '/')
9191
instance = path[1]
9292
os.environ['PATH_INFO'] = string.join(path[2:], '/')
9393
if ROUNDUP_INSTANCE_HOMES.has_key(instance):
9494
instance_home = ROUNDUP_INSTANCE_HOMES[instance]
95-
module_path, instance = os.path.split(instance_home)
96-
sys.path.insert(0, module_path)
97-
try:
98-
instance = __import__(instance)
99-
finally:
100-
del sys.path[0]
95+
instance = imp.load_module('instance', None, instance_home,
96+
('', '', 5))
10197
else:
10298
raise ValueError, 'No such instance "%s"'%instance
10399
main(instance, out)
@@ -110,6 +106,9 @@ sys.stdout, sys.stderr = out, err
110106

111107
#
112108
# $Log: not supported by cvs2svn $
109+
# Revision 1.5 2001/07/29 07:01:39 richard
110+
# Added vim command to all source so that we don't get no steenkin' tabs :)
111+
#
113112
# Revision 1.4 2001/07/23 04:47:27 anthonybaxter
114113
# renamed ROUNDUPS to ROUNDUP_INSTANCE_HOMES
115114
# sys.exit(0) if python version wrong.

roundup-admin

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#! /usr/bin/python
2-
# $Id: roundup-admin,v 1.10 2001-07-30 08:12:17 richard Exp $
2+
# $Id: roundup-admin,v 1.11 2001-08-03 00:59:34 richard Exp $
33

44
import sys
55
if int(sys.version[0]) < 2:
66
print 'Roundup requires python 2.0 or later.'
77
sys.exit(1)
88

9-
import string, os, getpass, getopt, re
9+
import string, os, getpass, getopt, re, imp
1010
from roundup import date, roundupdb, init
1111

1212
def usage(message=''):
@@ -381,12 +381,7 @@ def main():
381381
password = getpass.getpass(' password: ')
382382

383383
# get the instance
384-
path, instance = os.path.split(instance_home)
385-
sys.path.insert(0, path)
386-
try:
387-
instance = __import__(instance)
388-
finally:
389-
del sys.path[0]
384+
instance = imp.load_module('instance', None, instance_home, ('', '', 5))
390385

391386
function = figureCommands().get(command, None)
392387

@@ -409,6 +404,9 @@ if __name__ == '__main__':
409404

410405
#
411406
# $Log: not supported by cvs2svn $
407+
# Revision 1.10 2001/07/30 08:12:17 richard
408+
# Added time logging and file uploading to the templates.
409+
#
412410
# Revision 1.9 2001/07/30 03:52:55 richard
413411
# init help now lists templates and backends
414412
#

roundup-mailgw

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/python
2-
# $Id: roundup-mailgw,v 1.2 2001-07-29 07:01:39 richard Exp $
2+
# $Id: roundup-mailgw,v 1.3 2001-08-03 00:59:34 richard Exp $
33

44
import sys
55
if int(sys.version[0]) < 2:
@@ -17,10 +17,8 @@ if not instance_home:
1717
sys.exit(1)
1818

1919
# get the instance
20-
path, instance = os.path.split(instance_home)
21-
sys.path.insert(0, path)
22-
instance = __import__(instance)
23-
sys.path[0]
20+
import imp
21+
instance = imp.load_module('instance', None, instance_home, ('', '', 5))
2422

2523
# invokde the mail handler
2624
db = instance.open('admin')
@@ -29,6 +27,9 @@ handler.main(sys.stdin)
2927

3028
#
3129
# $Log: not supported by cvs2svn $
30+
# Revision 1.2 2001/07/29 07:01:39 richard
31+
# Added vim command to all source so that we don't get no steenkin' tabs :)
32+
#
3233
# Revision 1.1 2001/07/23 03:46:48 richard
3334
# moving the bin files to facilitate out-of-the-boxness
3435
#

roundup-server

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Stolen from CGIHTTPServer
55
6-
$Id: roundup-server,v 1.6 2001-07-29 07:01:39 richard Exp $
6+
$Id: roundup-server,v 1.7 2001-08-03 00:59:34 richard Exp $
77
88
"""
99
import sys
@@ -16,7 +16,7 @@ __version__ = "0.1"
1616

1717
__all__ = ["RoundupRequestHandler"]
1818

19-
import os, urllib, StringIO, traceback, cgi, binascii, string, getopt
19+
import os, urllib, StringIO, traceback, cgi, binascii, string, getopt, imp
2020
import BaseHTTPServer
2121
import SimpleHTTPServer
2222

@@ -98,12 +98,8 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
9898
instance = urllib.unquote(l_path[1])
9999
if self.ROUNDUP_INSTANCE_HOMES.has_key(instance):
100100
instance_home = self.ROUNDUP_INSTANCE_HOMES[instance]
101-
module_path, instance = os.path.split(instance_home)
102-
sys.path.insert(0, module_path)
103-
try:
104-
instance = __import__(instance)
105-
finally:
106-
del sys.path[0]
101+
instance = imp.load_module('instance', None, instance_home,
102+
('', '', 5))
107103
else:
108104
raise ValueError, 'No such instance "%s"'%instance
109105

@@ -261,6 +257,9 @@ if __name__ == '__main__':
261257

262258
#
263259
# $Log: not supported by cvs2svn $
260+
# Revision 1.6 2001/07/29 07:01:39 richard
261+
# Added vim command to all source so that we don't get no steenkin' tabs :)
262+
#
264263
# Revision 1.5 2001/07/24 01:07:59 richard
265264
# Added command-line arg handling to roundup-server so it's more useful
266265
# out-of-the-box.

roundup/init.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# $Id: init.py,v 1.8 2001-07-29 07:01:39 richard Exp $
1+
# $Id: init.py,v 1.9 2001-08-03 00:59:34 richard Exp $
22

3-
import os, shutil, sys, errno
3+
import os, shutil, sys, errno, imp
44

55
def copytree(src, dst, symlinks=0):
66
"""Recursively copy a directory tree using copy2().
@@ -31,7 +31,7 @@ def copytree(src, dst, symlinks=0):
3131
else:
3232
shutil.copy2(srcname, dstname)
3333

34-
def init(instance, template, backend, adminpw):
34+
def init(instance_home, template, backend, adminpw):
3535
''' initialise an instance using the named template
3636
'''
3737
# first, copy the template dir over
@@ -40,23 +40,24 @@ def init(instance, template, backend, adminpw):
4040
template_dir = os.path.split(__file__)[0]
4141
template_name = template
4242
template = os.path.join(template_dir, 'templates', template)
43-
copytree(template, instance)
43+
copytree(template, instance_home)
4444

45-
roundup.templatebuilder.installHtmlBase(template_name, instance)
45+
roundup.templatebuilder.installHtmlBase(template_name, instance_home)
4646

4747
# now select database
4848
db = '''# WARNING: DO NOT EDIT THIS FILE!!!
4949
from roundup.backends.back_%s import Database'''%backend
50-
open(os.path.join(instance, 'select_db.py'), 'w').write(db)
50+
open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
5151

5252
# now import the instance and call its init
53-
path, instance = os.path.split(instance)
54-
sys.path.insert(0, path)
55-
instance = __import__(instance)
53+
instance = imp.load_module('instance', None, instance_home, ('', '', 5))
5654
instance.init(adminpw)
5755

5856
#
5957
# $Log: not supported by cvs2svn $
58+
# Revision 1.8 2001/07/29 07:01:39 richard
59+
# Added vim command to all source so that we don't get no steenkin' tabs :)
60+
#
6061
# Revision 1.7 2001/07/28 07:59:53 richard
6162
# Replaced errno integers with their module values.
6263
# De-tabbed templatebuilder.py

0 commit comments

Comments
 (0)