upleb.uk

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

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorOlaiFG7 <156535605+OlaiFG7@users.noreply.github.com>2026-11-23 20:50:57 +0100
committerOlaiFG7 <156535605+OlaiFG7@users.noreply.github.com>2026-11-23 20:50:57 +0100
commit8d460a57f9b0d804fd20fc682009d2bd73f890fb (patch)
tree3af7ab0f94aafc5179cb3047d1f62607c0b0c884 /scripts
parent867d922f09b86583859796a174df89555fb32da8 (diff)
check_no_game_data: report an unreadable file as one stderr line and exit 2, not a traceback
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/check_no_game_data.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/scripts/check_no_game_data.py b/scripts/check_no_game_data.py
index fd6849fd3..14cc8340d 100644
--- a/scripts/check_no_game_data.py
+++ b/scripts/check_no_game_data.py
@@ -251,13 +251,20 @@ def tracked_files(root):
251 return [os.path.join(root, p) for p in out.decode("utf-8", "surrogateescape").split("\0") if p] 251 return [os.path.join(root, p) for p in out.decode("utf-8", "surrogateescape").split("\0") if p]
252 252
253 253
254def check(paths): 254def check(paths, unreadable=None):
255 """[(path, format)] for every regular file in `paths` that starts like game data.""" 255 """[(path, format)] for every regular file in `paths` that starts like game data.
256
257 A file that exists but cannot be opened or read is appended to `unreadable` (when given) as (path, error)."""
256 found = [] 258 found = []
257 for path in paths: 259 for path in paths:
258 if os.path.islink(path) or not os.path.isfile(path): 260 if os.path.islink(path) or not os.path.isfile(path):
259 continue # submodules, symlinks, files deleted in the working tree 261 continue # submodules, symlinks, files deleted in the working tree
260 name = classify_file(path) 262 try:
263 name = classify_file(path)
264 except OSError as e:
265 if unreadable is not None:
266 unreadable.append((path, e))
267 continue
261 if name: 268 if name:
262 found.append((path, name)) 269 found.append((path, name))
263 return found 270 return found
@@ -273,13 +280,16 @@ def display(path):
273 280
274def main(argv): 281def main(argv):
275 paths = argv or tracked_files(os.getcwd()) 282 paths = argv or tracked_files(os.getcwd())
276 found = check(paths) 283 unreadable = []
284 found = check(paths, unreadable)
277 for path, name in found: 285 for path, name in found:
278 print(f"{display(path)}: {name}") 286 print(f"{display(path)}: {name}")
287 for path, e in unreadable:
288 print(f"check_no_game_data: cannot read {display(path)}: {e.strerror or e}", file=sys.stderr)
279 if found: 289 if found:
280 print(f"{len(found)} file(s) start like game data. Remove them; see CONTRIBUTING.md.", file=sys.stderr) 290 print(f"{len(found)} file(s) start like game data. Remove them; see CONTRIBUTING.md.", file=sys.stderr)
281 return 1 291 return 1
282 return 0 292 return 2 if unreadable else 0 # 2: some files could not be checked and none of the others matched
283 293
284 294
285if __name__ == "__main__": 295if __name__ == "__main__":