Change rule differences to columnar format for easier field comparison

- Display rule fields side-by-side in columns like other sections
- Makes it easier to compare State, Once, Length, Free, Rules, etc.
- Consistent formatting with rest of report
This commit is contained in:
Mike Geppert 2026-01-04 12:52:44 -06:00
parent 3ea2798857
commit c2800ce646

View File

@ -278,7 +278,7 @@ class DeviceComparison:
def _print_rule_differences(self, differences: List[Dict], device1_name: str, device2_name: str) -> None: def _print_rule_differences(self, differences: List[Dict], device1_name: str, device2_name: str) -> None:
""" """
Print rule differences in row format (device per row). Print rule differences in columnar format for easier field comparison.
Args: Args:
differences: List of difference dictionaries differences: List of difference dictionaries
@ -288,25 +288,48 @@ class DeviceComparison:
if not differences: if not differences:
return return
# Group differences by rule number
rules_by_number = {}
for diff in differences: for diff in differences:
rule_key = str(diff['key']) rule_key = str(diff['key'])
rules_by_number[rule_key] = diff
# Print each rule's details in columnar format
for rule_num in sorted(rules_by_number.keys()):
diff = rules_by_number[rule_num]
val1 = diff['device1_value'] val1 = diff['device1_value']
val2 = diff['device2_value'] val2 = diff['device2_value']
print(f"\n{rule_key}:") print(f"\n{rule_num}:")
# Print Device 1 # Extract all fields from both devices
print(f" {device1_name}:") if isinstance(val1, dict) and isinstance(val2, dict):
if isinstance(val1, dict): all_fields = set(val1.keys()) | set(val2.keys())
for key, value in val1.items():
print(f" {key}: {value}")
else:
print(f" {val1}")
# Print Device 2 # Calculate column widths
print(f" {device2_name}:") max_field_len = max(len(field) for field in all_fields) if all_fields else 10
if isinstance(val2, dict): field_width = max(max_field_len, 10)
for key, value in val2.items():
print(f" {key}: {value}") dev1_header = device1_name
else: dev2_header = device2_name
print(f" {val2}")
# Calculate value column widths
val1_width = max(len(dev1_header), 20)
val2_width = max(len(dev2_header), 20)
# Print header
print(f"{'Field':<{field_width}} {dev1_header:<{val1_width}} {dev2_header:<{val2_width}}")
print("-" * field_width + " " + "-" * val1_width + " " + "-" * val2_width)
# Print each field
for field in sorted(all_fields):
v1 = str(val1.get(field, 'N/A'))
v2 = str(val2.get(field, 'N/A'))
# Truncate if too long
if len(v1) > val1_width:
v1 = v1[:val1_width-3] + "..."
if len(v2) > val2_width:
v2 = v2[:val2_width-3] + "..."
print(f"{field:<{field_width}} {v1:<{val1_width}} {v2:<{val2_width}}")