2 def match_tags(box, all_tags, exact_tags):
3 """ returns True if box has required tags """
5 texact = set(exact_tags)
7 if texact and box.connections == texact:
10 if tall and tall.issubset(box.connections):
15 def find_boxes(box, all_tags = None, exact_tags = None, max_depth = 1):
16 """ Look for the connected boxes with the required tags, doing breath-first
17 search, until max_depth ( max_depth = None will traverse the entire graph ).
19 if not all_tags and not exact_tags:
20 msg = "No matching criteria for resources."
21 raise RuntimeError(msg)
24 # enqueue (depth, box)
35 (depth, a) = queue.pop()
36 if match_tags(a, all_tags, exact_tags):
39 if not max_depth or depth <= max_depth:
41 for b in sorted(a.connections):
42 if b not in traversed: