<s> '''<STR_LIT>''' <EOL> import json <EOL> import core . marshal <EOL> import core . deptools <EOL> from core . bits import * <EOL> class TaskFactory ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , classes , dependency_strategy = core . deptools . DigraphDependencyStrategy ) : <EOL> self . classes = classes <EOL> self . dependency_strategy = dependency_strategy <EOL> def task_from_requirements ( self , requirements ) : <EOL> '''<STR_LIT>''' <EOL> items = self . dependency_strategy . instantiate_items ( self . classes ) <EOL> items = set ( items . values ( ) ) <EOL> items = self . dependency_strategy . filter_dependency_graph ( requirements , items ) <EOL> goal = TaskComplete ( self . dependency_strategy . find_goal_nodes ( items ) ) <EOL> items . add ( goal ) <EOL> assert set ( self . dependency_strategy . early_iter_all_items ( goal ) ) == items <EOL> assert goal . name == '<STR_LIT>' <EOL> items = self . dependency_strategy . make_group_dependencies_explicit_for_items ( items ) <EOL> assert goal in items <EOL> return Task ( items , requirements , goal ) <EOL> class ObjectItemLoader ( object ) : <EOL> '''<STR_LIT>''' <EOL> @ classmethod <EOL> def taskfactory_from_objects ( self , objects ) : <EOL> '''<STR_LIT>''' <EOL> classes = [ ] <EOL> marsh = core . marshal . ItemConverter ( ) <EOL> for o in objects : <EOL> self . check_sanity ( o ) <EOL> classes . append ( marsh . itemdict_to_item_class ( o ) ) <EOL> class_dict = dict ( ( cls . __name__ , cls ) for cls in classes ) <EOL> for cls in classes : <EOL> cls . depends = tuple ( class_dict [ marsh . normalise_item_name ( c ) ] for c in cls . depends ) <EOL> if issubclass ( cls , Group ) : <EOL> cls . contains = tuple ( class_dict [ marsh . normalise_item_name ( c ) ] for c in cls . contains ) <EOL> return TaskFactory ( classes ) <EOL> @ classmethod <EOL> def check_sanity ( self , objdict ) : <EOL> '''<STR_LIT>''' <EOL> name , group = objdict . get ( '<STR_LIT:name>' ) , objdict . get ( '<STR_LIT>' ) <EOL> if not name and not group : <EOL> raise ValueError ( '<STR_LIT>' , objdict ) <EOL> if name and group : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if group : <EOL> contains = objdict . get ( '<STR_LIT>' ) <EOL> if not contains : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if len ( contains ) == <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return True <EOL> class JSONItemLoader ( ObjectItemLoader ) : <EOL> '''<STR_LIT>''' <EOL> @ classmethod <EOL> def load_item_classes_from_file ( cls , f ) : <EOL> '''<STR_LIT>''' <EOL> return cls . taskfactory_from_objects ( json . load ( f ) ) <EOL> @ classmethod <EOL> def load_item_classes_from_string ( cls , data ) : <EOL> '''<STR_LIT>''' <EOL> return cls . taskfactory_from_objects ( json . loads ( data ) ) </s>
