Added program to check for duplicate icon states in DMIs (#26359)

This commit is contained in:
DamianX
2020-05-12 16:06:35 +02:00
committed by GitHub
parent 92dd406174
commit d5db2fe0c2
3 changed files with 62 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
language: generic
dist: xenial
dist: bionic
sudo: false
env:
@@ -21,6 +21,7 @@ matrix:
- python3
- python3-pip
- python3-setuptools
- python3-pil
cache:
directories:
- $HOME/SpacemanDMM
@@ -30,6 +31,7 @@ matrix:
- tools/travis/install_spaceman_dmm.sh dreamchecker
script:
- python tools/travis/check_map_files.py maps/
- python3 tools/dmi-validhunt/dmi-validhunt.py icons/ || true
- find -name '*.dme' -exec cat {} \; | awk '/maps\\test.*/ { exit 1 }'
- ~/dreamchecker || true
- name: "Compile all maps"

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env python3
import sys
import os
from PIL import Image
"""
Find duplicate icon states in DMI files.
"""
__author__ = "Damian"
__version__ = "0.1.0"
__license__ = "WTFPL"
def file_contains_duplicate_icon_states(filename: str):
try:
image = Image.open(filename)
except:
print(f"{filename}: An error occurred opening this file.")
return True # whatever, you get the point, something's wrong
desc = image.info["Description"]
states = set()
output = False
for line in desc.splitlines():
if not line.startswith("state = \""):
continue
state_name = line[9:-1]
if state_name in states:
print(f"{filename}: duplicate icon state: {state_name}")
output = True
else:
states.add(state_name)
return output
def main():
if(len(sys.argv) != 2):
print("You must pass a file or directory as the first argument.")
sys.exit(1)
path = sys.argv[1]
if os.path.isfile(path):
sys.exit(file_contains_duplicate_icon_states(path))
elif os.path.isdir(path):
exit_code = 0
for root, dirs, files in os.walk(path):
for file in files:
if not file.endswith(".dmi"):
continue
if file_contains_duplicate_icon_states(os.path.join(root, file)):
exit_code += 1
sys.exit(exit_code)
else:
print("Argument was not a file nor a directory. What are you doing?")
sys.exit(-1)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1 @@
Pillow