예제 #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_workflow_joblist_creation(self):
        joblist = WorkflowJoblist()

        job = WorkflowJob("JOB1")

        joblist.addJob(job)

        self.assertTrue(job in joblist)
        self.assertTrue("JOB1" in joblist)

        job_ref = joblist["JOB1"]

        self.assertEqual(job.name(), job_ref.name())