-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path.custom_targets.py
More file actions
83 lines (71 loc) · 2.81 KB
/
Copy path.custom_targets.py
File metadata and controls
83 lines (71 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import shutil
import re
import json
from version import *
from subprocess import check_output, CalledProcessError
import platform
Import("env")
def copy_and_replace(src, dest):
with open(src, "r") as src_file:
#read the file contents
file_contents = src_file.read()
text_pattern = re.compile(re.escape("$version$"), 0)
file_contents = text_pattern.sub(version, file_contents)
with open(dest, "w") as dest_file:
dest_file.seek(0)
dest_file.truncate()
dest_file.write(file_contents)
def copy_manifests_to_release(*args, **kwargs):
src = os.path.join(env["PROJECT_DIR"], "web", "esp-web-tools-manifest-bambulights-" + env["PIOENV"] + ".json")
dst = os.path.join(env["PROJECT_DIR"], 'releases', "esp-web-tools-manifest-bambulights-" + env["PIOENV"] + ".json")
copy_and_replace(src, dst)
def copy_firmware_to_release(*args, **kwargs):
# Open and read the manifest
manifest_path = os.path.join(env["PROJECT_DIR"], 'releases', "esp-web-tools-manifest-bambulights-" + env["PIOENV"] + ".json")
with open(manifest_path, 'r') as file:
manifest = json.load(file)
# merged firmware
src = os.path.join(env["PROJECT_DIR"], env.GetBuildPath("$BUILD_DIR"), env.GetBuildPath("${PROGNAME}_merged.bin"))
dst = os.path.join(env["PROJECT_DIR"], 'releases', manifest["builds"][0]["parts"][0]["path"])
print(src + " " + dst)
shutil.copy(src, dst)
# firmware
src = os.path.join(env["PROJECT_DIR"], env.GetBuildPath("$BUILD_DIR"), env.GetBuildPath("${PROGNAME}.bin"))
dst = os.path.join(env["PROJECT_DIR"], 'releases', manifest["builds"][0]["parts"][0]["path"].replace("_merged", ""))
print(src + " " + dst)
shutil.copy(src, dst)
# filesystem
src = os.path.join(env["PROJECT_DIR"], env.GetBuildPath("$BUILD_DIR"), env.GetBuildPath("${ESP32_FS_IMAGE_NAME}.bin"))
dst = os.path.join(env["PROJECT_DIR"], 'releases', "bl_littlefs.bin")
print(src + " " + dst)
shutil.copy(src, dst)
env.AddCustomTarget("release", [], [copy_manifests_to_release, copy_firmware_to_release])
def list_fs_contents(*args, **kwargs):
# Open and read the manifest
src = os.path.join(env["PROJECT_DIR"], env.GetBuildPath("$BUILD_DIR"), env.GetBuildPath("${ESP32_FS_IMAGE_NAME}.bin"))
# Run esptool to merge images into a single binary
env.Execute(
" ".join(
[
"/Users/Nemesis/.platformio/packages/tool-mklittlefs/mklittlefs",
"-l",
src
]
)
)
env.AddCustomTarget(
"listfs",
None,
list_fs_contents
)
env.AddCustomTarget(
name="release_prologue",
dependencies=None,
actions=[
"pio --version",
"python --version"
],
title="Prepare for Release",
description="Prepare for release"
)