-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextra_script.py
More file actions
52 lines (41 loc) · 1.67 KB
/
extra_script.py
File metadata and controls
52 lines (41 loc) · 1.67 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
Import("env")
from datetime import datetime, UTC
import json
import shutil
import subprocess
import sys
import textwrap
def create_version_header():
result = subprocess.run(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE, text=True)
git_commit_hash = result.stdout.strip()
with open('webui/package.json') as package_json_file:
package_json = json.load(package_json_file)
# get current datetime with UTC timezone but 'Z' instead of "+00:00" (e.g. 2025-05-02T07:56:10Z)
buildTime = datetime.now(UTC)
buildTimeString = buildTime.replace(tzinfo=None).isoformat(timespec="seconds") + 'Z'
contents = textwrap.dedent(f"""\
// Copyright (c) 2025 Tobias Gunkel
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
class Version {{
public:
static const char* getPackageVersion() {{ return "{package_json['version']}"; }}
static const char* getGitCommitHash() {{ return "{git_commit_hash}"; }}
static const char* getBuildTime() {{ return "{buildTimeString}"; }}
}};
""")
headerFile = 'src/version.h'
print("Updating {} with version/timestamp...".format(headerFile))
with open(headerFile, 'w+') as file:
file.write(contents)
def copy_config():
print("Copy config/config.yaml to data directory...")
shutil.copy('config/config.yaml', 'data/config.yaml')
def before_littlefs(source, target, env):
print("Building UI...")
if env.Execute("npm run --prefix webui build"):
print("UI build failed: npm returned an error", file=sys.stderr)
Exit(1)
copy_config()
create_version_header()
env.AddPreAction("$BUILD_DIR/littlefs.bin", before_littlefs)