Skip to content

Commit 3233592

Browse files
authored
Merge pull request #8 from Shyliuli/main
Add Architecture Name Prefix
2 parents 0bc0da9 + 3366a86 commit 3233592

File tree

2 files changed

+280
-200
lines changed

2 files changed

+280
-200
lines changed

contrib/trans.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
import sys
4+
5+
# 定义端口到架构的映射函数
6+
def get_arch_prefix(port):
7+
port = int(port)
8+
if 22001 <= port <= 23000:
9+
return "amd64"
10+
elif 23001 <= port <= 24000:
11+
return "loongson3"
12+
elif 24001 <= port <= 25000:
13+
return "arm64"
14+
elif 25001 <= port <= 26000:
15+
return "ppc64el"
16+
elif 26001 <= port <= 27000:
17+
return "riscv64"
18+
elif 27001 <= port <= 28000:
19+
return "loongarch64"
20+
elif 28001 <= port <= 29000:
21+
return "amd64"
22+
#这里有坑
23+
#目前都是amd64...
24+
#应该是emulation的部分
25+
else:
26+
return None
27+
28+
lines = sys.stdin.read().splitlines()
29+
30+
current_host_names = []
31+
current_host_lines = []
32+
current_arch = None
33+
34+
def output_host_block(host_names, host_lines, arch):
35+
# 如果能识别出架构,则在原Host行后面添加带前缀的主机名
36+
if arch is not None:
37+
# 构造带架构前缀的Host行
38+
new_host_names = host_names.copy()
39+
for hn in host_names:
40+
new_host_names.append(f"{arch}-{hn}")
41+
42+
# 输出修改后的Host行(原名称和带架构前缀的名称都包含在同一行)
43+
print("Host " + " ".join(new_host_names))
44+
# 输出其余配置行
45+
for line in host_lines[1:]:
46+
print(line)
47+
else:
48+
# 如果没有识别出架构,则原样输出
49+
for line in host_lines:
50+
print(line)
51+
print() # 块结束后加一行空行
52+
53+
for line in lines:
54+
# 匹配 Host 行
55+
if line.strip().startswith("Host "):
56+
# 如果之前有一个host块在收集,将其输出
57+
if current_host_names:
58+
output_host_block(current_host_names, current_host_lines, current_arch)
59+
60+
# 开始新的host块
61+
current_host_names = line.strip().split()[1:]
62+
current_host_lines = [line]
63+
current_arch = None
64+
else:
65+
# 不是Host行则加入当前host配置块
66+
current_host_lines.append(line)
67+
# 检测Port行来决定架构
68+
if line.strip().startswith("Port "):
69+
port_num = line.strip().split()[1]
70+
current_arch = get_arch_prefix(port_num)
71+
72+
# 文件结束后,如果还有一个host块未输出,则输出
73+
if current_host_names:
74+
output_host_block(current_host_names, current_host_lines, current_arch)
75+

0 commit comments

Comments
 (0)