Improve MinetestCheck name validation

This commit is contained in:
rubenwardy 2020-08-18 13:34:04 +01:00
parent 6167bdc7f0
commit 0c81d0ae2b
3 changed files with 16 additions and 7 deletions

View File

@ -164,11 +164,11 @@ def updateMetaFromRelease(self, id, path):
def getMetaPackages(names):
return [ MetaPackage.GetOrCreate(x, cache) for x in names ]
provides = getMetaPackages(tree.getModNames())
provides = tree.getModNames()
package = release.package
package.provides.clear()
package.provides.extend(provides)
package.provides.extend(getMetaPackages(tree.getModNames()))
# Delete all meta package dependencies
package.dependencies.filter(Dependency.meta_package != None).delete()

View File

@ -24,14 +24,14 @@ class ContentType(Enum):
if self == ContentType.MOD:
if not other.isModLike():
raise MinetestCheckError("expected a mod or modpack, found " + other.value)
raise MinetestCheckError("Expected a mod or modpack, found " + other.value)
elif self == ContentType.TXP:
if other != ContentType.UNKNOWN and other != ContentType.TXP:
raise MinetestCheckError("expected a " + self.value + ", found a " + other.value)
elif other != self:
raise MinetestCheckError("expected a " + self.value + ", found a " + other.value)
raise MinetestCheckError("Expected a " + self.value + ", found a " + other.value)
from .tree import PackageTreeNode, get_base_dir

View File

@ -1,7 +1,9 @@
import os
import os, re
from . import MinetestCheckError, ContentType
from .config import parse_conf
basenamePattern = re.compile("^([a-z0-9_]+)$")
def get_base_dir(path):
if not os.path.isdir(path):
raise IOError("Expected dir")
@ -49,11 +51,16 @@ class PackageTreeNode:
if self.type == ContentType.GAME:
if not os.path.isdir(baseDir + "/mods"):
raise MinetestCheckError(("game at {} does not have a mods/ folder").format(self.relative))
raise MinetestCheckError(("Game at {} does not have a mods/ folder").format(self.relative))
self.add_children_from_mod_dir(baseDir + "/mods")
elif self.type == ContentType.MOD:
if self.name and not basenamePattern.match(self.name):
raise MinetestCheckError(("Invalid base name for mod {} at {}, names must only contain a-z0-9_.") \
.format(self.name, self.relative))
elif self.type == ContentType.MODPACK:
self.add_children_from_mod_dir(baseDir)
def getMetaFilePath(self):
filename = None
if self.type == ContentType.GAME:
@ -100,7 +107,6 @@ class PackageTreeNode:
else:
try:
import re
pattern = re.compile("^([a-z0-9_]+)\??$")
with open(self.baseDir + "/depends.txt", "r") as myfile:
@ -153,6 +159,9 @@ class PackageTreeNode:
raise MinetestCheckError(("Expecting mod or modpack, found {} at {} inside {}") \
.format(child.type.value, child.relative, self.type.value))
if child.name is None:
raise MinetestCheckError(("Missing base name for mod at {}").format(self.relative))
self.children.append(child)
def getModNames(self):