This commit is contained in:
Amazed 2019-11-01 01:14:15 +01:00
parent b998714321
commit 660cf9e241

View File

@ -14,10 +14,17 @@ def main():
logger.addHandler(_ch)
logger.setLevel("DEBUG")
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()
map_file = args.map_file
_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()
@ -33,8 +40,12 @@ def main():
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)
with zip_file.open(bin_filename) as bin_file:
with fp as bin_file:
byte = bin_file.read(1)
while byte != b"":
if byte == b'\x2a': # start object
@ -47,6 +58,7 @@ def main():
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)
byte = bin_file.read(1)
if not args.bin:
zip_file.close()
logger.info("Number of objects: %s", len(objects))