From 6cdf1eba9682d241944f91aced4136c8b9794a30 Mon Sep 17 00:00:00 2001 From: Artem Kotik Date: Sat, 9 Nov 2024 19:19:09 +0100 Subject: [PATCH] Closes #84: Strip a lot of newlines in configs (#85) --- docs/colliecting-diffs.md | 3 +++ netbox_config_diff/compliance/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/colliecting-diffs.md b/docs/colliecting-diffs.md index 565c0bf..e9a9bef 100644 --- a/docs/colliecting-diffs.md +++ b/docs/colliecting-diffs.md @@ -42,6 +42,9 @@ If you have configs in NetBox DataSource, you can define it, the script instead !!! note Only synced DataSources are acceptable +!!! note + Diff replaces sequences of 3 or more empty lines with one empty line + If in your DataSource config names are different from the hostnames of the devices, you can specify config name with Jinja2 template in `Name template` field. Reference device with `{{ object }}` variable. diff --git a/netbox_config_diff/compliance/utils.py b/netbox_config_diff/compliance/utils.py index 24a17ef..8c89f54 100644 --- a/netbox_config_diff/compliance/utils.py +++ b/netbox_config_diff/compliance/utils.py @@ -40,8 +40,8 @@ def __init__(self, choices, *args, **kwargs): def get_unified_diff(rendered_config: str, actual_config: str, device: str) -> str: diff = unified_diff( - actual_config.splitlines(), - rendered_config.strip().splitlines(), + re.sub("\n{3,}", "\n", actual_config).splitlines(), + re.sub("\n{3,}", "\n", rendered_config).strip().splitlines(), fromfiledate=device, tofiledate=device, lineterm="",