Beispiel #1
0
    def run(self, ert, arguments, verbose=False):
        """
        @type ert: ert.enkf.enkf_main.EnKFMain
        @type arguments: list of str
        @type verbose: bool
        @rtype: ctypes.c_void_p
        """

        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)
            return 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))
            return self.__script.initializeAndRun(self.argumentTypes(), arguments, verbose=verbose)

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

        else:
            raise UserWarning("Unknown script type!")
Beispiel #2
0
class WorkflowJob(BaseCClass):

    def __init__(self, name, internal=True):
        c_ptr = WorkflowJob.cNamespace().alloc(name, internal)
        super(WorkflowJob, self).__init__(c_ptr)

        self.__script = None
        """ :type: ErtScript """

    def isInternal(self):
        """ @rtype: bool """
        return WorkflowJob.cNamespace().internal(self)

    def name(self):
        """ @rtype: str """
        return WorkflowJob.cNamespace().name(self)

    def minimumArgumentCount(self):
        """ @rtype: int """
        return WorkflowJob.cNamespace().min_arg(self)

    def maximumArgumentCount(self):
        """ @rtype: int """
        return WorkflowJob.cNamespace().max_arg(self)

    def functionName(self):
        """ @rtype: str """
        return WorkflowJob.cNamespace().get_function(self)

    def module(self):
        """ @rtype: str """
        return WorkflowJob.cNamespace().get_module(self)

    def executable(self):
        """ @rtype: str """
        return WorkflowJob.cNamespace().get_executable(self)

    def isInternalScript(self):
        """ @rtype: bool """
        return WorkflowJob.cNamespace().is_internal_script(self)

    def getInternalScriptPath(self):
        """ @rtype: str """
        return WorkflowJob.cNamespace().get_internal_script(self)

    def argumentTypes(self):
        """ @rtype: list of type """

        result = []
        for index in range(self.maximumArgumentCount()):
            t = WorkflowJob.cNamespace().arg_type(self, index)
            if t == ContentTypeEnum.CONFIG_BOOL:
                result.append(bool)
            elif t == ContentTypeEnum.CONFIG_FLOAT:
                result.append(float)
            elif t == ContentTypeEnum.CONFIG_INT:
                result.append(int)
            elif t == ContentTypeEnum.CONFIG_STRING:
                result.append(str)
            else:
                result.append(None)

        return result


    def run(self, ert, arguments, verbose=False):
        """
        @type ert: ert.enkf.enkf_main.EnKFMain
        @type arguments: list of str
        @type verbose: bool
        @rtype: ctypes.c_void_p
        """

        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)
            return 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))
            return self.__script.initializeAndRun(self.argumentTypes(), arguments, verbose=verbose)

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

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

    def cancel(self):
        if self.__script is not None:
            self.__script.cancel()

    def free(self):
        WorkflowJob.cNamespace().free(self)