Skip to content

Commit

Permalink
Add an MD5 hash to the tray menu icon
Browse files Browse the repository at this point in the history
Helpful when updating icons locally
  • Loading branch information
ungive committed Dec 6, 2024
1 parent 8f758f5 commit a7b5f00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 16 additions & 7 deletions scripts/2-icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import shutil
import json
import jsonschema
import hashlib
from collections import defaultdict
from typing import Optional
from PIL import Image, ImageDraw
Expand All @@ -51,6 +52,8 @@
OVERRIDES_SCHEMA = core.read_json(
os.path.join(INTERNAL_SCHEMA_PATH, "gen-overrides.schema.json")
)
# only hash the tray menu logo for now, to not inflate the resulting JSON
LABELS_TO_HASH = set(["tray-menu"])


class ImageType(enum.Enum):
Expand Down Expand Up @@ -419,6 +422,11 @@ def generate_icon(
return result_path


def md5hash(filename: str):
with open(filename, "rb") as f:
return hashlib.md5(f.read()).hexdigest()


if __name__ == "__main__":
output_json = True
if len(sys.argv) > 1:
Expand Down Expand Up @@ -450,13 +458,14 @@ def generate_icon(
)
)
assert path == f"{player}/{pathlib.Path(result.image_path).name}"
objects.append(
{
"label": result.label,
"type": result.image_type.value.lower(),
"url": f"{GEN_BASE_URL_ICONS}/{path}",
}
)
o = {
"label": result.label,
"type": result.image_type.value.lower(),
"url": f"{GEN_BASE_URL_ICONS}/{path}",
}
if result.label in LABELS_TO_HASH:
o["md5"] = md5hash(result.image_path)
objects.append(o)
output[player] = objects
if output_json:
json_output = json.dumps(output, separators=(",", ":"))
Expand Down
5 changes: 5 additions & 0 deletions src/schemas/icon.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"type": "string",
"format": "uri",
"pattern": "^https://\\S+[^/\\s]$"
},
"md5": {
"$comment": "MD5 hash of the file at the url",
"type": "string",
"pattern": "^[0-9a-f]{32}$"
}
}
}

0 comments on commit a7b5f00

Please sign in to comment.