@@ -65,20 +65,6 @@ def log_message(message, log_file):
6565 log_file .write (message + "\n " )
6666 log_file .write ("-" * 50 + "\n " ) # 添加分隔线
6767
68-
69- def out_put (message , success = True ):
70- # 改变控制台输出颜色
71- if success :
72- print (Fore .GREEN + message )
73- else :
74- fail = fail + 1
75- notification .notify (
76- title = 'Pyinstaller快速打包程序提醒您' ,
77- message = f'打包程序炸啦!到现在一共炸了{ fail } 次。' ,
78- timeout = 10
79- )
80- print (Fore .RED + message )
81-
8268# 函数:打包 Python 文件
8369def package_py (file_path , file_name , log_file = "None" ):
8470 try :
@@ -98,14 +84,20 @@ def package_py(file_path, file_name, log_file="None"):
9884 subprocess .run (command , shell = True , check = True )
9985 if log_file != "None" :
10086 log_message (f"打包完成:{ file_path } " , log_file )
101- out_put (f"打包完成:{ file_path } " )
102- out_put (f"还剩{ acount - fcount } 个文件待打包。" )
87+ print (f"{ Fore . GREEN } 打包完成:{ file_path } " )
88+ print (f"{ Fore . GREEN } 还剩{ acount - fcount } 个文件待打包。" )
10389 except subprocess .CalledProcessError as e :
10490 error_message = f"打包失败:{ file_path } ,错误信息:{ e } "
10591 if log_file != "None" :
10692 log_message (error_message , log_file )
107- out_put (error_message , success = False )
108- out_put (f"还剩{ acount - fcount } 个文件待打包。" )
93+ fail = fail + 1
94+ notification .notify (
95+ title = 'Pyinstaller快速打包程序提醒您' ,
96+ message = f'打包程序炸啦!到现在一共炸了{ fail } 次。' ,
97+ timeout = 10
98+ )
99+ print (f"{ Fore .RED } { error_message } " )
100+ print (f"{ Fore .GREEN } 还剩{ acount - fcount } 个文件待打包。" )
109101 return file_path
110102
111103# 函数:打包 Pythonw 文件
@@ -127,14 +119,20 @@ def package_pyw(file_path, file_name, log_file="None"):
127119 subprocess .run (command , shell = True , check = True )
128120 if log_file != "None" :
129121 log_message (f"打包完成:{ file_path } " , log_file )
130- out_put (f"打包完成:{ file_path } " )
131- out_put (f"还剩{ acount - fcount } 个文件待打包。" )
122+ print (f"{ Fore . GREEN } 打包完成:{ file_path } " )
123+ print (f"{ Fore . GREEN } 还剩{ acount - fcount } 个文件待打包。" )
132124 except subprocess .CalledProcessError as e :
133125 error_message = f"打包失败:{ file_path } ,错误信息:{ e } "
134126 if log_file != "None" :
135127 log_message (error_message , log_file )
136- out_put (error_message , success = False )
137- out_put (f"还剩{ acount - fcount } 个文件待打包。" )
128+ fail = fail + 1
129+ notification .notify (
130+ title = 'Pyinstaller快速打包程序提醒您' ,
131+ message = f'打包程序炸啦!到现在一共炸了{ fail } 次。' ,
132+ timeout = 10
133+ )
134+ print (f"{ Fore .RED } { error_message } " )
135+ print (f"{ Fore .GREEN } 还剩{ acount - fcount } 个文件待打包。" )
138136 return file_path
139137
140138# 打开日志文件,准备记录日志
@@ -207,13 +205,13 @@ def package_pyw(file_path, file_name, log_file="None"):
207205 file_path = os .path .join (root , file )
208206 countd = countd + 1
209207 os .remove (file_path )
210- print (f'已删除源文件: { file_path } (还剩{ acount - countd } 个源文件)' )
208+ print (f'{ Fore . GREEN } 已删除源文件: { file_path } (还剩{ acount - countd } 个源文件)' )
211209
212210notification .notify (
213211 title = 'Pyinstaller快速打包程序提醒您' ,
214212 message = f'文件删除完成!总共删除了{ countd } 个原文件' ,
215213 timeout = 10
216214)
217- print (f"文件删除完成!总共删除了{ countd } 个原文件" )
215+ print (f"{ Fore . GREEN } 文件删除完成!总共删除了{ countd } 个原文件" )
218216
219217input ("按 ENTER 键继续..." )
0 commit comments