sshwot/src/main-export-known-hosts.py

30 lines
767 B
Python
Raw Normal View History

2018-08-28 09:27:54 +00:00
import sys
import process_known_hosts
import write_file
def main():
# TODO: Handle errors
# TODO: Add a switch for whether you want to include IPs
2018-08-28 09:27:54 +00:00
with open(sys.argv[1], 'r') as f:
2018-08-29 11:04:07 +00:00
try:
known_host_entries = process_known_hosts.process_file(f)
2018-08-29 11:04:07 +00:00
except Exception as err:
print('Error: %s' % err, file=sys.stderr)
sys.exit(1)
2018-08-28 09:27:54 +00:00
# Convert to the entry format for .sshwot files
entries = []
for known_hosts_entry in known_host_entries:
entries.append(process_known_hosts.known_hosts_to_entry(known_hosts_entry))
2018-08-29 17:46:22 +00:00
# Write to stdout by default
# TODO: Add a way to change it
# We use sys.stdout.buffer instead of just sys.stdout because we
# are writing binary data
write_file.write(sys.stdout.buffer, entries)
2018-08-28 09:27:54 +00:00
if __name__ == '__main__':
main()