From 0a5840bce6edf3df7c246241f5b12057c4d872d6 Mon Sep 17 00:00:00 2001
From: Sinisa Veseli <sveseli@aps.anl.gov>
Date: Mon, 13 Apr 2015 13:14:03 +0000
Subject: [PATCH] object instance creation method can now use provided import
 path

---
 src/python/dm/common/utility/objectUtility.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/python/dm/common/utility/objectUtility.py b/src/python/dm/common/utility/objectUtility.py
index 70c81533..ddba57b0 100755
--- a/src/python/dm/common/utility/objectUtility.py
+++ b/src/python/dm/common/utility/objectUtility.py
@@ -5,12 +5,20 @@ from dm.common.utility.loggingManager import LoggingManager
 class ObjectUtility:
 
     @classmethod
-    def createObjectInstance(cls, moduleName, className, constructor):
+    def createObjectInstance(cls, moduleName, className, constructor, importPath=None):
         logger = LoggingManager.getInstance().getLogger(cls.__name__)
         logger.debug('Creating object: %s, %s, %s' % (moduleName, className, constructor))
+        if importPath is not None:
+            # Add import path if it was provided
+            sys.path.append[importPath]
+
         cmd = 'from %s import %s' % (moduleName, className)
         exec cmd
         cmd = 'objectInstance = %s' % (constructor)
         exec cmd
+
+        if importPath is not None:
+            # Remove import path that was added
+            del sys.path[-1]
         return objectInstance
 
-- 
GitLab