aboutsummaryrefslogtreecommitdiff
path: root/app/tasks/minetestcheck/tree.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-07-12 03:09:01 +0100
committerrubenwardy <rw@rubenwardy.com>2020-07-12 03:09:01 +0100
commita123f422911c7c543b35ca405ecb4524f905a1a9 (patch)
treef9afaca569e197829008fdad73902ea878c4c34e /app/tasks/minetestcheck/tree.py
parente6a7df6144b1d43124306851a66554db45a4ffa5 (diff)
downloadcheatdb-a123f422911c7c543b35ca405ecb4524f905a1a9.tar.xz
Fix incorrect mod name fold in MinetestCheck
Diffstat (limited to 'app/tasks/minetestcheck/tree.py')
-rw-r--r--app/tasks/minetestcheck/tree.py40
1 files changed, 26 insertions, 14 deletions
diff --git a/app/tasks/minetestcheck/tree.py b/app/tasks/minetestcheck/tree.py
index d078545..66dcbc8 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)
+
+ # 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, retval, type)
- def fold(self, attr, key=None, acc=None):
- if acc is None:
- acc = set()
-
- if self.meta is None:
- return acc
+ # Filter on type
+ if type and type != self.type:
+ return retval
+ # Get attribute
at = getattr(self, attr)
- value = at if key is None else at.get(key)
+ if not at:
+ return retval
+ # Get value
+ 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)
-
- for child in self.children:
- child.fold(attr, key, acc)
+ retval |= set(value)
+ elif value:
+ retval.add(value)
- return acc
+ return retval
def get(self, key):
return self.meta.get(key)