Skip to content

Commit c934534

Browse files
authored
Update nuitka_build.py
1 parent 1c533b4 commit c934534

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

package/nuitka_build.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@
77
from pathlib import Path
88
# from zip import zip_files_and_folders
99

10+
def run_command_with_input(cmd):
11+
"""执行命令并自动响应[Yes]/No提示"""
12+
process = subprocess.Popen(
13+
cmd,
14+
stdout=subprocess.PIPE,
15+
stderr=subprocess.STDOUT, # 合并标准错误到标准输出
16+
stdin=subprocess.PIPE,
17+
text=True, # 启用文本模式
18+
encoding='utf-8', # 设置编码
19+
bufsize=1 # 行缓冲
20+
)
21+
22+
# 实时读取输出并检测提示
23+
output_lines = []
24+
while True:
25+
line = process.stdout.readline()
26+
if not line: # 无输出表示进程结束
27+
break
28+
29+
print(line, end='') # 实时打印输出
30+
output_lines.append(line)
31+
32+
# 检测到[Yes]/No提示时自动输入yes
33+
if "Yes" in line:
34+
process.stdin.write("yes\n")
35+
process.stdin.flush()
36+
37+
# 等待进程结束并获取返回码
38+
returncode = process.wait()
39+
return subprocess.CompletedProcess(cmd, returncode, stdout=''.join(output_lines))
40+
1041
def main():
1142
print("="*50)
1243
print("="*50)
@@ -62,14 +93,6 @@ def main():
6293
arrch = "x64"
6394
output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine)
6495

65-
# 检查操作系统和架构
66-
# if Machine not in task.get('os', []):
67-
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前操作系统 {Machine}")
68-
# continue
69-
# if arrch not in task.get('arch', []):
70-
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前架构 {arrch}")
71-
# continue
72-
7396
# 检查Python文件是否存在
7497
if not python_file.exists():
7598
print(f"错误: Python文件不存在 {python_file}")
@@ -108,7 +131,8 @@ def main():
108131

109132
# 打印并执行命令
110133
print("执行命令:", ' '.join(cmd))
111-
result = subprocess.run(cmd)
134+
# 使用增强的命令执行函数
135+
result = run_command_with_input(cmd)
112136

113137
if result.returncode == 0:
114138
print(f"(onefile)打包成功: {dist_path / output_name}")

0 commit comments

Comments
 (0)