-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·103 lines (88 loc) · 2.97 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·103 lines (88 loc) · 2.97 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
#
# Build script for fcitx5-breeze.
# Based on upstream work by scratch-er (2021-2024), distributed under GPLv3.
# Modifications by Shining Yang in 2026.
# Copyright (C) 2026 Shining Yang
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
import os
import shutil
config_file = "build.json"
files = {}
variables = {}
tags = []
build_config = []
def mkne(dirname):
if not os.path.exists(dirname):
os.mkdir(dirname)
# 从源文件中替换掉变量的值并写入目标文件
def replace_variables(src_file, dst_file):
src_file = open(src_file, "rt")
dst_file = open(dst_file, "wt")
content = src_file.read()
for k, v in variables.items():
content = content.replace(f"${k}$", v)
dst_file.write(content)
src_file.close()
dst_file.close()
def write_file(dirname):
dst_dir = os.path.join("build", dirname)
mkne(dst_dir)
for dst_file, src_file in files.items():
dst_file = os.path.join(dst_dir, dst_file)
if src_file.endswith(".svg.in"):
# 根据模板生成SVG文件
tmp_file = os.path.join("tmp", os.path.basename(src_file) + ".svg")
replace_variables(src_file, tmp_file)
shutil.copy(tmp_file, dst_file)
elif src_file.endswith(".in"):
# 生成配置文件
replace_variables(src_file, dst_file)
else:
# 简单复制
shutil.copy(src_file, dst_file)
def build(level):
if level == len(build_config):
dir_name = ""
for tag in tags:
dir_name += tag + "-"
dir_name = dir_name[:-1]
print("Building theme " + dir_name)
write_file(dir_name)
else:
conf_list = build_config[level]
for conf in conf_list:
conf_tag = conf.get("tag", "none")
conf_files = conf.get("files", {})
conf_vars = conf.get("variables", {})
tags.append(conf_tag)
files.update(conf_files)
variables.update(conf_vars)
build(level + 1)
tags.pop()
for k in conf_files.keys():
files.pop(k)
for k in conf_vars.keys():
variables.pop(k)
config_file = open(config_file, "rt")
build_config = json.load(config_file)
config_file.close()
mkne("tmp")
mkne("build")
build(0)
print("Build successful.")
shutil.rmtree("tmp")
print("Cleanup successful.")