A Python package for reading and writing World of Warcraft addon TOC files.
You can install this package via pip.
pip install wow-pytoc
Reading a TOC file:
from pytoc import *
file_path: str = "X:/path/to/my/addon.toc"
toc = TOCFile(file_path)
print(toc.Interface)
print(toc.Title)
print(toc.LocalizedTitle["frFR"])
print(toc.AdditionalFields["X-Website"])
for file in toc.Files:
file: TOCFileEntry
print(file)
if file.Conditions:
for condition in file.Conditions:
print(condition.export())
for dep in toc.Dependencies
dep: TOCDependency
print(f"Dependency Name: {dep.Name} Required: {dep.Required}")Writing a TOC file:
from pytoc import TOCFile
toc = TOCFile()
toc.Interface = 110000
toc.Author = "Ghost"
toc.Title = "My Addon"
toc.LocalizedTitle = {
"frFR": "Mon Addon",
}
toc.Files = [
TOCFileEntry("file1.lua"),
TOCFileEntry("file2.xml"),
TOCFileEntry("MainlineOnly.lua", [
TOCAllowLoadGameType({TOCGameType.Mainline})
]),
TOCFileEntry("PlunderstormGlueOnly.lua", [
TOCAllowLoadGameType({TOCGameType.Plunderstorm}),
TOCAllowLoadEnvironment({TOCEnvironment.Glue})
])
]
required = True
toc.add_dependency("totalRP3", required)
output = "path/to/dest.toc"
overwrite = True
toc.export(output, overwrite)For some examples, take a look at the test_toc.py file.
Note
- All dependency fields will be added to the
TOCFile.Dependencieslist. - Non-standard directives (that don't start with
X-) will be added directly to theTOCFileobject, but will not be exported. - Fields will overwrite eachother if more than one of that directive is present in the TOC file, taking the last found value.
- For certain fields that accept comma-delimited input, the attribute may end up being either a
listor astr|int, depending on if there are multiple values or just a single one. - Comments and empty lines will be ignored in the current parser and will not be preserved when exporting.