summaryrefslogtreecommitdiff
path: root/extras
diff options
context:
space:
mode:
authorsawakita <sawakitanoodles@gmail.com>2012-10-01 18:44:36 +0200
committersawakita <sawakitanoodles@gmail.com>2012-10-01 18:44:36 +0200
commit58a9aacc0b5b00e0f06acfe99cb3612127ec24fd (patch)
tree1b5081fecc4e7cce4e28b00ab0c3066ad601abb3 /extras
parentcbb722d09b986cee7272db166010d44f0aeecb96 (diff)
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.
Diffstat (limited to 'extras')
-rw-r--r--extras/analyze_incbins.py24
1 files 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