Created
June 13, 2017 17:49
-
-
Save cmattoon/2463dfef584e8587ab958dcb0f3a77e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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