summaryrefslogtreecommitdiffstats
path: root/dyn_module.py
diff options
context:
space:
mode:
authorChristos Triantafyllidis <christos.triantafyllidis@gmail.com>2012-06-12 00:49:17 +0300
committerChristos Triantafyllidis <christos.triantafyllidis@gmail.com>2012-06-12 00:49:17 +0300
commitcf9c34812219c3417d9e4d8af4cafaedd1e8988c (patch)
treecef1abdeae93887b20de84202b6d7cd42e713a72 /dyn_module.py
downloadDynamicNagiosConfig-cf9c34812219c3417d9e4d8af4cafaedd1e8988c.tar.gz
DynamicNagiosConfig-cf9c34812219c3417d9e4d8af4cafaedd1e8988c.tar.xz
DynamicNagiosConfig-cf9c34812219c3417d9e4d8af4cafaedd1e8988c.zip
Initial GIT import
Diffstat (limited to 'dyn_module.py')
-rw-r--r--dyn_module.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/dyn_module.py b/dyn_module.py
new file mode 100644
index 0000000..e12d744
--- /dev/null
+++ b/dyn_module.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import md5
+import os.path
+import imp
+import traceback
+import sys
+
+def load_module(code_path):
+ try:
+ try:
+ code_dir = os.path.dirname(code_path)
+ code_file = os.path.basename(code_path)
+
+ fin = open(code_path, 'rb')
+
+ return imp.load_source(md5.new(code_path).hexdigest(), code_path, fin)
+ finally:
+ try: fin.close()
+ except: pass
+ except ImportError, x:
+ traceback.print_exc(file = sys.stderr)
+ raise
+ except:
+ traceback.print_exc(file = sys.stderr)
+ raise
+