#!/usr/bin/python ########################################## # # 9.14.08 Joe Mariglio (www.joemariglio.com) # # this should take an xml representation # of a network (made with matrixToXML) # and rename the plain integer nodes # with a list of proper names. # ########################################## import sys, string, os.path, getopt names = [] def rename(indoc, outfile, names): outdoc = indoc names = names.reverse() for name in names: outdoc = outdoc.replace(str(names.index(name)), name) return outdoc def getNames(nameString): names = nameString.split(' ') return names def usage(): print "usage:" print "matrixNames " print "name string should be in single quotes, space delimited." def main(argv): if len(sys.argv) == 4: #parse name string, delimiter ' ' nameString = sys.argv[3] names = getNames(nameString) #read in infile #input inpath = sys.argv[1] infile = open(inpath, "r") indoc = infile.read() #output outpath = sys.argv[2] outfile = open(outpath, "w") #rename integers with items in name array outdoc = rename(indoc, outfile, names) outfile.write(outdoc) #write out to outfile outfile.close() infile.close() else: usage() if __name__ == '__main__': import sys, string, os.path, getopt main(sys.argv[1:])