Skip to content
This repository was archived by the owner on Apr 9, 2026. It is now read-only.

Commit 20f7b57

Browse files
authored
Update edit_pack_mcmeta.py
1 parent bcc7867 commit 20f7b57

1 file changed

Lines changed: 88 additions & 53 deletions

File tree

.github/scripts/edit_pack_mcmeta.py

Lines changed: 88 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,121 @@
11
#!/usr/bin/env python3
2-
"""
3-
pack.mcmeta düzenleyici.
4-
Kullanım: edit_pack_mcmeta.py <pack_format> <supported_min> <supported_max>
5-
overlay_updates: GITHUB_EVENT_PATH üzerinden okunur (workflow_dispatch input).
6-
"""
72

83
import json
94
import os
105
import sys
6+
from typing import Dict, Any
117

128

13-
def main():
9+
def main() -> None:
1410
if len(sys.argv) < 4:
1511
print("Kullanım: edit_pack_mcmeta.py <pack_format> <supported_min> <supported_max>")
1612
sys.exit(1)
1713

18-
pf = int(sys.argv[1])
19-
smin = int(sys.argv[2])
20-
smax = int(sys.argv[3])
14+
try:
15+
pf = int(sys.argv[1])
16+
smin = int(sys.argv[2])
17+
smax = int(sys.argv[3])
18+
except ValueError:
19+
print("Hata: pack_format, supported_min ve supported_max tam sayı olmalıdır.")
20+
sys.exit(1)
2121

22-
# overlay_updates'i GITHUB_EVENT_PATH'ten oku (jq/heredoc sorunlarını önler)
22+
# GitHub Actions'tan overlay_updates girdisini oku
2323
overlay_raw = ""
2424
event_path = os.environ.get("GITHUB_EVENT_PATH", "")
2525
if event_path and os.path.exists(event_path):
26-
with open(event_path, "r", encoding="utf-8") as f:
27-
event = json.load(f)
28-
overlay_raw = event.get("inputs", {}).get("overlay_updates", "") or ""
26+
try:
27+
with open(event_path, "r", encoding="utf-8") as f:
28+
event = json.load(f)
29+
overlay_raw = event.get("inputs", {}).get("overlay_updates", "") or ""
30+
except (json.JSONDecodeError, IOError) as e:
31+
print(f"Uyarı: GitHub event dosyası okunamadı: {e}")
32+
33+
# pack.mcmeta dosyasını oku
34+
try:
35+
with open("pack.mcmeta", "r", encoding="utf-8") as f:
36+
meta: Dict[str, Any] = json.load(f)
37+
except FileNotFoundError:
38+
print("Hata: pack.mcmeta dosyası bulunamadı!")
39+
sys.exit(1)
40+
except json.JSONDecodeError as e:
41+
print(f"Hata: pack.mcmeta geçerli bir JSON değil: {e}")
42+
sys.exit(1)
2943

30-
with open("pack.mcmeta", "r", encoding="utf-8") as f:
31-
meta = json.load(f)
44+
pack = meta.setdefault("pack", {})
3245

33-
old_pf = meta["pack"]["pack_format"]
34-
old_smin = meta["pack"].get("supported_formats", {}).get("min_inclusive", "?")
35-
old_smax = meta["pack"].get("supported_formats", {}).get("max_inclusive", "?")
46+
# Eski değerleri kaydet (log için)
47+
old_pf = pack.get("pack_format")
48+
supported = pack.get("supported_formats", {})
49+
old_smin = supported.get("min_inclusive", "?")
50+
old_smax = supported.get("max_inclusive", "?")
3651

37-
meta["pack"]["pack_format"] = pf
38-
meta["pack"]["supported_formats"] = {
52+
# Ana pack_format ve supported_formats güncelle
53+
pack["pack_format"] = pf
54+
pack["supported_formats"] = {
3955
"min_inclusive": smin,
4056
"max_inclusive": smax,
4157
}
4258

43-
if "min_format" in meta["pack"]:
44-
meta["pack"]["min_format"] = smin
45-
if "max_format" in meta["pack"]:
46-
meta["pack"]["max_format"] = smax
59+
# Eski stil min_format / max_format varsa onları da güncelle (geriye uyumluluk)
60+
if "min_format" in pack:
61+
pack["min_format"] = smin
62+
if "max_format" in pack:
63+
pack["max_format"] = smax
4764

48-
print(f"pack_format : {old_pf}{pf}")
65+
print(f"pack_format : {old_pf}{pf}")
4966
print(f"supported_formats: [{old_smin}, {old_smax}] → [{smin}, {smax}]")
5067

68+
# Overlay'leri güncelle (varsa)
5169
if overlay_raw.strip():
52-
entries = {e["directory"]: e for e in meta.get("overlays", {}).get("entries", [])}
70+
entries: Dict[str, Dict[str, Any]] = {
71+
e["directory"]: e
72+
for e in meta.get("overlays", {}).get("entries", [])
73+
}
74+
5375
for line in overlay_raw.splitlines():
5476
line = line.strip()
5577
if not line or "=" not in line or ":" not in line:
5678
continue
57-
directory, fmt = line.split("=", 1)
58-
directory = directory.strip()
59-
o_min, o_max = fmt.strip().split(":", 1)
60-
o_min = int(o_min.strip())
61-
o_max = int(o_max.strip())
62-
63-
if directory in entries:
64-
old_fmt = entries[directory].get("formats", {})
65-
old_min = old_fmt.get("min_inclusive", "?")
66-
old_max = old_fmt.get("max_inclusive", "?")
67-
entries[directory]["formats"] = {
68-
"min_inclusive": o_min,
69-
"max_inclusive": o_max,
70-
}
71-
if "min_format" in entries[directory]:
72-
entries[directory]["min_format"] = o_min
73-
if "max_format" in entries[directory]:
74-
entries[directory]["max_format"] = o_max
75-
print(f"overlay '{directory}': [{old_min}, {old_max}] → [{o_min}, {o_max}]")
76-
else:
77-
print(f"WARN: overlay '{directory}' pack.mcmeta'da bulunamadı, atlandı.")
78-
79-
with open("pack.mcmeta", "w", encoding="utf-8") as f:
80-
json.dump(meta, f, indent=2, ensure_ascii=False)
81-
f.write("\n")
82-
83-
print("pack.mcmeta güncellendi.")
79+
80+
try:
81+
directory, fmt = [x.strip() for x in line.split("=", 1)]
82+
o_min_str, o_max_str = [x.strip() for x in fmt.split(":", 1)]
83+
84+
o_min = int(o_min_str)
85+
o_max = int(o_max_str)
86+
87+
if directory in entries:
88+
entry = entries[directory]
89+
old_fmt = entry.get("formats", {})
90+
old_min = old_fmt.get("min_inclusive", "?")
91+
old_max = old_fmt.get("max_inclusive", "?")
92+
93+
entry["formats"] = {
94+
"min_inclusive": o_min,
95+
"max_inclusive": o_max,
96+
}
97+
98+
if "min_format" in entry:
99+
entry["min_format"] = o_min
100+
if "max_format" in entry:
101+
entry["max_format"] = o_max
102+
103+
print(f"overlay '{directory}': [{old_min}, {old_max}] → [{o_min}, {o_max}]")
104+
else:
105+
print(f"WARN: overlay '{directory}' pack.mcmeta'da bulunamadı, atlandı.")
106+
107+
except (ValueError, IndexError) as e:
108+
print(f"WARN: Geçersiz overlay satırı atlandı: '{line}' ({e})")
109+
110+
# Güncellenmiş pack.mcmeta'yı yaz
111+
try:
112+
with open("pack.mcmeta", "w", encoding="utf-8") as f:
113+
json.dump(meta, f, indent=2, ensure_ascii=False)
114+
f.write("\n")
115+
print("✅ pack.mcmeta başarıyla güncellendi.")
116+
except IOError as e:
117+
print(f"Hata: pack.mcmeta yazılamadı: {e}")
118+
sys.exit(1)
84119

85120

86121
if __name__ == "__main__":

0 commit comments

Comments
 (0)