aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/util.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-04-17 09:43:03 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-04-17 09:43:03 -0500
commitcb8ea0fe3f44f21c13e16f8d6363f56f31c52b27 (patch)
tree6ae0bb4be1a7aef42c4d2f34adb8c2f3c5cff160 /mediagoblin/util.py
parent904f61c2988af2e27701a9ea47140abab12624aa (diff)
downloadmediagoblin-cb8ea0fe3f44f21c13e16f8d6363f56f31c52b27.tar.lz
mediagoblin-cb8ea0fe3f44f21c13e16f8d6363f56f31c52b27.tar.xz
mediagoblin-cb8ea0fe3f44f21c13e16f8d6363f56f31c52b27.zip
Moved app.load_controller -> util.import_component and added tests.
Diffstat (limited to 'mediagoblin/util.py')
-rw-r--r--mediagoblin/util.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index bd509256..cf03a93e 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import sys
+
import jinja2
import mongokit
@@ -54,3 +56,19 @@ def setup_user_in_request(request):
request.session.invalidate()
request.user = user
+
+
+def import_component(import_string):
+ """
+ Import a module component defined by STRING. Probably a method,
+ class, or global variable.
+
+ Args:
+ - import_string: a string that defines what to import. Written
+ in the format of "module1.module2:component"
+ """
+ module_name, func_name = import_string.split(':', 1)
+ __import__(module_name)
+ module = sys.modules[module_name]
+ func = getattr(module, func_name)
+ return func