Skip to content

Instantly share code, notes, and snippets.

@hughesjj
Created October 6, 2022 00:48
Show Gist options
  • Save hughesjj/4482e4b9143b2c801ed43c6174ab4dda to your computer and use it in GitHub Desktop.
Save hughesjj/4482e4b9143b2c801ed43c6174ab4dda to your computer and use it in GitHub Desktop.
def open_file(filename: str) -> str:
with open(filename) as fin:
return fin.read()
docker = open_file("redis-config-docker-default.txt")
local = open_file("redis-config-local-default.txt")
def to_datastructure(file_contents:str):
tokens = file_contents.split('\n')
if not tokens[-1]:
tokens.pop()
print(tokens)
i = 0
ds = {}
while i < len(tokens):
t = tokens[i]
# print(f"{t} {i}")
i += 1
v = tokens[i]
# print(f"{v} {i}")
i += 1
ds[t] = v
return ds
docker_config = to_datastructure(docker)
local_config = to_datastructure(local)
FILLER = 3*'\t'
values_mismatch = [
#(key, docker_config[key], local_config[key])
f"{key}{FILLER}{docker_config[key]}{FILLER}{local_config[key]}"
for key in docker_config.keys() & local_config.keys()
if docker_config[key] != local_config[key]
]
print(f"Keys in DOCKER but not in LOCAL: {','.join(docker_config.keys() - local_config.keys())}")
print(f"Keys in LOCAL but not in DOCKER: {','.join(local_config.keys() - docker_config.keys())}")
print(f"MISMATCHED VALUES: {','.join(local_config.keys() - docker_config.keys())}")
print("Key Docker Local\n" + '==='.join(3*[FILLER])+ "\n" +'\n'.join(values_mismatch))
@hughesjj
Copy link
Author

hughesjj commented Oct 6, 2022

Diff:

❯ python redisdiff.py
Keys in DOCKER but not in LOCAL:
Keys in LOCAL but not in DOCKER:
MISMATCHED VALUES:
Key Docker Local
                        ===                     ===
"protected-mode"                        "no"                    "yes"
"supervised"                    "no"                    "systemd"
"pidfile"                       ""                      "/var/run/redis_6379.pid"
"dir"                   "/data"                 "/var/lib/redis"
"bind"                  "* -::*"                        "127.0.0.1 -::1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment