Validate mod directory casing

This commit is contained in:
rubenwardy 2023-01-01 22:45:10 +00:00
parent 048b02db1d
commit 5e425cd29c

@ -58,11 +58,17 @@ class PackageTreeNode:
self.add_children_from_mod_dir("mods") self.add_children_from_mod_dir("mods")
elif self.type == ContentType.MOD: elif self.type == ContentType.MOD:
if self.name and not basenamePattern.match(self.name): if self.name and not basenamePattern.match(self.name):
raise MinetestCheckError("Invalid base name for mod {} at {}, names must only contain a-z0-9_." \ raise MinetestCheckError(f"Invalid base name for mod {self.name} at {self.relative}, names must only contain a-z0-9_.")
.format(self.name, self.relative)) self.check_dir_casing(["textures", "media", "sounds", "models", "locale"])
elif self.type == ContentType.MODPACK: elif self.type == ContentType.MODPACK:
self.add_children_from_mod_dir(None) self.add_children_from_mod_dir(None)
def check_dir_casing(self, dirs):
for dir in next(os.walk(self.baseDir))[1]:
lowercase = dir.lower()
if lowercase != dir and lowercase in dirs:
raise MinetestCheckError(f"Incorrect case, {dir} should be {lowercase} at {self.relative}{dir}")
def getReadMePath(self): def getReadMePath(self):
for filename in os.listdir(self.baseDir): for filename in os.listdir(self.baseDir):
path = os.path.join(self.baseDir, filename) path = os.path.join(self.baseDir, filename)