Caracal_Firmware/prepare_firmware.py

29 lines
708 B
Python
Raw Normal View History

2018-02-09 23:28:40 +01:00
"""
Prepare the firmware image for publishing
- Read Firmware version from code
- Generate firmware.version file
- Rename Firmware image
"""
import os
import re
import time
with open("Caracal_Firmware.ino", 'r') as f:
2018-02-09 23:28:40 +01:00
code = f.read()
match = re.search(r"#define HW_GROUP (\d+)", code)
hw_version = match.group(1)
2018-02-09 23:28:40 +01:00
match = re.search(r"FW_VERSION = (\d+);", code)
fw_version = match.group(1)
fname = "firmware{}.bin".format(hw_version)
if os.path.exists("Caracal_Firmware.ino.generic.bin"):
if os.path.exists(fname):
os.remove(fname)
os.rename("Caracal_Firmware.ino.generic.bin", fname)
2018-02-09 23:28:40 +01:00
with open("firmware{}.version".format(hw_version), 'w') as f:
f.write(fw_version)