#!/usr/bin/env python # generate .mpc config import sys, re def parse_hostnames(hostnames): constellation = {} type_num = {} for hostname in hostnames: hostname = hostname.strip() data = hostname.split('-', 1) if len(data) != 2: continue host, site = data type_num_pattern = re.compile(r"([A-Za-z_]+)([0-9]+)") type_num = type_num_pattern.match(host) type_num[] = type_num.groups() constellation[site] = type_num[] print constellation.keys() print constellation.values() if __name__ == '__main__': if len(sys.argv) == 1: parse_hostnames(sys.stdin.readlines()) else: parse_hostnames(open(sys.argv[1]).readlines())