update
This commit is contained in:
parent
b998714321
commit
660cf9e241
46
extract.py
46
extract.py
@ -14,27 +14,38 @@ def main():
|
|||||||
logger.addHandler(_ch)
|
logger.addHandler(_ch)
|
||||||
logger.setLevel("DEBUG")
|
logger.setLevel("DEBUG")
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("map_file")
|
parser.add_argument("map_file", help="map file, or bin if you also use --bin")
|
||||||
|
parser.add_argument("--bin", action="store_true", help="use this if the file is already a .bin file")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
map_file = args.map_file
|
map_file = args.map_file
|
||||||
logger.info("Opening %s", map_file)
|
|
||||||
zip_file = zipfile.ZipFile(map_file)
|
|
||||||
files = zip_file.namelist()
|
|
||||||
bin_filename = None
|
|
||||||
for file in files:
|
|
||||||
logger.info("Found file %s", file)
|
|
||||||
if file.endswith(".bin"):
|
|
||||||
bin_filename = file
|
|
||||||
logger.info("Found BIN file %s", bin_filename)
|
|
||||||
break
|
|
||||||
if not bin_filename:
|
|
||||||
logger.error("FATAL: BIN file not found")
|
|
||||||
zip_file.close()
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
_fh = logging.FileHandler(args.map_file+".log")
|
||||||
|
_fh.setFormatter(_formatter)
|
||||||
|
logger.addHandler(_fh)
|
||||||
|
|
||||||
|
if not args.bin:
|
||||||
|
logger.info("Opening %s", map_file)
|
||||||
|
zip_file = zipfile.ZipFile(map_file)
|
||||||
|
files = zip_file.namelist()
|
||||||
|
bin_filename = None
|
||||||
|
for file in files:
|
||||||
|
logger.info("Found file %s", file)
|
||||||
|
if file.endswith(".bin"):
|
||||||
|
bin_filename = file
|
||||||
|
logger.info("Found BIN file %s", bin_filename)
|
||||||
|
break
|
||||||
|
if not bin_filename:
|
||||||
|
logger.error("FATAL: BIN file not found")
|
||||||
|
zip_file.close()
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
fp = zip_file.open(bin_filename)
|
||||||
|
else:
|
||||||
|
bin_filename = args.map_file
|
||||||
|
fp = open(bin_filename, "rb")
|
||||||
logger.info("Opening %s", bin_filename)
|
logger.info("Opening %s", bin_filename)
|
||||||
with zip_file.open(bin_filename) as bin_file:
|
with fp as bin_file:
|
||||||
byte = bin_file.read(1)
|
byte = bin_file.read(1)
|
||||||
while byte != b"":
|
while byte != b"":
|
||||||
if byte == b'\x2a': # start object
|
if byte == b'\x2a': # start object
|
||||||
@ -47,7 +58,8 @@ def main():
|
|||||||
objects.append({"model": model, "x": x, "y": y, "z": z, "angle": angle})
|
objects.append({"model": model, "x": x, "y": y, "z": z, "angle": angle})
|
||||||
logger.info("Object model=%s x=%s y=%s z=%s angle=%s", model, x, y, z, angle)
|
logger.info("Object model=%s x=%s y=%s z=%s angle=%s", model, x, y, z, angle)
|
||||||
byte = bin_file.read(1)
|
byte = bin_file.read(1)
|
||||||
zip_file.close()
|
if not args.bin:
|
||||||
|
zip_file.close()
|
||||||
|
|
||||||
logger.info("Number of objects: %s", len(objects))
|
logger.info("Number of objects: %s", len(objects))
|
||||||
models_count = {}
|
models_count = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user