/
singlwolf
/
Radiola-2S3
Обзор
Документация
Войти
/
singlwolf
/
Radiola-2S3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
extra_script.py
110 строк
3 KB
SinglWolf
Public access
27 мар 2026, 07:00
27 мар 2026, 07:00
642fcfc
Код
Авторство
О чём код?
from sys import platform from os.path import isfile, join import os import shutil import hashlib import pathlib from pathlib import Path Import("env") # print(env.Dump()) # print(env.subst("$PIOENV")) # print(env.subst("$TARGET")) # PIOENV = env.subst("$PIOENV") PROJECT_DIR = env.subst("$PROJECT_DIR") flash_size = env.GetProjectOption("custom_flash_size") spiram_size = env.GetProjectOption("custom_spiram_size") file_list = [env.subst("$PROGNAME") + ".bin", "bootloader.bin", "partitions.bin"] if platform == "linux" or platform == "darwin": # linux or OS X SLASH = '/' elif platform == "win32": # Windows... SLASH = '\\' BUILD_DIR = env.subst("$BUILD_DIR") + SLASH BIN_DIR = PROJECT_DIR + SLASH + 'binaries' + SLASH pathlib.Path(BIN_DIR).mkdir(parents=True, exist_ok=True) git_ignore = Path(BIN_DIR + '.gitignore') try: f = open(git_ignore) f.close() # print("File found!") except FileNotFoundError: # print("Files couldn't be opened!") git_ignore.touch(exist_ok=True) f = open(git_ignore, 'w') print("*\n!.gitignore", file=f) f.close() def get_hash_sha1(filename): with open(filename, 'rb') as f: m = hashlib.sha1() while True: data = f.read(2**16) if not data: break m.update(data) return m.hexdigest() def check_sha1(name): check = True File = BIN_DIR + name File_sha1 = BIN_DIR + name.rsplit(".", 1)[0] + '.sha' if isfile(File_sha1): with open(File_sha1, 'r') as file: lst = list() for line in file.readlines(): lst.extend(line.rstrip().split(' ')) else: print("Checksum file for:", name, "not found.") with open(File_sha1, 'w') as fout: f_hash_sha1 = get_hash_sha1(File) print(f_hash_sha1 + ' *' + name, file=fout) print("Checksum file for:", name, "created.") check = False return check if lst[0] != get_hash_sha1(File): with open(File_sha1, 'w') as fout: f_hash_sha1 = get_hash_sha1(File) print(f_hash_sha1 + ' ' + name, file=fout) print("File:", name, "changed. Checksum overwritten.") check = False return check def del_files(): for name in file_list: if isfile(BUILD_DIR + name): os.remove(BUILD_DIR + name) def copy_bin(source, target, env): for name in file_list: if name == "partitions.bin": dest_name = flash_size + "_" + name elif name == "bootloader.bin": dest_name = spiram_size + "_" + name else: dest_name = name shutil.copy(BUILD_DIR + name, BIN_DIR + dest_name) check_sha1(dest_name) def copy_img_fs(source, target, env): name = env.GetProjectOption("board_build.filesystem") +".bin" dest_name = flash_size + "_" + name shutil.copy(BUILD_DIR + name, BIN_DIR + dest_name) check_sha1(dest_name) del_files() env.AddPostAction('buildprog', copy_bin) env.AddPostAction('buildfs', copy_img_fs)