From 58a9aacc0b5b00e0f06acfe99cb3612127ec24fd Mon Sep 17 00:00:00 2001 From: sawakita Date: Mon, 1 Oct 2012 18:44:36 +0200 Subject: [PATCH] Restore auto-loading of default "main" asm file This feature was removed misunderstanding its actual use: if filename passed to load_asm() is in defaults the correct current main asm file is loaded. This saves us from knowing which actually is the current name of the "main" asm file, because the correct one is chosen automatically (unless, of course, the passed filename is not in the defaults list. --- extras/analyze_incbins.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/extras/analyze_incbins.py b/extras/analyze_incbins.py index 8ba36e09..612c1410 100644 --- a/extras/analyze_incbins.py +++ b/extras/analyze_incbins.py @@ -33,13 +33,31 @@ def load_asm(filename=os.path.join(pokered_dir, "main.asm")): is using main.asm, common.asm or pokered.asm, which is useful when generating images in romvisualizer.py""" global asm + # chronological order is important defaults = [os.path.join(pokered_dir, f) for f in ["main.asm", "common.asm", "pokered.asm"]] if filename in defaults: - asm = open(filename, "r").read().split("\n") - else: - raise Exception("this shouldn't happen") + if not load_asm_if_one_exists_in(defaults): + raise Exception("This shouldn't happen") + elif os.path.exists(filename): + asm = get_all_lines_from_file(filename) + if asm is None: + raise Exception("file doesn't exists (did you mean one among: {0}?)".format(", ".join(defaults))) return asm +def load_asm_if_one_exists_in(*args): + global asm + for f in args: + if os.path.exists(f): + asm = get_all_lines_from_file(f) + return True + return False + +def get_all_lines_from_file(filename): + try: + return open(filename, "r").read().split("\n") + except IOError as e: + raise(e) + def isolate_incbins(): "find each incbin line" global incbin_lines