[FIX] graph.py: correct Node() creation.

Fixes #3730
This commit is contained in:
Christophe Simonis 2014-11-19 15:14:14 +01:00
parent c87b9c6539
commit 6bbc21b906
1 changed files with 10 additions and 5 deletions

View File

@ -56,7 +56,8 @@ class Graph(dict):
def add_node(self, name, info):
max_depth, father = 0, None
for n in [Node(x, self, None) for x in info['depends']]:
for d in info['depends']:
n = self.get(d) or Node(d, self, None) # lazy creation, do not use default value for get()
if n.depth >= max_depth:
father = n
max_depth = n.depth
@ -117,7 +118,6 @@ class Graph(dict):
later.clear()
current.remove(package)
node = self.add_node(package, info)
node.data = info
for kind in ('init', 'demo', 'update'):
if package in tools.config[kind] or 'all' in tools.config[kind] or kind in force:
setattr(node, kind, True)
@ -148,6 +148,8 @@ class Graph(dict):
yield module
level += 1
def __str__(self):
return '\n'.join(str(n) for n in self if n.depth == 0)
class Node(object):
""" One module in the modules dependency graph.
@ -162,18 +164,21 @@ class Node(object):
inst = graph[name]
else:
inst = object.__new__(cls)
inst.name = name
inst.info = info
graph[name] = inst
return inst
def __init__(self, name, graph, info):
self.name = name
self.graph = graph
self.info = info or getattr(self, 'info', {})
if not hasattr(self, 'children'):
self.children = []
if not hasattr(self, 'depth'):
self.depth = 0
self.info = info or {}
@property
def data(self):
return self.info
def add_child(self, name, info):
node = Node(name, self.graph, info)