Commit 97f9a182 authored by Vincent Pelletier's avatar Vincent Pelletier

Make it possible to get pt representation as text.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2131 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 97e9b77c
...@@ -231,6 +231,13 @@ class PartitionTable(object): ...@@ -231,6 +231,13 @@ class PartitionTable(object):
return self.num_filled_rows == self.np return self.num_filled_rows == self.np
def log(self): def log(self):
for line in self._format():
logging.debug(line)
def format(self):
return '\n'.join(self._format())
def _format(self):
"""Help debugging partition table management. """Help debugging partition table management.
Output sample: Output sample:
...@@ -249,6 +256,8 @@ class PartitionTable(object): ...@@ -249,6 +256,8 @@ class PartitionTable(object):
partition on the line (here, line length is 9 to keep the docstring partition on the line (here, line length is 9 to keep the docstring
width under 80 column). width under 80 column).
""" """
result = []
append = result.append
node_list = self.count_dict.keys() node_list = self.count_dict.keys()
node_list = [k for k, v in self.count_dict.items() if v != 0] node_list = [k for k, v in self.count_dict.items() if v != 0]
node_list.sort() node_list.sort()
...@@ -256,15 +265,15 @@ class PartitionTable(object): ...@@ -256,15 +265,15 @@ class PartitionTable(object):
for i, node in enumerate(node_list): for i, node in enumerate(node_list):
uuid = node.getUUID() uuid = node.getUUID()
node_dict[uuid] = i node_dict[uuid] = i
logging.debug('pt: node %d: %s, %s', i, dump(uuid), append('pt: node %d: %s, %s' % (i, dump(uuid),
protocol.node_state_prefix_dict[node.getState()]) protocol.node_state_prefix_dict[node.getState()]))
line = [] line = []
max_line_len = 20 # XXX: hardcoded number of partitions per line max_line_len = 20 # XXX: hardcoded number of partitions per line
cell_state_dict = protocol.cell_state_prefix_dict cell_state_dict = protocol.cell_state_prefix_dict
for offset, row in enumerate(self.partition_list): for offset, row in enumerate(self.partition_list):
if len(line) == max_line_len: if len(line) == max_line_len:
logging.debug('pt: %08d: %s', offset - max_line_len, append('pt: %08d: %s' % (offset - max_line_len,
'|'.join(line)) '|'.join(line)))
line = [] line = []
if row is None: if row is None:
line.append('X' * len(node_list)) line.append('X' * len(node_list))
...@@ -279,8 +288,9 @@ class PartitionTable(object): ...@@ -279,8 +288,9 @@ class PartitionTable(object):
cell.append('.') cell.append('.')
line.append(''.join(cell)) line.append(''.join(cell))
if len(line): if len(line):
logging.debug('pt: %08d: %s', offset - len(line) + 1, append('pt: %08d: %s' % (offset - len(line) + 1,
'|'.join(line)) '|'.join(line)))
return result
def operational(self): def operational(self):
if not self.filled(): if not self.filled():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment