/ RNode_Firmware_CE_G2 / release_hashes.py
release_hashes.py
1 #!/bin/python 2 3 # Copyright (C) 2024, Mark Qvist 4 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 15 # You should have received a copy of the GNU General Public License 16 # along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 import os 19 import json 20 import hashlib 21 22 major_version = None 23 minor_version = None 24 target_version = None 25 26 file = open("Config.h", "rb") 27 config_data = file.read().splitlines() 28 for line in config_data: 29 dline = line.decode("utf-8").strip() 30 components = dline.split() 31 if dline.startswith("#define MAJ_VERS"): 32 major_version = "%01d" % ord(bytes.fromhex(dline.split()[2].split("x")[1])) 33 if dline.startswith("#define MIN_VERS"): 34 minor_version = "%02d" % ord(bytes.fromhex(dline.split()[2].split("x")[1])) 35 36 target_version = major_version+"."+minor_version 37 38 release_hashes = {} 39 target_dir = "./Release" 40 files = os.listdir(target_dir) 41 for filename in files: 42 if os.path.isfile(os.path.join(target_dir, filename)): 43 if filename.startswith("rnode_firmware"): 44 file = open(os.path.join(target_dir, filename), "rb") 45 release_hashes[filename] = { 46 "hash": hashlib.sha256(file.read()).hexdigest(), 47 "version": target_version 48 } 49 50 print(json.dumps(release_hashes))