[FIX] graph.py: correct Node() creation.
authorChristophe Simonis <chs@odoo.com>
Wed, 19 Nov 2014 14:14:14 +0000 (15:14 +0100)
committerChristophe Simonis <chs@odoo.com>
Wed, 19 Nov 2014 14:14:14 +0000 (15:14 +0100)
Fixes #3730

openerp/modules/graph.py

index 48666d9..3f7a00c 100644 (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)