@@ -33,14 +33,18 @@ def main():
3333 parser = argparse .ArgumentParser (description = 'Nuitka打包脚本' )
3434 parser .add_argument ('config' , help = '配置文件路径' )
3535 args = parser .parse_args ()
36- cpu_count = os .cpu_count ()
37- # 读取配置文件
38- with open (args .config , 'r' , encoding = 'utf-8' ) as f :
39- config = yaml .safe_load (f )
4036
4137 # 基础路径设置
4238 base_dir = Path (__file__ ).parent .parent # 项目根目录
4339 upx_dir = base_dir / './upx/' # UPX目录
40+
41+ # 读取配置文件
42+ config_path = base_dir / args .config
43+ if not config_path .exists ():
44+ print (f"错误: 配置文件不存在 { config_path } " )
45+ sys .exit (1 )
46+ with open (str (config_path ), 'r' , encoding = 'utf-8' ) as f :
47+ config = yaml .safe_load (f )
4448
4549 success_count = 0
4650 task_error_list = []
@@ -55,7 +59,6 @@ def main():
5559 python_file = base_dir / task ['python-file' ]
5660 dist_path = base_dir / task ['distpath' ]
5761 requirements = task .get ('install-requirements' , [])
58- use_upx = task .get ('upx' , False )
5962 enable_plugins = task .get ('enable-plugins' , [])
6063
6164 # onefile = task.get('onefile', 0)
@@ -164,16 +167,19 @@ def main():
164167 except subprocess .TimeoutExpired :
165168 print (f"任务[{ i } /{ len (config )} { task ['name' ]} ] 执行超时 { timeout } 秒" )
166169 print (f"任务[{ i } /{ len (config )} { task ['name' ]} ]失败: { e } " )
170+ os .remove (t_file_path )
167171 task_error_list .append (task ['name' ])
168172 continue
169173 else :
170174 result = subprocess .run (cmd )
171175
172176 if result .returncode == 0 :
173177 print (f"打包成功: { dist_path / output_name } " )
178+ os .remove (t_file_path )
174179 success_count += 1
175180 else :
176181 print (f"打包失败,退出码: { result .returncode } " )
182+ os .remove (t_file_path )
177183 except Exception as e :
178184 print (f"任务[{ i } /{ len (config )} { task ['name' ]} ]失败: { e } " )
179185 task_error_list .append (task ['name' ])
0 commit comments