From 907db555b4c84cde8e69db3c0390e50024d37f2a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 10 Dec 2013 17:06:49 -0500 Subject: [PATCH] module import helper --- devsupApp/src/devsup/db.py | 4 ++-- devsupApp/src/devsup/util.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/devsupApp/src/devsup/db.py b/devsupApp/src/devsup/db.py index 4017cae..c337682 100644 --- a/devsupApp/src/devsup/db.py +++ b/devsupApp/src/devsup/db.py @@ -1,7 +1,7 @@ import threading, sys, traceback, time -from devsup.util import Worker +from devsup.util import Worker, importmod try: import _dbapi @@ -326,5 +326,5 @@ def processLink(name, lstr): rec = getRecord(name) parts = lstr.split(None,1) modname, args = parts[0], parts[1] if len(parts)>1 else None - mod = __import__(modname, fromlist=['__should_not_exist']) + mod = importmod(modname) return rec, mod.build(rec, args) diff --git a/devsupApp/src/devsup/util.py b/devsupApp/src/devsup/util.py index 2907112..1ef5fdd 100644 --- a/devsupApp/src/devsup/util.py +++ b/devsupApp/src/devsup/util.py @@ -6,6 +6,17 @@ try: except ImportError: import queue +def importmod(modname): + """Import the named python module(s) + add return the leaf. + + >>> M=importmod('xml.sax') + >>> M.__name__ + 'xml.sax' + >>> + """ + return __import__(modname, fromlist=['__should_not_exist']) + class StoppableThread(threading.Thread): """A thread which can be requested to stop.