Files
OpenMQTTGateway/scripts/replace_lib.py
Florian f1f27cc83e [DEV] Add automatic BT lib replacement for BLE environments (#1860)
So that the replacement is done locally on the development environments but also with the CI
2024-01-09 12:52:59 -06:00

29 lines
928 B
Python

import shutil
import os
import hashlib
Import("env")
def calculate_md5(filepath):
md5_hash = hashlib.md5()
with open(filepath, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
md5_hash.update(byte_block)
return md5_hash.hexdigest()
def main():
print(f"Pre build BLE library replacement script")
home_path = os.environ.get('HOME') or os.environ.get('USERPROFILE')
source_file = 'lib/esp32-bt-lib/esp32/libbtdm_app.a'
destination_file = os.path.join(home_path, '.platformio', 'packages', 'framework-arduinoespressif32', 'tools', 'sdk', 'esp32', 'ld', 'libbtdm_app.a')
try:
shutil.copyfile(source_file, destination_file)
md5_hash = calculate_md5(destination_file)
print(f"Successfully copied {source_file} to {destination_file}")
print(f"MD5: {md5_hash}")
except Exception as e:
print(f"Error occurred: {e}")
main()