Factor error printing into one thing
This commit is contained in:
parent
3ef3321137
commit
c1c8890319
|
@ -51,33 +51,27 @@ def main():
|
||||||
# returns, we have correct arguments
|
# returns, we have correct arguments
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
with open(args.infile, 'r') as f:
|
||||||
with open(args.infile, 'r') as f:
|
known_host_entries = process_known_hosts.process_file(f, args.ignore_ips)
|
||||||
known_host_entries = process_known_hosts.process_file(f, args.ignore_ips)
|
|
||||||
except Exception as err:
|
|
||||||
print('Error: %s' % err, file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Convert to the entry format for .sshwot files
|
# Convert to the entry format for .sshwot files
|
||||||
entries = []
|
entries = []
|
||||||
for known_hosts_entry in known_host_entries:
|
for known_hosts_entry in known_host_entries:
|
||||||
entries.append(process_known_hosts.known_hosts_to_entry(known_hosts_entry))
|
entries.append(process_known_hosts.known_hosts_to_entry(known_hosts_entry))
|
||||||
|
|
||||||
|
if args.outfile is None:
|
||||||
|
# Write to stdout by default
|
||||||
|
# We use sys.stdout.buffer instead of just sys.stdout because we
|
||||||
|
# are writing binary data
|
||||||
|
write_file.write(sys.stdout.buffer, entries)
|
||||||
|
|
||||||
|
else:
|
||||||
|
with open(args.outfile, 'wb') as outf:
|
||||||
|
write_file.write(outf, entries)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
if args.outfile is None:
|
main()
|
||||||
# Write to stdout by default
|
|
||||||
# We use sys.stdout.buffer instead of just sys.stdout because we
|
|
||||||
# are writing binary data
|
|
||||||
write_file.write(sys.stdout.buffer, entries)
|
|
||||||
|
|
||||||
else:
|
|
||||||
with open(args.outfile, 'wb') as outf:
|
|
||||||
write_file.write(outf, entries)
|
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print('Error: %s' % err, file=sys.stderr)
|
print('Error: %s' % err, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue