Some of the yaml creator tools available now have a tendency to... complicate the look of the yaml file. So, I created a simple little program to convert This format Code: - Coordinates: - 15 - -89 - -778 Color: 0.8, 0.83, 0 Icon: Rhombus Playfields: - - 0, 0, 0 - Instanced Omicron Orbit - SpaceRingDebris - '' - - -10500, 0, 0 - Instanced Omicron - InstanceOmicron back to the Easy to read format that looks like Code: - Coordinates: [ -227, -89, -796 ] Color: 0.8, 0.83, 0 Icon: Rhombus Playfields: - [ "0, 0, 0", Instanced Cerberus Orbit, SpaceRingDebris ] - [ "-10500, 0, 0", Instanced Cerberus, InstanceCerberus ] https://drive.google.com/open?id=0BwtLXvAMvkc-LVdqUzJQRGVOZFU
Python code probably wouldnt help much but here it is anyways Code: import os global listname listname = "" global listdata listdata = [] mainlist = [] playfields = [] def makelist(line, listdata): if line.startswith(" - "): listdata.append(line[3:]) if line.startswith(" - "): if ":" in line: line2 = "'" + line[6:] + "'" listdata.append(line2) else: listdata.append(line[6:]) return listdata filename = os.path.join("Sectors" + ".yaml") fh = open("backup.yaml", "w") fh.write(" ") fh.close() with open(filename) as f: filedata = [line.strip('\n') for line in open(filename)] for line in filedata: fh = open("backup.yaml", "a") try: fh.write("\r") fh.write(line) except: junk = "junk" fh.close() if line.endswith(":"): if "Playfields" in line: mainlist.append(" Playfields:") elif len(listdata) > 0 : listdata = ", ".join(listdata) if listname == "Playfields": listname = " - [ " + listdata + " ]" else: listname = " " + listname + ": [ " + listdata + " ]" mainlist.append(listname) listdata = [] listname = line[2:-1] elif line.startswith(" - - "): if len(listdata) > 0: listdata = ", ".join(listdata) listdata = " - [ " + listdata + " ]" mainlist.append(listdata) playfields = "\"" + line[6:] + "\"" listdata = [] listdata.append(playfields) elif line.startswith(" - "): if "[" in line: mainlist.append(line) else: listdata = makelist(line, listdata) elif line.startswith(" - "): listdata = makelist(line, listdata) else: if len(listname) > 0: if len(listdata) > 0 : listdata = ", ".join(listdata) if listname == "Coordinates": mainlist.append("\r") listname = "- " + listname + ": [" + listdata + " ]" elif listname == "Playfields": listname = " - [ " + listdata + " ]" else: listname = " " + listname + ": [" + listdata + " ]" mainlist.append(listname) listdata = [] mainlist.append(line) for line in mainlist: print (line) fh = open("Sectors.yaml", "w") #fh.write("") fh.write("\n") fh.close() fh = open("Sectors.yaml", "a") for line in mainlist: try: fh.write(line) fh.write("\r") except: junk = "junk" fh.close()
New version I posted yesterday fixed all the bugs I knew about. If you find any bugs, please let me know