#!/bin/env python import os from Ft.Xml.Domlette import Print, NonvalidatingReader, implementation ADDON_PATH = "/home/jerry/wow/Interface/AddOns" UTF8_MARKER = "\xEF\xBB\xBF" def merge_lua_files(output, files): f = open(output, "w") for file in files: f.write("-- %s\n" % file) i = open(file, "r") for line in i.readlines(): f.write(line) i.close() f.close() def merge_xml_files(output, files): out = implementation.createDocument("http://www.blizzard.com/wow/ui/", "Ui", None) root = out.firstChild root.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "http://www.blizzard.com/wow/ui/../FrameXML/UI.xsd") for file in files: i = open(file, "r") doc = NonvalidatingReader.parseStream(i) i.close() root.appendChild(out.createComment(file)) child = doc.firstChild.firstChild while child: root.appendChild(child.cloneNode(True)) child = child.nextSibling o = open(output, "w") Print(out, o) o.close() for addon in os.listdir(ADDON_PATH): path = os.path.join(ADDON_PATH, addon) if os.path.isdir(path): toc = os.path.join(path, addon + ".toc") files = [] f = open(toc, "r") lines = f.readlines() f.close() f = open(toc, "w") for line in lines: if line[:3] == UTF8_MARKER: line = line[3:] if line[-2:] == '\r\n': line = line[:-2] elif line[-1:] == '\n': line = line[:-1] line = line.strip() if line[:1] == "#": f.write("%s\n" % line) elif len(line) > 0: n = os.path.join(path, line.replace("\\", os.sep)) if os.path.isfile(n): files.append(n) id = 1 while len(files): file = files[0] ext = os.path.splitext(file)[1] i = 1 while i < len(files) and os.path.splitext(files[i])[1] == ext: i += 1 if i == 1: f.write("%s\n" % files[0]) else: o = "content%d%s" % (id, ext) if ext == ".lua": merge_lua_files(os.path.join(path, o), files[:i]) elif ext == ".xml": merge_xml_files(os.path.join(path, o), files[:i]) else: raise "Invalid extension" f.write("# Merged "+", ".join(files[:i])+"\n") f.write("%s\n" % o) id += 1 files = files[i:] f.close()