mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 18:32:03 +00:00
Added program to check for duplicate icon states in DMIs (#26359)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
language: generic
|
language: generic
|
||||||
dist: xenial
|
dist: bionic
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -21,6 +21,7 @@ matrix:
|
|||||||
- python3
|
- python3
|
||||||
- python3-pip
|
- python3-pip
|
||||||
- python3-setuptools
|
- python3-setuptools
|
||||||
|
- python3-pil
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $HOME/SpacemanDMM
|
- $HOME/SpacemanDMM
|
||||||
@@ -30,6 +31,7 @@ matrix:
|
|||||||
- tools/travis/install_spaceman_dmm.sh dreamchecker
|
- tools/travis/install_spaceman_dmm.sh dreamchecker
|
||||||
script:
|
script:
|
||||||
- python tools/travis/check_map_files.py maps/
|
- 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 }'
|
- find -name '*.dme' -exec cat {} \; | awk '/maps\\test.*/ { exit 1 }'
|
||||||
- ~/dreamchecker || true
|
- ~/dreamchecker || true
|
||||||
- name: "Compile all maps"
|
- name: "Compile all maps"
|
||||||
|
|||||||
58
tools/dmi-validhunt/dmi-validhunt.py
Normal file
58
tools/dmi-validhunt/dmi-validhunt.py
Normal 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()
|
||||||
1
tools/dmi-validhunt/requirements.txt
Normal file
1
tools/dmi-validhunt/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Pillow
|
||||||
Reference in New Issue
Block a user