#!/usr/bin/env python # generate .mpc config import sys, re def parse_hostnames(hosts_file): """Read from stdin or a file given as the first command line argument and parse through a list of hosts that use the hostname convention typenum-site """ constellation = {} types = {} for hostname in hosts_file: hostname = hostname.strip() host_site = hostname.split('-', 1) if len(host_site) != 2: continue host, site = host_site type_num_pattern = re.compile(r"([A-Za-z_]+)([0-9]+)") type_num = type_num_pattern.match(host) type, num = type_num.groups() print site, type, num # how should this work? #types[type] = num #constellation[site] = types if __name__ == '__main__': if len(sys.argv) == 1: parse_hostnames(sys.stdin.readlines()) else: parse_hostnames(open(sys.argv[1]).readlines())