From 415041be8d5fbe0c50eddaa0e61e85dd8c15f992 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Thu, 27 May 2021 02:32:19 +0200 Subject: [PATCH] Add support for new .toc client version suffixes: MyAddon-BCC.toc, MyAddon-Classic.toc, MyAddon-Mainline.toc. --- wau/addons.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wau/addons.py b/wau/addons.py index bd0b9dd..3f855ac 100644 --- a/wau/addons.py +++ b/wau/addons.py @@ -105,9 +105,11 @@ def find_addon_dirs(path: Path) -> Dict[str, Path]: addon_dirs = {} for p in level: tocs = list(p.glob("*.toc")) - if any(toc.stem == p.name for toc in tocs): + if any(Path(toc_stem(str(toc))).stem == p.name for toc in tocs): addon_dirs[p.name] = p - elif len(level) == 1 and len(tocs) == 1: + # using the length of the toc_stem set to allow multiple .tocs in the root, as long as they are identically + # named when the client version suffix is stripped + elif len(level) == 1 and len(set(toc_stem(str(t)) for t in tocs)) == 1: addon_dirs[tocs[0].stem] = p if addon_dirs: logger.debug("Found AddOn dirs: %s in '%s'", addon_dirs, path) @@ -119,6 +121,14 @@ def find_addon_dirs(path: Path) -> Dict[str, Path]: raise FileNotFoundError(f"No AddOn dirs found in {path}") +def toc_stem(toc: str): + """ + Removes AddOn .toc client version suffixes, such as '-Classic.toc' or '-BCC.toc'. + See https://github.com/Stanzilla/WoWUIBugs/issues/68#issuecomment-830351390 for more information. + """ + return re.sub(r"(.*)-(BCC|Classic|Mainline)(\.toc)", r"\1\3", toc) + + def get_valid_dir_filename(s: str) -> str: """ From https://github.com/django/django/blob/master/django/utils/text.py