From a123f422911c7c543b35ca405ecb4524f905a1a9 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 12 Jul 2020 03:09:01 +0100 Subject: [PATCH] Fix incorrect mod name fold in MinetestCheck --- app/tasks/importtasks.py | 4 +-- app/tasks/minetestcheck/tree.py | 44 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 0568949e..1361afe3 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -161,7 +161,7 @@ def updateMetaFromRelease(self, id, path): def getMetaPackages(names): return [ MetaPackage.GetOrCreate(x, cache) for x in names ] - provides = getMetaPackages(tree.fold("name")) + provides = getMetaPackages(tree.getModNames()) package = release.package package.provides.clear() @@ -206,7 +206,7 @@ def getMeta(urlstr, author): result = {} result["name"] = tree.name - result["provides"] = tree.fold("name") + result["provides"] = tree.getModNames() result["type"] = tree.type.name for key in ["depends", "optional_depends"]: diff --git a/app/tasks/minetestcheck/tree.py b/app/tasks/minetestcheck/tree.py index d078545b..66dcbc8f 100644 --- a/app/tasks/minetestcheck/tree.py +++ b/app/tasks/minetestcheck/tree.py @@ -144,26 +144,38 @@ class PackageTreeNode: self.children.append(child) + def getModNames(self): + return self.fold("name", type=ContentType.MOD) - def fold(self, attr, key=None, acc=None): - if acc is None: - acc = set() - - if self.meta is None: - return acc - - at = getattr(self, attr) - value = at if key is None else at.get(key) - - if isinstance(value, list): - acc |= set(value) - elif value is not None: - acc.add(value) + # attr: Attribute name + # key: Key in attribute + # retval: Accumulator + # type: Filter to type + def fold(self, attr, key=None, retval=None, type=None): + if retval is None: + retval = set() + # Iterate through children for child in self.children: - child.fold(attr, key, acc) + child.fold(attr, key, retval, type) - return acc + # Filter on type + if type and type != self.type: + return retval + + # Get attribute + at = getattr(self, attr) + if not at: + return retval + + # Get value + value = at if key is None else at.get(key) + if isinstance(value, list): + retval |= set(value) + elif value: + retval.add(value) + + return retval def get(self, key): return self.meta.get(key)