From 7ba31d4554b8aceb84abadad1e2cb3613dd0f1a5 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu, 22 Dec 2022 10:43:14 +0100 Subject: [PATCH] Target: Erase and Upload (#48) * Target: Erase Flash and Upload * zopfli * "version": "2022.12.1" --- builder/frameworks/arduino.py | 51 ++++++++++++++++++++++++++++++++++- builder/main.py | 15 +++++++++++ platform.json | 2 +- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 3b96cd994..ebbc269b5 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -22,8 +22,13 @@ http://arduino.cc/en/Reference/HomePage """ +import subprocess +import json +import semantic_version from os.path import join -from SCons.Script import DefaultEnvironment, SConscript + +from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript +from platformio.package.version import pepver_to_semver env = DefaultEnvironment() @@ -46,3 +51,47 @@ SConscript( join(DefaultEnvironment().PioPlatform().get_package_dir( "framework-arduinoespressif32"), "tools", "platformio-build.py")) + +def install_python_deps(): + def _get_installed_pip_packages(): + result = {} + packages = {} + pip_output = subprocess.check_output( + [env.subst("$PYTHONEXE"), "-m", "pip", "list", "--format=json"] + ) + try: + packages = json.loads(pip_output) + except: + print("Warning! Couldn't extract the list of installed Python packages.") + return {} + for p in packages: + result[p["name"]] = pepver_to_semver(p["version"]) + + return result + + deps = { + "zopfli": ">=0.2.2" + } + + installed_packages = _get_installed_pip_packages() + packages_to_install = [] + for package, spec in deps.items(): + if package not in installed_packages: + packages_to_install.append(package) + else: + version_spec = semantic_version.Spec(spec) + if not version_spec.match(installed_packages[package]): + packages_to_install.append(package) + + if packages_to_install: + env.Execute( + env.VerboseAction( + ( + '"$PYTHONEXE" -m pip install -U --force-reinstall ' + + " ".join(['"%s%s"' % (p, deps[p]) for p in packages_to_install]) + ), + "Installing Python dependencies", + ) + ) + +install_python_deps() diff --git a/builder/main.py b/builder/main.py index 4291298ee..2265e7018 100644 --- a/builder/main.py +++ b/builder/main.py @@ -491,6 +491,21 @@ def __fetch_fs_size(target, source, env): env.AddPlatformTarget( "uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA") +# +# Target: Erase Flash and Upload +# + +env.AddPlatformTarget( + "erase_upload", + target_firm, + [ + env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."), + env.VerboseAction("$ERASECMD", "Erasing..."), + env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") + ], + "Erase Flash and Upload", +) + # # Target: Erase Flash # diff --git a/platform.json b/platform.json index 985c9ce99..369154519 100644 --- a/platform.json +++ b/platform.json @@ -18,7 +18,7 @@ "type": "git", "url": "https://github.com/tasmota/platform-espressif32.git" }, - "version": "2022.12.0", + "version": "2022.12.1", "frameworks": { "arduino": { "script": "builder/frameworks/arduino.py"