diff --git a/src/Placeholders.py b/src/Placeholders.py index d0acb223..aecbb101 100644 --- a/src/Placeholders.py +++ b/src/Placeholders.py @@ -65,6 +65,10 @@ def read_input(self, xml): # magic word for "relative to HERON root" heron_path = hutils.get_heron_loc() self._target_file = os.path.abspath(self._source.replace('%HERON%', heron_path)) + elif self._source.startswith('%FARM%'): + # magic word for "relative to FARM root" + farm_path = hutils.get_farm_loc() + self._target_file = os.path.abspath(self._source.replace('%FARM%', farm_path)) else: # check absolute path rel_interp = os.path.abspath(os.path.join(self._workingDir, self._source)) diff --git a/src/_utils.py b/src/_utils.py index 99516261..3bad46d4 100644 --- a/src/_utils.py +++ b/src/_utils.py @@ -47,13 +47,28 @@ def get_cashflow_loc(raven_path=None): """ if raven_path is None: raven_path = get_raven_loc() - plugin_handler_dir = path.join(raven_path, '..', 'scripts') + plugin_handler_dir = path.join(raven_path, 'scripts') sys.path.append(plugin_handler_dir) plugin_handler = importlib.import_module('plugin_handler') sys.path.pop() cf_loc = plugin_handler.getPluginLocation('TEAL') return cf_loc +def get_farm_loc(raven_path=None): # Added by Haoyu Wang, May 25, 2022 + """ + Get FARM location in installed RAVEN + @ In, raven_path, string, optional, if given then start with this path + @ Out, cf_loc, string, location of CashFlow + """ + if raven_path is None: + raven_path = get_raven_loc() + plugin_handler_dir = path.join(raven_path, 'scripts') + sys.path.append(plugin_handler_dir) + plugin_handler = importlib.import_module('plugin_handler') + sys.path.pop() + farm_loc = plugin_handler.getPluginLocation('FARM') + return farm_loc + def get_all_resources(components): """ Provides a set of all resources used among all components diff --git a/src/validators/Factory.py b/src/validators/Factory.py index 6a998949..8288e09a 100644 --- a/src/validators/Factory.py +++ b/src/validators/Factory.py @@ -2,12 +2,33 @@ # ALL RIGHTS RESERVED from .ExampleValidator import Example +import os +import sys +# set up path of raven +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +import _utils as hutils +raven_path = hutils.get_raven_loc() + +# set up path of farm +farm_loc = hutils.get_farm_loc(raven_path=raven_path) +if farm_loc is not None: + farm_path = os.path.abspath(os.path.join(farm_loc)) + sys.path.append(farm_path) + from FARM.src.FARMValidatorsForHeron import FARM_Beta, FARM_Gamma_LTI, FARM_Gamma_FMU + +# default known validators known = { 'Example': Example, # ModelicaGoverner: TODO, } +# add farm validators to the known dictionary +if farm_loc is not None: + known['FARM_Beta'] = FARM_Beta + known['FARM_Gamma_LTI'] = FARM_Gamma_LTI + known['FARM_Gamma_FMU'] = FARM_Gamma_FMU + def get_class(typ): """ Returns the requested dispatcher type.