Skip to content

Commit 5de3a45

Browse files
author
Richard Jones
committed
re-worked detectors initialisation - woohoo, no more cross-importing!
1 parent e8709f2 commit 5de3a45

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

roundup/templates/classic/detectors/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: __init__.py,v 1.6 2002-09-11 21:39:17 richard Exp $
18+
#$Id: __init__.py,v 1.7 2003-02-20 07:04:55 richard Exp $
19+
20+
import sys, os, imp
1921

2022
def init(db):
2123
''' execute the init functions of all the modules in this directory
2224
'''
23-
import os, sys
2425
this_dir = os.path.split(__file__)[0]
25-
try:
26-
sys.path.insert(0, this_dir)
27-
for file in os.listdir(this_dir):
28-
file, ext = os.path.splitext(file)
29-
if file == '__init__':
30-
continue
31-
if ext == '.py':
32-
module = __import__(file)
33-
module.init(db)
34-
finally:
35-
del sys.path[0]
26+
for file in os.listdir(this_dir):
27+
path = os.path.join(this_dir, file)
28+
name, ext = os.path.splitext(file)
29+
if name == '__init__':
30+
continue
31+
if ext == '.py':
32+
module = imp.load_module(name, open(path), file,
33+
('.py', 'r', imp.PY_SOURCE))
34+
print (name, open(path), file, module)
35+
module.init(db)
3636

3737
# vim: set filetype=python ts=4 sw=4 et si

roundup/templates/minimal/detectors/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: __init__.py,v 1.1 2002-09-26 04:15:26 richard Exp $
18+
#$Id: __init__.py,v 1.2 2003-02-20 07:04:55 richard Exp $
19+
20+
import sys, os, imp
1921

2022
def init(db):
2123
''' execute the init functions of all the modules in this directory
2224
'''
23-
import os, sys
2425
this_dir = os.path.split(__file__)[0]
25-
try:
26-
sys.path.insert(0, this_dir)
27-
for file in os.listdir(this_dir):
28-
file, ext = os.path.splitext(file)
29-
if file == '__init__':
30-
continue
31-
if ext == '.py':
32-
module = __import__(file)
33-
module.init(db)
34-
finally:
35-
del sys.path[0]
26+
for file in os.listdir(this_dir):
27+
path = os.path.join(this_dir, file)
28+
name, ext = os.path.splitext(file)
29+
if name == '__init__':
30+
continue
31+
if ext == '.py':
32+
module = imp.load_module(name, open(path), file,
33+
('.py', 'r', imp.PY_SOURCE))
34+
print (name, open(path), file, module)
35+
module.init(db)
3636

3737
# vim: set filetype=python ts=4 sw=4 et si

0 commit comments

Comments
 (0)