From d242268bb25085165b5ee1bfab5d62b102588d5e Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 16 Feb 2023 14:35:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=B4,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=20partitions.b?= =?UTF-8?q?in=20=D0=B8=20=D0=B7=D0=B0=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20pio=20=D0=BD=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D1=8F=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrepareServer.py | 49 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/PrepareServer.py b/PrepareServer.py index ab5187dc..6ab6d57a 100644 --- a/PrepareServer.py +++ b/PrepareServer.py @@ -1,43 +1,36 @@ # подготавливаем папку для локального сервера обновлений # для этого компилируем проект и получаем бинарные файлы: -# firmware.bin, littlefs.bin и ver.json +# firmware.bin, littlefs.bin, partitions.bin и ver.json import shutil import configparser import os, json, sys, getopt from pathlib import Path + +def copyFileIfExist(fileName, deviceName): + srcFilePath = ".pio/build/" + deviceName + "/" + fileName + dstFilePath = "iotm/" + deviceName + "/400/" + fileName + if Path(srcFilePath).is_file(): + print("Ok...... \"" + srcFilePath + "\" на месте!") + Path(dstFilePath).parent.mkdir(parents=True, exist_ok=True) + shutil.copy(srcFilePath, dstFilePath) + return True + else: + print("Error...... \"" + srcFilePath + "\" НЕ существует!") + return False + + config = configparser.ConfigParser() # создаём объекта парсера INI config.read("platformio.ini") deviceName = config["platformio"]["default_envs"] homeDir = os.path.expanduser('~') os.system(homeDir + "\.platformio\penv\Scripts\pio run") -os.system(homeDir + "\.platformio\penv\Scripts\pio run -t buildfs") +os.system(homeDir + "\.platformio\penv\Scripts\pio run -t buildfs --disable-auto-clean") -firmwareSrcPath = ".pio/build/" + deviceName + "/firmware.bin" -littlefsSrcPath = ".pio/build/" + deviceName + "/littlefs.bin" - -if Path(firmwareSrcPath).is_file(): - print("Ok...... \"" + firmwareSrcPath + "\" Exist!") - firmwareDstPath = "iotm/" + deviceName + "/400/firmware.bin" - Path(firmwareDstPath).parent.mkdir(parents=True, exist_ok=True) - shutil.copy(firmwareSrcPath, firmwareDstPath) - - if Path(littlefsSrcPath).is_file(): - print("Ok...... \"" + littlefsSrcPath + "\" Exist!") - littlefsDstPath = "iotm/" + deviceName + "/400/littlefs.bin" - Path(littlefsDstPath).parent.mkdir(parents=True, exist_ok=True) - shutil.copy(littlefsSrcPath, littlefsDstPath) - - versionsJson = json.loads('{"' + deviceName + '": {"0": "400"}}') - with open("iotm/ver.json", "w", encoding='utf-8') as write_file: - json.dump(versionsJson, write_file, ensure_ascii=False, indent=4, sort_keys=False) - - print(f"\x1b[1;31;42m Сервер для обновления 'по воздуху' для " + deviceName + " подготовлен. Не забудьте установить расширение Live Server, запустить его и прописать в ESP IP вашего компьютера. Подробнее смотрите в WIKI: https://iotmanager.org/wiki.\x1b[0m") - - else: - print("Error...... \"" + littlefsSrcPath + "\" Not exist!") - -else: - print("Error...... \"" + firmwareSrcPath + "\" Not exist!") \ No newline at end of file +if copyFileIfExist("firmware.bin", deviceName) and copyFileIfExist("littlefs.bin", deviceName) and copyFileIfExist("partitions.bin", deviceName): + versionsJson = json.loads('{"' + deviceName + '": {"0": "400"}}') + with open("iotm/ver.json", "w", encoding='utf-8') as write_file: + json.dump(versionsJson, write_file, ensure_ascii=False, indent=4, sort_keys=False) + print(f"\x1b[1;31;42m Сервер для обновления 'по воздуху' для " + deviceName + " подготовлен. Не забудьте установить расширение Live Server, запустить его и прописать в ESP IP вашего компьютера. Подробнее смотрите в WIKI: https://iotmanager.org/wiki.\x1b[0m") \ No newline at end of file