From 9111aa1341fbd96175e1c61f39006f2bf8ee9841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Wisniewski?= <gregory@nexedi.com> Date: Wed, 30 Sep 2009 11:52:45 +0000 Subject: [PATCH] Change NodeManager.log() implementation, display one node per line with (or without) it's UUID and bind address if available. Implement '__gt__' to sort nodes per UUID by default. Reduce log verbosity by displaying nodes only one time per manager update. git-svn-id: https://svn.erp5.org/repos/neo/trunk@1323 71dcc9de-d417-0410-9af5-da40c76e7ee4 --- neo/node.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/neo/node.py b/neo/node.py index a1fbebce..4515bc9c 100644 --- a/neo/node.py +++ b/neo/node.py @@ -295,28 +295,21 @@ class NodeManager(object): node.setState(state) self.add(node) logging.info('create node %s %s %s %s' % log_args) - self.log() + self.log() def log(self): logging.debug('Node manager : %d nodes' % len(self._node_set)) - node_with_uuid = set(sorted(self._uuid_dict.values())) - node_without_uuid = self._node_set - node_with_uuid - for node in node_with_uuid | node_without_uuid: - if node.getUUID() is not None: - uuid = dump(node.getUUID()) - else: - uuid = '-' * 32 - args = ( - uuid, - node.getType(), - node.getState() - ) - logging.debug('nm: %s : %s/%s' % args) - for address, node in sorted(self._address_dict.items()): - args = ( - address, - node.getType(), - node.getState() - ) - logging.debug('nm: %s : %s/%s' % args) + for node in sorted(list(self._node_set)): + uuid = dump(node.getUUID()) or '-' * 32 + address = node.getAddress() or '' + if address: + address = '%s:%d' % address + logging.debug(' * %32s | %17s | %22s | %s' % ( + uuid, node.getType(), address, node.getState())) + + def __gt__(self, node): + # sort per UUID if defined + if self._uuid is not None: + return self._uuid > node.uuid + return self._address > node._address -- 2.30.9