Fix incorrect mod name fold in MinetestCheck

This commit is contained in:
rubenwardy 2020-07-12 03:09:01 +01:00
parent e6a7df6144
commit a123f42291
2 changed files with 30 additions and 18 deletions

@ -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"]:

@ -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)