From f16cd1d498935b404fce38a88488a2068870c6ca Mon Sep 17 00:00:00 2001 From: "U-CAIS2006\\sonny" Date: Mon, 17 May 2010 14:23:35 +0800 Subject: [PATCH] added autoproduce graph --- observer.py | 12 ++++++++++-- p2prfd.py | 26 +++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/observer.py b/observer.py index 16d3588..8ce154d 100755 --- a/observer.py +++ b/observer.py @@ -20,6 +20,12 @@ class ObserverResource(twisted.web.resource.Resource): trees = {} last_name = 0 names = {} + graph_counter = 0 + def produce_graph(self, rss): + f = open('graph/graph%03d.dot' % self.graph_counter, 'w') + f.write(self.tree_pic_dot(self.trees[rss])) + f.close() + self.graph_counter += 1 def node_pic(self, node, tree): if node: name = self.names[node] @@ -46,11 +52,11 @@ class ObserverResource(twisted.web.resource.Resource): pass def node_dot(self, node, tree): retu = '' - if node in tree['child_left']: + if node in tree['child_left'] and tree['child_left'][node]: left_node = tree['child_left'][node] retu += self.names[node] + ' -> ' + self.names[left_node] + ';\n' retu += self.node_dot(left_node, tree) - if node in tree['child_right']: + if node in tree['child_right'] and tree['child_right'][node]: right_node = tree['child_right'][node] retu += self.names[node] + ' -> ' + self.names[right_node] + ';\n' retu += self.node_dot(right_node, tree) @@ -87,6 +93,7 @@ class ObserverResource(twisted.web.resource.Resource): else: self.trees[feed_url] = {'root': None, 'child_left': {}, 'child_right': {}} self.trees[feed_url]['root'] = root + self.produce_graph(feed_url) pass elif action == 'adopt_child': parent = eval(queries['parent'][0]); @@ -101,6 +108,7 @@ class ObserverResource(twisted.web.resource.Resource): elif loc == 'right': self.trees[feed_url]['child_right'][parent] = child pass + self.produce_graph(feed_url) pass else: rss = None diff --git a/p2prfd.py b/p2prfd.py index ab5bcab..a56f44e 100755 --- a/p2prfd.py +++ b/p2prfd.py @@ -144,14 +144,14 @@ class P2prfdProxy(twisted.web.resource.Resource): helper.del_key(self.child_left, feed_url) self.try_connection(try_actions, except_actions) if child_right: - try: + def try_actions(): self.notify_node(child_right, feed_url, content) - except: + def except_actions(): print 'right child %s error' % (repr(child_right)) #child_right = None self.observer.notify_adopt_child(feed_url, self.get_me(feed_url), None, 'right') helper.del_key(self.child_right, feed_url) - pass + self.try_connection(try_actions, except_actions) pass def update_feed(self, feed_url): if feed_url in self.parent_of: @@ -180,23 +180,21 @@ class P2prfdProxy(twisted.web.resource.Resource): if feed_url in self.child_right: child_right = self.child_right[feed_url] me = (self.ip_addr[feed_url], self.p2prfd_http_port) if child_left: - try: + def try_actions(): self.ping_node(child_left, feed_url) - except: + def except_actions(): print 'left child %s error' % (repr(child_left)) - child_left = None self.observer.notify_adopt_child(feed_url, self.get_me(feed_url), None, 'left') helper.del_key(self.child_left, feed_url) - pass + self.try_connection(try_actions, except_actions) if child_right: - try: + def try_actions(): self.ping_node(child_right, feed_url) - except: + def except_actions(): print 'right child %s error' % (repr(child_right)) - child_right = None self.observer.notify_adopt_child(feed_url, self.get_me(feed_url), None, 'right') helper.del_key(self.child_right, feed_url) - pass + self.try_connection(try_actions, except_actions) #print 'check result:' #print 'left child is %s' % (repr(child_left)) #print 'right child is %s' % (repr(child_right)) @@ -342,7 +340,8 @@ class P2prfdResource(twisted.web.resource.Resource): if child_left: try: left_info = self.get_node_info(child_left, feed_url) - except: + except Exception, exc: + print 'exceptione:', exc print 'left child %s error' % (repr(child_left)) child_left = None self.rsrc.observer.notify_adopt_child(feed_url, self.rsrc.get_me(feed_url), None, 'left') @@ -351,7 +350,8 @@ class P2prfdResource(twisted.web.resource.Resource): if child_right: try: right_info = self.get_node_info(child_right, feed_url) - except: + except Exception, exc: + print 'exceptione:', exc print 'right child %s error' % (repr(child_right)) child_right = None self.rsrc.observer.notify_adopt_child(feed_url, self.rsrc.get_me(feed_url), None, 'right') -- 2.11.4.GIT