Skip to content

Instantly share code, notes, and snippets.

@cmattoon
Created June 13, 2017 17:49
Show Gist options
  • Save cmattoon/2463dfef584e8587ab958dcb0f3a77e1 to your computer and use it in GitHub Desktop.
Save cmattoon/2463dfef584e8587ab958dcb0f3a77e1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Creates a list of hosts from a CSV export of nodes
Usage: ./check_pe_csv path/to/csvfile
"""
import csv
import os
import sys
E_OK = 0
def main(csvfilename):
with open(csvfilename) as cf:
has_header = csv.Sniffer().has_header(cf.read(1024))
cf.seek(0)
reader = csv.reader(cf, delimiter=',', quotechar='"')
if has_header: next(reader)
hosts = sorted(set(map(lambda row: row[0], reader)))
sys.stdout.write(os.linesep.join(hosts))
sys.stdout.write(os.linesep)
return E_OK
if __name__ == '__main__':
exit(main(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment