示例#1
0
    def find_tasks_from_objects(self, objects, project):
        tasks = {}
        unconfirmed_tasks = {}
        if self.tag in self.history.keys():
            if 'tasks' in self.history[self.tag]:
                for t in self.history[self.tag]['tasks']:
                    logger.info("loading old task: %s" % t.get_object_name())
                    tasks[t.get_object_name()] = t

        #Build a list of all tasks
        task_list = [
            task for o in objects
            for task in ccm_cache.get_object(o, self.ccm).get_tasks()
        ]
        num_of_tasks = len(set(task_list))
        logger.info("Tasks with associated objects: %i" % num_of_tasks)

        task_util = TaskUtil(self.ccm)
        for t in set(task_list) - set(tasks.keys()):
            try:
                task = ccm_cache.get_object(t, self.ccm)
            except ccm_cache.ObjectCacheException:
                continue
            if task.status == 'completed':
                if task_util.task_in_project(task, project):
                    tasks[task.get_object_name()] = task
                else:
                    # try to add it anyway to see what happens...
                    unconfirmed_tasks[task.get_object_name()] = task
        # Add objects to tasks
        [
            t.add_object(o) for o in objects for t in tasks.values()
            if t.get_object_name() in ccm_cache.get_object(
                o, self.ccm).get_tasks()
        ]
        # Add objects to unconfirmed tasks
        [
            t.add_object(o) for o in objects
            for t in unconfirmed_tasks.values() if t.get_object_name() in
            ccm_cache.get_object(o, self.ccm).get_tasks()
        ]
        logger.info("Sanitizing tasks")
        tasks = sanitize_tasks(tasks, unconfirmed_tasks)

        logger.info("No of tasks in release %s: %i" %
                    (project.get_object_name(), len(tasks.keys())))
        self.history[self.tag]['tasks'] = tasks.values()
        fname = self.outputfile + '_' + self.tag + '_inc'
        self.persist_data(fname, self.history[self.tag])