def temp(fileName=None): import psyco psyco.full() init(3) testClasses = (bosh.MreWrld, bosh.MreCell, bosh.MreAcre, bosh.MreAchr, bosh.MreRefr) loadFactory = bosh.LoadFactory(False, *testClasses) modInfo = bosh.modInfos[GPath(fileName)] modFile = bosh.ModFile(modInfo, loadFactory) modFile.load(True) strf = bosh.strFid for cb in modFile.CELL.cellBlocks: print cb.cell.full, strf(cb.cell.fid) cb.cell.setChanged() for attr in ("persistent", "temp", "distant"): # print ' ',attr for record in getattr(cb, attr): # print ' ',strf(record.fid) record.setChanged() for wb in modFile.WRLD.worldBlocks: print wb.world.full, strf(wb.world.fid) for cb in wb.cellBlocks: print ".", cb.cell.full, strf(cb.cell.fid) cb.cell.setChanged() for attr in ("persistent", "temp", "distant"): # print ' ',attr for record in getattr(cb, attr): # print ' ',strf(record.fid) record.setChanged() modFile.tes4.masters.append(modInfo.name) modFile.tes4.setChanged() outInfo = bosh.ModInfo(modInfo.dir, GPath("Wrye Dump.esp")) modFile.fileInfo = outInfo loadFactory.keepAll = True modFile.askSave() return for record in modFile.SCPT.getActiveRecords(): print record.eid out = GPath(record.eid + ".mws").open("w") out.write(record.scriptText) out.close() return # --Save to test file for testClass in testClasses: print testClass.classType for record in getattr(modFile, testClass.classType).records: # print record.eid if reBarExt.match(record.model.modPath): record.model.modPath = reBarExt.sub(r"Architecture\\BarabusCrypt", record.model.modPath) print record.eid, record.model.modPath record.setChanged() modFile.askSave(True)
def dumpPage(fileName, records, source=None, header=None): doLinks = source != "TSFC" # --Filter? if source: records = [x for x in records if re.match(source, x[1])] out = GPath(fileName).open("w") # --Header if header: out.write(header + "\n\n") out.write("'''Editors:''' Do not edit entries on this page. See [[Raw Function List]] for more info.\n\n") if doLinks: out.write("{{CompactTOC4}}\n") # --Sort records.sort(key=lambda x: x[0].lower()) current = "" links = ( "", " - [[#A|A]][[#B|B]][[#C|C]][[#D|D]][[#E|E]][[#F|F]][[#G|G]][[#H|H]][[#I|I]][[#J|J]][[#K|K]][[#L|L]][[#M|M]][[#N|N]][[#O|O]][[#P|P]][[#Q|Q]][[#R|R]][[#S|S]][[#T|T]][[#U|U]][[#V|V]][[#W|W]][[#X|X]][[#Y|Y]][[#Z|Z]]", )[doLinks] if source == "TSFC": links = "" for func, src, type, text in records: # --Alpha header if func[0].upper() != current: if current: out.write("|}\n\n") current = func[0].upper() if doLinks: out.write("===%s===\n" % current) out.write("{| width=100% class=functionTable\n|-\n") out.write("!align=left width=10%|Source\n") # out.write('!align=left width=10%|Type\n') out.write("!align=left width=35%|Function\n") # out.write('!align=left|Description ([[#top|Top]])\n') out.write("!align=left|Description" + links + "\n") # --Entry fields = (groupLink(src), "[[" + func + "]]", text) out.write("|-\n|" + (" || ".join(fields)) + "\n") if current: out.write("|}\n") out.write("\n[[Category:Scripting]]\n") out.close() print "Wrote", fileName
def csFunctions(fileName="CS Functions.txt"): """Generates various function tables for CS Wiki from a raw CSFunctions.csv file.""" records = [] functions = set() source_icol = {"Function": 0, "Source": 1, "Type": 2, "Description": 3} ins = GPath(fileName).open() for line in ins: line = re.sub("#.*", "", line.strip()) fields = line.split(";") fields = map(string.strip, fields) if fields and fields[0] and fields[0] != "Function": while len(fields) < 4: fields.append("") if not fields[1]: print " No source for", fields[0] if fields[0] in functions: print " Repeated function", fields[0] functions.add(fields[0]) records.append(fields) ins.close() print "Read", fileName # --Page writer def groupLink(group): group = re.sub("OBSE", "[[:Category:Fallout3_Script_Extender|OBSE]]", group) group = re.sub("Pluggy", "[[:Category:Pluggy|]]", group) group = re.sub("TSFC", "[[:Category:TSFC|]]", group) return group def dumpPage(fileName, records, source=None, header=None): doLinks = source != "TSFC" # --Filter? if source: records = [x for x in records if re.match(source, x[1])] out = GPath(fileName).open("w") # --Header if header: out.write(header + "\n\n") out.write("'''Editors:''' Do not edit entries on this page. See [[Raw Function List]] for more info.\n\n") if doLinks: out.write("{{CompactTOC4}}\n") # --Sort records.sort(key=lambda x: x[0].lower()) current = "" links = ( "", " - [[#A|A]][[#B|B]][[#C|C]][[#D|D]][[#E|E]][[#F|F]][[#G|G]][[#H|H]][[#I|I]][[#J|J]][[#K|K]][[#L|L]][[#M|M]][[#N|N]][[#O|O]][[#P|P]][[#Q|Q]][[#R|R]][[#S|S]][[#T|T]][[#U|U]][[#V|V]][[#W|W]][[#X|X]][[#Y|Y]][[#Z|Z]]", )[doLinks] if source == "TSFC": links = "" for func, src, type, text in records: # --Alpha header if func[0].upper() != current: if current: out.write("|}\n\n") current = func[0].upper() if doLinks: out.write("===%s===\n" % current) out.write("{| width=100% class=functionTable\n|-\n") out.write("!align=left width=10%|Source\n") # out.write('!align=left width=10%|Type\n') out.write("!align=left width=35%|Function\n") # out.write('!align=left|Description ([[#top|Top]])\n') out.write("!align=left|Description" + links + "\n") # --Entry fields = (groupLink(src), "[[" + func + "]]", text) out.write("|-\n|" + (" || ".join(fields)) + "\n") if current: out.write("|}\n") out.write("\n[[Category:Scripting]]\n") out.close() print "Wrote", fileName # --Dump pages dumpPage( "CS All.txt", records, None, "[[Category:Scripting]]\nThis page lists all scripting functions including OBSE and OBSE plugin functions.", ) dumpPage( "CS CS.txt", records, "CS", "[[Category:Scripting]]\nThis page lists all native CS scripting functions. For a more comprehensive list (including OBSE and OBSE plugin functions), see [[List of Functions]].", ) dumpPage( "CS OBSE.txt", records, "OBSE", "[[Category:Scripting]][[Category:Fallout3 Script Extender]]\nThis page lists all functions for [[:Category:Fallout3_Script_Extender|]]. For a more comprehensive list (including native CS and OBSE plugin functions), see [[List of Functions]].", ) dumpPage( "CS Pluggy.txt", records, "Pluggy", "[[Category:Scripting]][[Category:Pluggy]]\nThis page lists all functions for [[:Category:Pluggy|]]. For a more comprehesive list of functions (including native CS and other OBSE related functions), see [[List of Functions]].", ) dumpPage( "CS TSFC.txt", records, "TSFC", "[[Category:Scripting]][[Category:TSFC]]\nThis page lists all functions for [[:Category:TSFC|]]. For a more comprehesive list of functions (including native CS and other OBSE related functions), see [[List of Functions]].", )
def bookExport(fileName=None): """Export data from book to text file(s).""" fileName = GPath(fileName) init(3) # --Data from mod doImport = True modInfo = bosh.modInfos[fileName] loadFactory = bosh.LoadFactory(doImport, bosh.MreBook) modFile = bosh.ModFile(modInfo, loadFactory) modFile.load(True) data = {} texts = {} imported = {} # --Import Book texts if doImport: eid = None buffer = None reAt = re.compile("^@", re.M) reHeader = re.compile("== ?\[(\w+)\]") ins = GPath(fileName.root() + ".txt").open("r") reEndLine = re.compile("\n") for line in ins: maHeader = reHeader.match(line) if maHeader: if eid and buffer: imported[eid] = bosh.winNewLines(buffer.getvalue()) eid = maHeader.group(1) buffer = cStringIO.StringIO() addTags = True wasBlank = True firstLine = True blanks = "" elif buffer: if firstLine: firstLine = False addTags = "<" not in line if addTags: line = '<font face=1><div align="center">' + line isBlank = not bool(line.strip()) if addTags: line = reAt.sub('<div align="left">', line) line = reEndLine.sub("<br>\n", line) if isBlank: blanks += line else: buffer.write(blanks) buffer.write(line) blanks = "" ins.close() if eid and buffer: imported[eid] = bosh.winNewLines(buffer.getvalue()) # --Books from mod changed = False for book in modFile.BOOK.records: if doImport: newText = imported.get(book.eid) if newText and newText != book.text: print "Updating", book.eid book.text = newText book.setChanged() changed = True data[book.eid] = (book.eid, book.full, book.value, len(book.text)) texts[book.eid] = book.text # --Save import? if doImport and changed: modFile.askSave(True) # --Dump book info if False: textPath = GPath(fileName.root() + ".csv") out = textPath.open("w") # out.write('"Edit Id"\t"Name"\t"Value"\t"Text Len"\n') for eid in sorted(data): out.write('"%s"\t"%s"\t"%d"\t"%d"\n' % data[eid]) out.close() # --Dump Texts if True: reNewLine = re.compile("\r\n") out = GPath(fileName.root() + ".txt").open("w") for eid in sorted(data): text = reNewLine.sub("\n", texts[eid]) out.write("== [%s] %s\n" % data[eid][:2]) out.write(text) out.write("\n\n") out.close()