-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathplatformio_utils.py
More file actions
57 lines (41 loc) · 1.34 KB
/
platformio_utils.py
File metadata and controls
57 lines (41 loc) · 1.34 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
Import("env", "projenv")
try:
import jinja2
except ImportError:
env.Execute("$PYTHONEXE -m pip install jinja2")
import jinja2
from glob import glob
import os
import shutil
import os.path
import subprocess
def pre_spiffs_callback(target, source, env):
template_dir = 'src_data/'
loader = jinja2.FileSystemLoader(template_dir)
environment = jinja2.Environment(loader=loader)
for page in glob("src_data/*.j2"):
page_name = os.path.basename(page)
template = environment.get_template(page_name)
with open("data/" + page_name.replace('.j2', ''), 'w') as f:
f.write(template.render(the="variables", go="here"))
print("Created: " + page_name.replace('.j2', ''))
if(os.path.exists("data/config.txt") == False):
shutil.copyfile("data/config.default", "data/config.txt")
env.AddPreAction("$BUILD_DIR/spiffs.bin", pre_spiffs_callback)
git_commit_hash = (
subprocess.check_output(['git', 'show', '--pretty=format:%h', '--no-patch'])
.strip()
.decode("utf-8")
)
git_status = (
subprocess.check_output(['git', 'status', '--porcelain'])
.strip()
.decode("utf-8")
)
git_version = git_commit_hash
if git_status:
git_version += "-dirty"
print("Git version: " + git_version)
projenv.Append(CPPDEFINES=[
("GIT_VERSION", env.StringifyMacro(git_version))
])