def create_list(taskset, all_tasks): """Creates a list of all the tasks that should be run. """ from bootstrapvz.common.phases import order # Make sure all_tasks is a superset of the resolved taskset if not all_tasks >= taskset: msg = ( 'bootstrap-vz generated a list of all available tasks. ' 'That list is not a superset of the tasks required for bootstrapping. ' 'The tasks that were not found are: {tasks} ' '(This is an error in the code and not the manifest, please report this issue.)' .format(tasks=', '.join(map(str, taskset - all_tasks)))) raise TaskListError(msg) # Create a graph over all tasks by creating a map of each tasks successors graph = {} for task in all_tasks: # Do a sanity check first check_ordering(task) successors = set() # Add all successors mentioned in the task successors.update(task.successors) # Add all tasks that mention this task as a predecessor successors.update( filter(lambda succ: task in succ.predecessors, all_tasks)) # Create a list of phases that succeed the phase of this task succeeding_phases = order[order.index(task.phase) + 1:] # Add all tasks that occur in above mentioned succeeding phases successors.update( filter(lambda succ: succ.phase in succeeding_phases, all_tasks)) # Map the successors to the task graph[task] = successors # Use the strongly connected components algorithm to check for cycles in our task graph components = strongly_connected_components(graph) cycles_found = 0 for component in components: # Node of 1 is also a strongly connected component but hardly a cycle, so we filter them out if len(component) > 1: cycles_found += 1 log.debug('Cycle: {list}\n' + (', '.join(map(repr, component)))) if cycles_found > 0: msg = ('{num} cycles were found in the tasklist, ' 'consult the logfile for more information.'.format( num=cycles_found)) raise TaskListError(msg) # Run a topological sort on the graph, returning an ordered list sorted_tasks = topological_sort(graph) # Filter out any tasks not in the tasklist # We want to maintain ordering, so we don't use set intersection sorted_tasks = filter(lambda task: task in taskset, sorted_tasks) return sorted_tasks
def create_list(taskset, all_tasks): """Creates a list of all the tasks that should be run. """ from bootstrapvz.common.phases import order # Make sure all_tasks is a superset of the resolved taskset if not all_tasks >= taskset: msg = ('bootstrap-vz generated a list of all available tasks. ' 'That list is not a superset of the tasks required for bootstrapping. ' 'The tasks that were not found are: {tasks} ' '(This is an error in the code and not the manifest, please report this issue.)' .format(tasks=', '.join(map(str, taskset - all_tasks))) ) raise TaskListError(msg) # Create a graph over all tasks by creating a map of each tasks successors graph = {} for task in all_tasks: # Do a sanity check first check_ordering(task) successors = set() # Add all successors mentioned in the task successors.update(task.successors) # Add all tasks that mention this task as a predecessor successors.update(filter(lambda succ: task in succ.predecessors, all_tasks)) # Create a list of phases that succeed the phase of this task succeeding_phases = order[order.index(task.phase) + 1:] # Add all tasks that occur in above mentioned succeeding phases successors.update(filter(lambda succ: succ.phase in succeeding_phases, all_tasks)) # Map the successors to the task graph[task] = successors # Use the strongly connected components algorithm to check for cycles in our task graph components = strongly_connected_components(graph) cycles_found = 0 for component in components: # Node of 1 is also a strongly connected component but hardly a cycle, so we filter them out if len(component) > 1: cycles_found += 1 log.debug('Cycle: {list}\n' + (', '.join(map(repr, component)))) if cycles_found > 0: msg = ('{num} cycles were found in the tasklist, ' 'consult the logfile for more information.'.format(num=cycles_found)) raise TaskListError(msg) # Run a topological sort on the graph, returning an ordered list sorted_tasks = topological_sort(graph) # Filter out any tasks not in the tasklist # We want to maintain ordering, so we don't use set intersection sorted_tasks = filter(lambda task: task in taskset, sorted_tasks) return sorted_tasks
def create_list(self): """Creates a list of all the tasks that should be run. """ from bootstrapvz.common.phases import order # Get a hold of all tasks tasks = self.get_all_tasks() # Make sure the taskset is a subset of all the tasks we have gathered self.tasks.issubset(tasks) # Create a graph over all tasks by creating a map of each tasks successors graph = {} for task in tasks: # Do a sanity check first self.check_ordering(task) successors = set() # Add all successors mentioned in the task successors.update(task.successors) # Add all tasks that mention this task as a predecessor successors.update(filter(lambda succ: task in succ.predecessors, tasks)) # Create a list of phases that succeed the phase of this task succeeding_phases = order[order.index(task.phase) + 1 :] # Add all tasks that occur in above mentioned succeeding phases successors.update(filter(lambda succ: succ.phase in succeeding_phases, tasks)) # Map the successors to the task graph[task] = successors # Use the strongly connected components algorithm to check for cycles in our task graph components = self.strongly_connected_components(graph) cycles_found = 0 for component in components: # Node of 1 is also a strongly connected component but hardly a cycle, so we filter them out if len(component) > 1: cycles_found += 1 log.debug("Cycle: {list}\n".format(list=", ".join(map(repr, component)))) if cycles_found > 0: msg = "{0} cycles were found in the tasklist, " "consult the logfile for more information.".format( cycles_found ) raise TaskListError(msg) # Run a topological sort on the graph, returning an ordered list sorted_tasks = self.topological_sort(graph) # Filter out any tasks not in the tasklist # We want to maintain ordering, so we don't use set intersection sorted_tasks = filter(lambda task: task in self.tasks, sorted_tasks) return sorted_tasks