mirror of
https://github.com/thornAvery/kep-hack.git
synced 2025-09-17 02:40:50 +12:00
Make analyze_incbins dirs reference os-independent
This should fix a bug caused by comparing string literals to directories. It should also be safer, using "os" module to access paths.
This commit is contained in:
parent
4b28ddb11f
commit
723e424979
|
@ -7,6 +7,7 @@ from copy import copy, deepcopy
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
from extract_maps import rom, assert_rom, load_rom, calculate_pointer, load_map_pointers, read_all_map_headers, map_headers
|
from extract_maps import rom, assert_rom, load_rom, calculate_pointer, load_map_pointers, read_all_map_headers, map_headers
|
||||||
|
from pokered_dir import pokered_dir
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pretty_map_headers import map_header_pretty_printer, map_name_cleaner
|
from pretty_map_headers import map_header_pretty_printer, map_name_cleaner
|
||||||
|
@ -26,24 +27,17 @@ def offset_to_pointer(offset):
|
||||||
if type(offset) == str: offset = int(offset, base)
|
if type(offset) == str: offset = int(offset, base)
|
||||||
return int(offset) % 0x4000 + 0x4000
|
return int(offset) % 0x4000 + 0x4000
|
||||||
|
|
||||||
def load_asm(filename="../main.asm"):
|
def load_asm(filename=os.path.join(pokered_dir, "main.asm")):
|
||||||
"""loads the asm source code into memory
|
"""loads the asm source code into memory
|
||||||
this also detects if the revision of the repository
|
this also detects if the revision of the repository
|
||||||
is using main.asm, common.asm or pokered.asm, which is
|
is using main.asm, common.asm or pokered.asm, which is
|
||||||
useful when generating images in romvisualizer.py"""
|
useful when generating images in romvisualizer.py"""
|
||||||
global asm
|
global asm
|
||||||
defaults = ["../main.asm", "../common.asm", "../pokered.asm"]
|
defaults = [os.path.join(pokered_dir, f) for f in ["main.asm", "common.asm", "pokered.asm"]]
|
||||||
if filename in defaults:
|
if filename in defaults:
|
||||||
if os.path.exists("../main.asm"):
|
|
||||||
asm = open("../main.asm", "r").read().split("\n")
|
|
||||||
elif os.path.exists("../common.asm"):
|
|
||||||
asm = open("../common.asm", "r").read().split("\n")
|
|
||||||
elif os.path.exists("../pokered.asm"):
|
|
||||||
asm = open("../pokered.asm", "r").read().split("\n")
|
|
||||||
else:
|
|
||||||
raise "this shouldn't happen"
|
|
||||||
else:
|
|
||||||
asm = open(filename, "r").read().split("\n")
|
asm = open(filename, "r").read().split("\n")
|
||||||
|
else:
|
||||||
|
raise Exception("this shouldn't happen")
|
||||||
return asm
|
return asm
|
||||||
|
|
||||||
def isolate_incbins():
|
def isolate_incbins():
|
||||||
|
@ -168,7 +162,9 @@ def generate_diff_insert(line_number, newline):
|
||||||
newfile_fh.close()
|
newfile_fh.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
diffcontent = subprocess.check_output("diff -u ../main.asm " + newfile_filename, shell=True)
|
diffcontent = subprocess.check_output(
|
||||||
|
"diff -u {0} {1}".format(os.path.join(pokered_dir, "main.asm"), newfile_filename),
|
||||||
|
shell=True)
|
||||||
except AttributeError, exc:
|
except AttributeError, exc:
|
||||||
raise exc
|
raise exc
|
||||||
except Exception, exc:
|
except Exception, exc:
|
||||||
|
@ -208,7 +204,7 @@ def insert_map_header_asm(map_id):
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
#apply the patch
|
#apply the patch
|
||||||
os.system("patch ../main.asm temp.patch")
|
os.system("patch {0} temp.patch".format(os.path.join(pokered_dir, "main.asm")))
|
||||||
|
|
||||||
#remove the patch
|
#remove the patch
|
||||||
os.system("rm temp.patch")
|
os.system("rm temp.patch")
|
||||||
|
@ -243,8 +239,12 @@ def apply_diff(diff, try_fixing=True, do_compile=True):
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
#apply the patch
|
#apply the patch
|
||||||
os.system("cp ../main.asm ../main1.asm")
|
os.system("cp {0} {1}".format(
|
||||||
os.system("patch ../main.asm temp.patch")
|
os.path.join(pokered_dir, "main.asm"),
|
||||||
|
os.path.join(pokered_dir, "main1.asm")))
|
||||||
|
os.system("patch {0} {1}".format(
|
||||||
|
os.path.join(pokered_dir, "main.asm"),
|
||||||
|
"temp.patch"))
|
||||||
|
|
||||||
#remove the patch
|
#remove the patch
|
||||||
os.system("rm temp.patch")
|
os.system("rm temp.patch")
|
||||||
|
@ -252,11 +252,13 @@ def apply_diff(diff, try_fixing=True, do_compile=True):
|
||||||
#confirm it's working
|
#confirm it's working
|
||||||
if do_compile:
|
if do_compile:
|
||||||
try:
|
try:
|
||||||
subprocess.check_call("cd ../; make clean; LC_CTYPE=C make", shell=True)
|
subprocess.check_call("cd {0}; make clean; LC_CTYPE=C make".format(pokered_dir), shell=True)
|
||||||
return True
|
return True
|
||||||
except Exception, exc:
|
except Exception, exc:
|
||||||
if try_fixing:
|
if try_fixing:
|
||||||
os.system("mv ../main1.asm ../main.asm")
|
os.system("mv {0} {1}".format(
|
||||||
|
os.path.join(pokered_dir, "main1.asm"),
|
||||||
|
os.path.join(pokered_dir, "main.asm")))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def index(seq, f):
|
def index(seq, f):
|
||||||
|
|
4
extras/pokered_dir.py
Normal file
4
extras/pokered_dir.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
#main dir of repo (simply one level up than here)
|
||||||
|
pokered_dir = os.path.dirname(os.path.dirname(__file__))
|
Loading…
Reference in a new issue