forked from hugcabbage/shared-lede
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.python脚本重写,逻辑更加清晰。 2.流程文档替换actions即将弃用的set-output命令。
- Loading branch information
1 parent
d363b7c
commit bbea118
Showing
2 changed files
with
65 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
#!/usr/bin/python3 | ||
|
||
|
||
import os | ||
import sys | ||
import shutil | ||
import fileinput | ||
|
||
os.chdir("preset-models") | ||
|
||
main_targets = ["mi-router-4a-gigabit", "mi-router-cr6608", "redmi-router-ac2100", "phicomm_k2p", "redmi-router-ax6s"] | ||
main_numbers = ["1", "2", "3", "4", "5"] | ||
sub_targets = ["mi-router-cr6606", "mi-router-cr6609", "mi-router-3g", "mi-router-4", "mi-router-3-pro", "mi-router-ac2100", "mi-router-3g-v2"] | ||
sub_numbers = ["2-1", "2-2", "2-3", "2-4", "2-5", "3-1", "1-1"] | ||
|
||
def get_number(): | ||
for target in main_targets: | ||
if target == sys.argv[1]: | ||
i = main_targets.index(target) | ||
return main_numbers[i] | ||
break | ||
headers = { | ||
'xiaomi-4a-gigabit': ('1', 'ramips', 'mt7621', 'mi-router-4a-gigabit'), | ||
'xiaomi-3g-v2': ('1-1', 'ramips', 'mt7621', 'mi-router-3g-v2'), | ||
'xiaomi-cr6608': ('2', 'ramips', 'mt7621', 'mi-router-cr6608'), | ||
'xiaomi-cr6606': ('2-1', 'ramips', 'mt7621', 'mi-router-cr6606'), | ||
'xiaomi-cr6609': ('2-2', 'ramips', 'mt7621', 'mi-router-cr6609'), | ||
'xiaomi-3g': ('2-3', 'ramips', 'mt7621', 'mi-router-3g'), | ||
'xiaomi-4': ('2-4', 'ramips', 'mt7621', 'mi-router-4'), | ||
'xiaomi-3-pro': ('2-5', 'ramips', 'mt7621', 'mi-router-3-pro'), | ||
'redmi-ac2100': ('3', 'ramips', 'mt7621', 'redmi-router-ac2100'), | ||
'xiaomi-ac2100': ('3-1', 'ramips', 'mt7621', 'mi-router-ac2100'), | ||
'phicomm-k2p': ('4', 'ramips', 'mt7621', 'phicomm_k2p'), | ||
'redmi-ax6s': ('5', 'ramips', 'mt7621', 'redmi-router-ax6s') | ||
} | ||
|
||
|
||
# model为机型名称, num为原始配置文件前缀(即编号),temp为即将用于编译流程中的临时文件前缀 | ||
def produce_temp_files(model: str, num: str, temp: str): | ||
header = [ | ||
f'CONFIG_TARGET_{(t1 := headers[model][1])}=y\n', | ||
f'CONFIG_TARGET_{t1}_{(t2 := headers[model][2])}=y\n', | ||
f'CONFIG_TARGET_{t1}_{t2}_DEVICE_{headers[model][3]}=y\n' | ||
] | ||
# 生成临时clone.sh, modify.sh | ||
shutil.copyfile(num + 'clone.sh', temp + 'clone.sh') | ||
shutil.copyfile(num + 'modify.sh', temp + 'modify.sh') | ||
# 生成临时.config | ||
tindex = () | ||
with open(num + '.config') as f: | ||
text = f.readlines() | ||
for (index, value) in enumerate(text): | ||
if 'CONFIG_TARGET' in value: | ||
tindex += (index,) | ||
if len(tindex) == 0: | ||
text = header + text | ||
else: | ||
for target in sub_targets: | ||
if target == sys.argv[1]: | ||
j = sub_targets.index(target) | ||
return sub_numbers[j] | ||
break | ||
|
||
def copy_files(old_pre, new_pre, old_str="", new_str=""): | ||
co_files = [".config", "clone.sh", "modify.sh"] | ||
for co_file in co_files: | ||
shutil.copyfile(old_pre + co_file, new_pre + co_file) | ||
if old_str != "" and new_str != "": | ||
for line in fileinput.input(new_pre + co_files[0], inplace=1): | ||
line = line.replace(old_str, new_str) | ||
print(line, end = "") | ||
for i in range(3): | ||
text[tindex[i]] = header[i] | ||
with open(temp + '.config', 'w') as f: | ||
f.writelines(text) | ||
return | ||
|
||
# 获取序号 | ||
num = get_number() | ||
|
||
print(num) | ||
|
||
#复制子机型配置文件 | ||
if "-" in num: | ||
num_part1 = num.split("-")[0] | ||
m = main_numbers.index(num_part1) | ||
n = sub_numbers.index(num) | ||
copy_files(num_part1, "temp.", main_targets[m], sub_targets[n]) | ||
else: | ||
copy_files(num, "temp.") | ||
os.rename("temp..config", "temp.config") | ||
if __name__ == '__main__': | ||
os.chdir('preset-models') | ||
modelname = sys.argv[1] | ||
if modelname not in headers: | ||
print('机型信息错误,请检查') | ||
else: | ||
modelnum = headers[modelname][0].split('-')[0] | ||
produce_temp_files(modelname, modelnum, 'temp.') | ||
os.rename('temp..config', 'temp.config') | ||
# 输出对应机型的编号,以设置编译流程中的变量读取预设release内容 | ||
print(headers[modelname][0]) |