diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-08-03 15:12:45 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-08-03 15:12:45 -0500 |
commit | f6b13962f62dbe23be0322656d0d12b6d1a16901 (patch) | |
tree | cd4c448c717ec0f1991d737bcb6046cae3b487f7 | |
parent | 860829c2b12ec42ec75145ed9ba053195b3bff73 (diff) |
combine hram/gbhw readers into read_constants
This consolidates read_hram_constants and read_gbhw_constants.
-rw-r--r-- | wram.py | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -92,18 +92,25 @@ def scrape_constants(text): text = text.split('\n') return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]]) -def read_hram_constants(): +def read_constants(filepath): """ - Load constants from hram.asm. + Load lines from a file and call scrape_constants. """ try: - hram_file_handler = open(os.path.join(os.path.dirname(path), 'hram.asm'), 'r') + file_handler = open(filepath, "r") except IOError as exception: - hram_lines = [""] + lines = [""] else: - hram_lines = hram_file_handler.readlines() - hram_constants = scrape_constants(hram_lines) - return hram_constants + lines = file_handler.readlines() + constants = scrape_constants(lines) + return constants + +def read_hram_constants(): + """ + Load constants from hram.asm. + """ + hram_path = os.path.join(os.path.dirname(path), 'hram.asm') + return read_constants(hram_path) hram_constants = read_hram_constants() @@ -111,13 +118,7 @@ def read_gbhw_constants(): """ Load constants from gbhw.asm. """ - try: - gbhw_file_handler = open(os.path.join(os.path.dirname(path), 'gbhw.asm'), 'r') - except IOError as exception: - gbhw_lines = [""] - else: - gbhw_lines = gbhw_file_handler.readlines() - gbhw_constants = scrape_constants(gbhw_lines) - return gbhw_constants + gbhw_path = os.path.join(os.path.dirname(path), 'gbhw.asm') + return read_constants(gbhw_path) gbhw_constants = read_gbhw_constants() |