From fda75eea6c09e875d52f1c07b58a833d0ecd9bd8 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 13 Jul 2009 04:19:21 +0000 Subject: [PATCH] Move the text output of port diffs from the HostDiff class to the PortDiff class. --- ndiff/ndiff | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/ndiff/ndiff b/ndiff/ndiff index 2a93b58d8..35edb60d3 100755 --- a/ndiff/ndiff +++ b/ndiff/ndiff @@ -545,23 +545,8 @@ class HostDiff(object): port_table.append((mark, u"PORT", u"STATE", u"SERVICE", u"VERSION")) for port in self.ports: - diff = self.port_diffs[port] - a_columns = [diff.port_a.spec_string(), - diff.port_a.state_string(), - diff.port_a.service.name_string(), - diff.port_a.service.version_string()] - b_columns = [diff.port_b.spec_string(), - diff.port_b.state_string(), - diff.port_b.service.name_string(), - diff.port_b.service.version_string()] - if a_columns == b_columns: - if verbose: - port_table.append([u" "] + a_columns) - else: - if not host_a.is_extraports(diff.port_a.state): - port_table.append([u"-"] + a_columns) - if not host_b.is_extraports(diff.port_b.state): - port_table.append([u"+"] + b_columns) + port_diff = self.port_diffs[port] + port_diff.append_to_port_table(port_table, host_a, host_b) if len(port_table) > 1: print >> f, port_table @@ -723,6 +708,30 @@ class PortDiff(object): if self.port_a.service != self.port_b.service: self.cost += 1 + # PortDiffs are inserted into a Table and then printed, not printed out + # directly. That's why this class has append_to_port_table instead of + # print_text. + def append_to_port_table(self, table, host_a, host_b): + """Append this port diff to a Table containing five columns: + +- PORT STATE SERVICE VERSION + The "+-" stands for the diff indicator column.""" + a_columns = [self.port_a.spec_string(), + self.port_a.state_string(), + self.port_a.service.name_string(), + self.port_a.service.version_string()] + b_columns = [self.port_b.spec_string(), + self.port_b.state_string(), + self.port_b.service.name_string(), + self.port_b.service.version_string()] + if a_columns == b_columns: + if verbose: + table.append([u" "] + a_columns) + else: + if not host_a.is_extraports(self.port_a.state): + table.append([u"-"] + a_columns) + if not host_b.is_extraports(self.port_b.state): + table.append([u"+"] + b_columns) + def to_dom_fragment(self, document): frag = document.createDocumentFragment() portdiff_elem = document.createElement(u"portdiff")