Skip to content

Commit 05c1846

Browse files
author
Richard Jones
committed
Instances are now opened by a special function...
...that generates a unique module name for the instances on import time.
1 parent 17fd2f6 commit 05c1846

File tree

6 files changed

+68
-14
lines changed

6 files changed

+68
-14
lines changed

cgi-bin/roundup.cgi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# $Id: roundup.cgi,v 1.7 2001-08-03 01:28:33 richard Exp $
2+
# $Id: roundup.cgi,v 1.8 2001-08-05 07:43:52 richard Exp $
33

44
# python version check
55
import sys
@@ -86,13 +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, imp
89+
import os, string
90+
import roundup.instance
9091
path = string.split(os.environ['PATH_INFO'], '/')
9192
instance = path[1]
9293
os.environ['PATH_INFO'] = string.join(path[2:], '/')
9394
if ROUNDUP_INSTANCE_HOMES.has_key(instance):
9495
instance_home = ROUNDUP_INSTANCE_HOMES[instance]
95-
instance = imp.load_package('instance', instance_home)
96+
instance = roundup.instance.open(instance_home)
9697
else:
9798
raise ValueError, 'No such instance "%s"'%instance
9899
main(instance, out)
@@ -105,6 +106,9 @@ sys.stdout, sys.stderr = out, err
105106

106107
#
107108
# $Log: not supported by cvs2svn $
109+
# Revision 1.7 2001/08/03 01:28:33 richard
110+
# Used the much nicer load_package, pointed out by Steve Majewski.
111+
#
108112
# Revision 1.6 2001/08/03 00:59:34 richard
109113
# Instance import now imports the instance using imp.load_module so that
110114
# we can have instance homes of "roundup" or other existing python package

roundup-admin

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#! /usr/bin/python
2-
# $Id: roundup-admin,v 1.12 2001-08-03 01:28:33 richard Exp $
2+
# $Id: roundup-admin,v 1.13 2001-08-05 07:44:13 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, imp
9+
import string, os, getpass, getopt, re
1010
from roundup import date, roundupdb, init
11+
import roundup.instance
1112

1213
def usage(message=''):
1314
if message: message = 'Problem: '+message+'\n'
@@ -381,7 +382,7 @@ def main():
381382
password = getpass.getpass(' password: ')
382383

383384
# get the instance
384-
instance = imp.load_package('instance', instance_home)
385+
instance = roundup.instance.open(instance_home)
385386

386387
function = figureCommands().get(command, None)
387388

@@ -404,6 +405,9 @@ if __name__ == '__main__':
404405

405406
#
406407
# $Log: not supported by cvs2svn $
408+
# Revision 1.12 2001/08/03 01:28:33 richard
409+
# Used the much nicer load_package, pointed out by Steve Majewski.
410+
#
407411
# Revision 1.11 2001/08/03 00:59:34 richard
408412
# Instance import now imports the instance using imp.load_module so that
409413
# we can have instance homes of "roundup" or other existing python package

roundup-mailgw

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/python
2-
# $Id: roundup-mailgw,v 1.4 2001-08-03 01:28:33 richard Exp $
2+
# $Id: roundup-mailgw,v 1.5 2001-08-05 07:44:25 richard Exp $
33

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

1919
# get the instance
20-
import imp
21-
instance = imp.load_package('instance', instance_home)
20+
import roundup.instance
21+
instance = roundup.instance.open(instance_home)
2222

2323
# invokde the mail handler
2424
db = instance.open('admin')
@@ -27,6 +27,9 @@ handler.main(sys.stdin)
2727

2828
#
2929
# $Log: not supported by cvs2svn $
30+
# Revision 1.4 2001/08/03 01:28:33 richard
31+
# Used the much nicer load_package, pointed out by Steve Majewski.
32+
#
3033
# Revision 1.3 2001/08/03 00:59:34 richard
3134
# Instance import now imports the instance using imp.load_module so that
3235
# we can have instance homes of "roundup" or other existing python package

roundup-server

Lines changed: 6 additions & 2 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.8 2001-08-03 01:28:33 richard Exp $
6+
$Id: roundup-server,v 1.9 2001-08-05 07:44:36 richard Exp $
77
88
"""
99
import sys
@@ -22,6 +22,7 @@ import SimpleHTTPServer
2222

2323
# Roundup modules of use here
2424
from roundup import cgitb, cgi_client
25+
import roundup.instance
2526

2627
#
2728
## Configuration
@@ -98,7 +99,7 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
9899
instance = urllib.unquote(l_path[1])
99100
if self.ROUNDUP_INSTANCE_HOMES.has_key(instance):
100101
instance_home = self.ROUNDUP_INSTANCE_HOMES[instance]
101-
instance = imp.load_package('instance', instance_home)
102+
instance = roundup.instance.open(instance_home)
102103
else:
103104
raise ValueError, 'No such instance "%s"'%instance
104105

@@ -256,6 +257,9 @@ if __name__ == '__main__':
256257

257258
#
258259
# $Log: not supported by cvs2svn $
260+
# Revision 1.8 2001/08/03 01:28:33 richard
261+
# Used the much nicer load_package, pointed out by Steve Majewski.
262+
#
259263
# Revision 1.7 2001/08/03 00:59:34 richard
260264
# Instance import now imports the instance using imp.load_module so that
261265
# we can have instance homes of "roundup" or other existing python package

roundup/init.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# $Id: init.py,v 1.11 2001-08-04 22:42:43 richard Exp $
1+
# $Id: init.py,v 1.12 2001-08-05 07:43:52 richard Exp $
22

3-
import os, shutil, sys, errno, imp
3+
import os, shutil, sys, errno
4+
5+
import roundup.instance
46

57
def copytree(src, dst, symlinks=0):
68
"""Recursively copy a directory tree using copy2().
@@ -50,11 +52,14 @@ def init(instance_home, template, backend, adminpw):
5052
open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
5153

5254
# now import the instance and call its init
53-
instance = imp.load_package('instance', instance_home)
55+
instance = roundup.instance.open(instance_home)
5456
instance.init(adminpw)
5557

5658
#
5759
# $Log: not supported by cvs2svn $
60+
# Revision 1.11 2001/08/04 22:42:43 richard
61+
# Fixed sf.net bug #447671 - typo
62+
#
5863
# Revision 1.10 2001/08/03 01:28:33 richard
5964
# Used the much nicer load_package, pointed out by Steve Majewski.
6065
#

roundup/instance.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# $Id: instance.py,v 1.1 2001-08-05 07:43:52 richard Exp $
2+
3+
''' Currently this module provides one function: open. This function opens
4+
an instance.
5+
'''
6+
7+
import imp
8+
9+
class Opener:
10+
def __init__(self):
11+
self.number = 0
12+
self.instances = {}
13+
14+
def open(self, instance_home):
15+
if self.instances.has_key(instance_home):
16+
return imp.load_package(self.instances[instance_home],
17+
instance_home)
18+
self.number = self.number + 1
19+
modname = '_roundup_instance_%s'%self.number
20+
self.instances[instance_home] = modname
21+
return imp.load_package(modname, instance_home)
22+
23+
opener = Opener()
24+
open = opener.open
25+
26+
del Opener
27+
del opener
28+
29+
30+
#
31+
# $Log: not supported by cvs2svn $
32+
#
33+
#
34+
# vim: set filetype=python ts=4 sw=4 et si

0 commit comments

Comments
 (0)