upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/tex_export.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/tex_export.py')
-rw-r--r--tools/tex_export.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/tools/tex_export.py b/tools/tex_export.py
index df5157b27..f7de7dd28 100644
--- a/tools/tex_export.py
+++ b/tools/tex_export.py
@@ -187,12 +187,33 @@ def main():
187 ap.add_argument("--limit", type=positive_int, help="export only the first N textures (N >= 1)") 187 ap.add_argument("--limit", type=positive_int, help="export only the first N textures (N >= 1)")
188 ap.add_argument("--png", action="store_true", help="also write a PNG beside each DDS dds_png.py can decode") 188 ap.add_argument("--png", action="store_true", help="also write a PNG beside each DDS dds_png.py can decode")
189 a = ap.parse_args() 189 a = ap.parse_args()
190 with open(a.index, encoding="utf-8") as f: 190 try:
191 texs = json.load(f) 191 with open(a.index, encoding="utf-8") as f:
192 texs.sort(key=lambda t: (t["archive"], t["gpu"])) 192 texs = json.load(f)
193 except (OSError, ValueError) as e:
194 print(f"ERROR: cannot read {a.index}: {e}", file=sys.stderr)
195 return 2
196 if not isinstance(texs, list):
197 print(f"ERROR: cannot read {a.index}: expected a texture list, got {type(texs).__name__}", file=sys.stderr)
198 return 2
199 try:
200 texs.sort(key=lambda t: (t["archive"], t["gpu"]))
201 except KeyError as e:
202 print(f"ERROR: cannot read {a.index}: row has no {e.args[0]!r}", file=sys.stderr)
203 return 2
204 except TypeError as e:
205 print(f"ERROR: cannot read {a.index}: {e}", file=sys.stderr)
206 return 2
193 if a.limit is not None: # 0 used to read as "no limit", and a negative N dropped the last N 207 if a.limit is not None: # 0 used to read as "no limit", and a negative N dropped the last N
194 texs = texs[: a.limit] 208 texs = texs[: a.limit]
195 os.makedirs(a.out, exist_ok=True) 209 if os.path.exists(a.out) and not os.path.isdir(a.out):
210 print(f"ERROR: {a.out} is a file, not a folder", file=sys.stderr)
211 return 2
212 try:
213 os.makedirs(a.out, exist_ok=True)
214 except OSError as e: # a report path under an existing file, or a dangling symlink
215 print(f"ERROR: cannot create {a.out}: {e.strerror or e}", file=sys.stderr)
216 return 2
196 res, cache, pngs = Counter(), {}, Counter() 217 res, cache, pngs = Counter(), {}, Counter()
197 for i, t in enumerate(texs, 1): 218 for i, t in enumerate(texs, 1):
198 try: 219 try: