コード例 #1
0
 def __loadPlugin(self):
     """@rtype: ErtPlugin"""
     script_obj = ErtScript.loadScriptFromFile(
         self.__workflow_job.getInternalScriptPath()
     )
     script = script_obj(self.__ert)
     return script
コード例 #2
0
ファイル: test_ert_script.py プロジェクト: oyvindeide/ert
    def test_ert_script_from_file(self):
        with TestAreaContext("python/job_queue/ert_script"):
            ErtScriptTest.createScripts()

            script_object = ErtScript.loadScriptFromFile("subtract_script.py")

            script = script_object("ert")
            result = script.initializeAndRun([int, int], ["1", "2"])
            self.assertEqual(result, -1)

            # with self.assertRaises(ErtScriptError):
            self.assertIsNone(
                ErtScript.loadScriptFromFile("syntax_error_script.py"))
            self.assertIsNone(
                ErtScript.loadScriptFromFile("import_error_script.py"))
            self.assertIsNone(ErtScript.loadScriptFromFile("empty_script.py"))
コード例 #3
0
    def isPlugin(self):
        """@rtype: bool"""
        if self.isInternalScript():
            script_obj = ErtScript.loadScriptFromFile(self.getInternalScriptPath())
            return script_obj is not None and issubclass(script_obj, ErtPlugin)

        return False
コード例 #4
0
    def run(self, ert, arguments, verbose=False):
        """
        @type ert: res.enkf.enkf_main.EnKFMain
        @type arguments: list of str
        @type verbose: bool
        @rtype: ctypes.c_void_p
        """
        self.__running = True

        min_arg = self.minimumArgumentCount()
        if min_arg > 0 and len(arguments) < min_arg:
            raise UserWarning(
                "The job: %s requires at least %d arguments, %d given."
                % (self.name(), min_arg, len(arguments))
            )

        max_arg = self.maximumArgumentCount()
        if 0 < max_arg < len(arguments):
            raise UserWarning(
                "The job: %s can only have %d arguments, %d given."
                % (self.name(), max_arg, len(arguments))
            )

        if self.isInternalScript():
            script_obj = ErtScript.loadScriptFromFile(self.getInternalScriptPath())
            self.__script = script_obj(ert)
            result = self.__script.initializeAndRun(
                self.argumentTypes(), arguments, verbose=verbose
            )

        elif self.isInternal() and not self.isInternalScript():
            self.__script = FunctionErtScript(
                ert,
                self.functionName(),
                self.argumentTypes(),
                argument_count=len(arguments),
            )
            result = self.__script.initializeAndRun(
                self.argumentTypes(), arguments, verbose=verbose
            )

        elif not self.isInternal():
            self.__script = ExternalErtScript(ert, self.executable())
            result = self.__script.initializeAndRun(
                self.argumentTypes(), arguments, verbose=verbose
            )

        else:
            raise UserWarning("Unknown script type!")

        self.__running = False
        return result
コード例 #5
0
ファイル: plugin.py プロジェクト: berland/ert
 def __loadPlugin(self):
     """ @rtype: ErtPlugin """
     script_obj = ErtScript.loadScriptFromFile(self.__workflow_job.getInternalScriptPath())
     script = script_obj(self.__ert)
     return script
コード例 #6
0
ファイル: plugins.py プロジェクト: berland/ert
 def getScript(self, plugin_job):
     script_obj = ErtScript.loadScriptFromFile(plugin_job.getInternalScriptPath())
     script = script_obj(self.ert())
     return script
コード例 #7
0
 def getScript(self, plugin_job):
     script_obj = ErtScript.loadScriptFromFile(
         plugin_job.getInternalScriptPath())
     script = script_obj(self.ert())
     return script