Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
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()