Skip to content

Commit 7ba31d4

Browse files
authored
Target: Erase and Upload (#48)
* Target: Erase Flash and Upload * zopfli * "version": "2022.12.1"
1 parent bbb1759 commit 7ba31d4

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

builder/frameworks/arduino.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
http://arduino.cc/en/Reference/HomePage
2323
"""
2424

25+
import subprocess
26+
import json
27+
import semantic_version
2528
from os.path import join
26-
from SCons.Script import DefaultEnvironment, SConscript
29+
30+
from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript
31+
from platformio.package.version import pepver_to_semver
2732

2833
env = DefaultEnvironment()
2934

@@ -46,3 +51,47 @@
4651
SConscript(
4752
join(DefaultEnvironment().PioPlatform().get_package_dir(
4853
"framework-arduinoespressif32"), "tools", "platformio-build.py"))
54+
55+
def install_python_deps():
56+
def _get_installed_pip_packages():
57+
result = {}
58+
packages = {}
59+
pip_output = subprocess.check_output(
60+
[env.subst("$PYTHONEXE"), "-m", "pip", "list", "--format=json"]
61+
)
62+
try:
63+
packages = json.loads(pip_output)
64+
except:
65+
print("Warning! Couldn't extract the list of installed Python packages.")
66+
return {}
67+
for p in packages:
68+
result[p["name"]] = pepver_to_semver(p["version"])
69+
70+
return result
71+
72+
deps = {
73+
"zopfli": ">=0.2.2"
74+
}
75+
76+
installed_packages = _get_installed_pip_packages()
77+
packages_to_install = []
78+
for package, spec in deps.items():
79+
if package not in installed_packages:
80+
packages_to_install.append(package)
81+
else:
82+
version_spec = semantic_version.Spec(spec)
83+
if not version_spec.match(installed_packages[package]):
84+
packages_to_install.append(package)
85+
86+
if packages_to_install:
87+
env.Execute(
88+
env.VerboseAction(
89+
(
90+
'"$PYTHONEXE" -m pip install -U --force-reinstall '
91+
+ " ".join(['"%s%s"' % (p, deps[p]) for p in packages_to_install])
92+
),
93+
"Installing Python dependencies",
94+
)
95+
)
96+
97+
install_python_deps()

builder/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,21 @@ def __fetch_fs_size(target, source, env):
491491
env.AddPlatformTarget(
492492
"uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA")
493493

494+
#
495+
# Target: Erase Flash and Upload
496+
#
497+
498+
env.AddPlatformTarget(
499+
"erase_upload",
500+
target_firm,
501+
[
502+
env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."),
503+
env.VerboseAction("$ERASECMD", "Erasing..."),
504+
env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")
505+
],
506+
"Erase Flash and Upload",
507+
)
508+
494509
#
495510
# Target: Erase Flash
496511
#

platform.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"type": "git",
1919
"url": "https://github.com/tasmota/platform-espressif32.git"
2020
},
21-
"version": "2022.12.0",
21+
"version": "2022.12.1",
2222
"frameworks": {
2323
"arduino": {
2424
"script": "builder/frameworks/arduino.py"

0 commit comments

Comments
 (0)