shithub: pokered

Download patch

ref: 58a9aacc0b5b00e0f06acfe99cb3612127ec24fd
parent: cbb722d09b986cee7272db166010d44f0aeecb96
author: sawakita <sawakitanoodles@gmail.com>
date: Mon Oct 1 14:44:36 EDT 2012

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.

--- a/extras/analyze_incbins.py
+++ b/extras/analyze_incbins.py
@@ -33,12 +33,30 @@
     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"