Sort knownhosts entries

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-10 00:33:28 +01:00
parent 5250a53078
commit 68433c1e59
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -54,13 +54,16 @@ def read_and_reduce():
def write_hosts_file(knownhosts):
# Replace known hosts with a cleaned version
with open(KNOWN_HOSTS, 'w') as f:
for key, host in knownhosts.items():
if len(host['hosts']) == 0:
continue
lines = []
for key, host in knownhosts.items():
if len(host['hosts']) == 0:
continue
host['hosts_joined'] = ",".join(sorted(host['hosts'], reverse=True))
f.write("{hosts_joined} {keytype} {fingerprint}\n".format(**host))
host['hosts_joined'] = ",".join(sorted(host['hosts'], reverse=True))
lines.append("{hosts_joined} {keytype} {fingerprint}".format(**host))
with open(KNOWN_HOSTS, 'w') as f:
f.write('\n'.join(sorted(lines)))
def main():