-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
42 lines (35 loc) · 1.09 KB
/
Copy pathSConstruct
File metadata and controls
42 lines (35 loc) · 1.09 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
import os
import tarfile
import shutil
import stat
def build():
os.makedirs("dist", exist_ok=True)
tar_name = "dist/payload.tar.gz"
# Bundle the python code and assets
with tarfile.open(tar_name, "w:gz") as tar:
for f in os.listdir("."):
if f.endswith(".py") or f in ["assets", "fonts"]:
tar.add(f)
# Create self-extracting bash script
script = """#!/bin/sh
APP_DIR=/tmp/hamlog_app
mkdir -p "$APP_DIR"
sed '1,/^__PAYLOAD_BEGIN__/d' "$0" | tar xz -C "$APP_DIR"
cd "$APP_DIR"
exec python3 main.py "$@"
exit 0
__PAYLOAD_BEGIN__
"""
with open("dist/run.sh", "wb") as f:
f.write(script.encode())
with open(tar_name, "rb") as t:
f.write(t.read())
os.remove(tar_name)
# Make executable
st = os.stat("dist/run.sh")
os.chmod("dist/run.sh", st.st_mode | stat.S_IEXEC)
# Provide the icon in dist so pack_deb.py embeds it in the desktop file
if os.path.exists("assets/icon.png"):
shutil.copy2("assets/icon.png", "dist/icon.png")
build()
print("SConstruct completed successfully.")