@@ -52,8 +52,31 @@ def __prn_log(self, logger_level, text, timestamp=None):
5252 self .prn_txd = partial (__prn_log , self , 'TXD' )
5353 self .prn_rxd = partial (__prn_log , self , 'RXD' )
5454
55+ def get_PyCADI_path (self ):
56+ """ get the PyCADI path from the config file
57+ @return PyCADI path if setting exist
58+ @return None if not exist
59+ """
60+ if "PyCADI_path" in self .json_configs ["GLOBAL" ]:
61+ return self .json_configs ["GLOBAL" ][self .os ]["PyCADI_path" ]
62+ else :
63+ return None
64+
5565def check_import ():
5666 """ Append PVLIB_HOME to PATH, so import PyCADI fm.debug can be imported """
67+ warning_msgs = []
68+ from .fm_config import FastmodelConfig
69+ config = FastmodelConfig ()
70+
71+ fm_pycadi_path = config .get_PyCADI_path ()
72+ if fm_pycadi_path :
73+ if os .path .exists (fm_pycadi_path ):
74+ sys .path .append (fm_pycadi_path )
75+ else :
76+ warning_msgs .append ("Warning: Could not locate PyCADI_path '%s'" % fm_pycadi_path )
77+ else :
78+ warning_msgs .append ("Warning: PyCADI_path not set in settings.json" )
79+
5780 if 'PVLIB_HOME' in os .environ :
5881 #FastModels PyCADI have different folder on different host OS
5982 fm_pycadi_path1 = os .path .join (os .environ ['PVLIB_HOME' ], 'lib' , 'python27' )
@@ -63,13 +86,15 @@ def check_import():
6386 elif os .path .exists (fm_pycadi_path2 ):
6487 sys .path .append (fm_pycadi_path2 )
6588 else :
66- print "Warning: Could not locate PyCADI in PVLIB_HOME/lib/python27"
89+ warning_msgs . append ( "Warning: Could not locate PyCADI in PVLIB_HOME/lib/python27" )
6790 else :
68- print "Warning: PVLIB_HOME not exist, check your fastmodel installation!"
91+ warning_msgs . append ( "Warning: ' PVLIB_HOME' environment variable not been set." )
6992
7093 try :
7194 import fm .debug
7295 except ImportError as e :
96+ for warning in warning_msgs :
97+ print warning
7398 print "Error: Failed to import fast models PyCADI!!!"
7499 return False
75100 else :
0 commit comments