예제 #1
0
    def __init__(self, subst_list=None, config_content=None, config_dict=None):
        if subst_list is None:
            raise ValueError('Failed to construct ErtWorkflowList with no substitution list')

        if config_content is None and config_dict is None:
            raise ValueError('Failed to construct ErtWorkflowList instance with no config object')

        if config_content is not None and config_dict is not None:
            raise ValueError('Failed to construct ErtWorkflowList instance with multiple config object')

        c_ptr = None

        if config_content is not None:
            c_ptr = self._alloc(subst_list, config_content)

        if config_dict is not None:
            workflow_joblist = WorkflowJoblist()
            parser = WorkflowJob.configParser( )
            for job in config_dict.get(ConfigKeys.LOAD_WORKFLOW_JOB, []):
                try:
                    new_job = WorkflowJob.fromFile(config_file=job['PATH'], name=job['NAME'], parser=parser)
                except:
                    print("WARNING: Unable to create job from {}".format(job['PATH']))
                    continue
                workflow_joblist.addJob(new_job)
                new_job.convertToCReference(None)

            for job_path in config_dict.get(ConfigKeys.WORKFLOW_JOB_DIRECTORY, []) :
                if not os.path.isdir(job_path):
                    print("WARNING: Unable to open job directory {}".format(job_path))
                    continue

                files = os.listdir(job_path)
                for file_name in files:
                    full_path = os.path.join(job_path, file_name)
                    try:
                        new_job = WorkflowJob.fromFile(config_file=full_path, parser=parser)
                        workflow_joblist.addJob(new_job)
                        new_job.convertToCReference(None)
                    except:
                        print("WARNING: Unable to create job from {}".format(full_path))
                        continue

            workflow_joblist.convertToCReference(None)

            c_ptr = self._alloc_full(subst_list, workflow_joblist )

        if c_ptr is None:
            raise ValueError('Failed to construct ErtWorkflowList instance')

        super(ErtWorkflowList, self).__init__(c_ptr)


        if config_dict is not None:
            for job in config_dict.get(ConfigKeys.LOAD_WORKFLOW, []):
                self.addWorkflow(job['PATH'], job['NAME'])
예제 #2
0
    def test_compare(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createInternalFunctionJob()

            parser = WorkflowJob.configParser()
            with self.assertRaises(IOError):
                workflow_job = WorkflowJob.fromFile("no/such/file")

            workflow_job = WorkflowJob.fromFile("compare_job",
                                                name="COMPARE",
                                                parser=parser)
            self.assertEqual(workflow_job.name(), "COMPARE")

            result = workflow_job.run(None, ["String", "string"])
            self.assertNotEqual(result, 0)

            result = workflow_job.run(None, ["String", "String"])
            # result is returned as c_void_p -> automatic conversion to None if value is 0
            self.assertIsNone(result)

            workflow_job = WorkflowJob.fromFile("compare_job")
            self.assertEqual(workflow_job.name(), "compare_job")