@@ -175,7 +175,7 @@ def generate_iss_file():
175
175
def compress_folder_to_7z (source_folder , target_folder , archive_name ):
176
176
try :
177
177
# 压缩文件夹为7z格式
178
- with py7zr .SevenZipFile (os .path .join (target_folder , archive_name + '.7z' ), 'w' ) as archive :
178
+ with py7zr .SevenZipFile (str ( os .path .join (target_folder , archive_name + '.7z' ) ), 'w' ) as archive :
179
179
archive .writeall (source_folder , arcname = os .path .basename (source_folder ))
180
180
181
181
print (f"{ Fore .GREEN } ✓{ Fore .RESET } 压缩7z发行版 { Fore .BLUE } { archive_name } { Fore .RESET } 成功" )
@@ -187,10 +187,10 @@ def compress_folder_to_7z(source_folder, target_folder, archive_name):
187
187
def compress_folder_to_zip (source_folder , target_folder , archive_name ):
188
188
try :
189
189
# 压缩文件夹为zip格式
190
- with zipfile .ZipFile (os .path .join (target_folder , archive_name + '.zip' ), 'w' , zipfile .ZIP_DEFLATED ) as archive :
190
+ with zipfile .ZipFile (str ( os .path .join (target_folder , archive_name + '.zip' ) ), 'w' , zipfile .ZIP_DEFLATED ) as archive :
191
191
for root , dirs , files in os .walk (source_folder ):
192
192
for file in files :
193
- archive .write (os .path .join (root , file ), os .path .relpath (os .path .join (root , file ), source_folder ))
193
+ archive .write (str ( os .path .join (root , file )) , os .path .relpath (str ( os .path .join (root , file ) ), source_folder ))
194
194
195
195
print (f"{ Fore .GREEN } ✓{ Fore .RESET } 压缩zip发行版 { Fore .BLUE } { archive_name } { Fore .RESET } 成功" )
196
196
return True
@@ -204,8 +204,9 @@ def compress_releases():
204
204
compress_folder_to_zip (py_releases_dir , releases_dir , "Chinese_git_py" )
205
205
compress_folder_to_7z (pack_releases_dir , releases_dir , "Chinese_git" )
206
206
compress_folder_to_7z (py_releases_dir , releases_dir , "Chinese_git_py" )
207
+ subprocess .run (["iscc" , os .path .join (releases_dir , "pack.iss" )], check = True )
207
208
return True
208
- except :
209
+ except Exception :
209
210
return False
210
211
# -----------
211
212
@@ -218,10 +219,54 @@ def jobs_clean_up(step):
218
219
shutil .rmtree (py_releases_dir )
219
220
shutil .rmtree (repo_dir )
220
221
print (f"{ Fore .GREEN } ✓{ Fore .RESET } 成功清理工作文件" )
222
+ return True
221
223
except Exception as e :
222
224
print (f"{ Fore .RED } ✕{ Fore .RESET } 清理失败,因为:\n { Fore .RED } { e } { Fore .RESET } " )
225
+ return False
223
226
else :
224
227
print (f"{ Fore .YELLOW } ⚠{ Fore .RESET } 跳过清理,因为目录 { Fore .BLUE } { repo_dir } { Fore .RESET } 不存在" )
228
+ return True
229
+ elif step == "finish" :
230
+ if os .path .exists (repo_dir ):
231
+ # Chinese_git 仓库
232
+ try :
233
+ # 移除非空目录 repo_dir
234
+ shutil .rmtree (repo_dir )
235
+ print (f"{ Fore .GREEN } ✓{ Fore .RESET } 成功清理 Chinese_git 仓库文件" )
236
+ # 权限
237
+ except PermissionError :
238
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 清理 Chinese_git 仓库文件失败: { Fore .YELLOW } 权限不足{ Fore .RESET } " )
239
+ return False
240
+ except Exception as e :
241
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 清理 Chinese_git 仓库文件失败: { Fore .RED } { e } { Fore .RESET } " )
242
+ return False
243
+ if os .path .exists (os .path .join (script_dir , "yazicbs.github.io" )):
244
+ # (方法二) 公告文件所在仓库
245
+ try :
246
+ shutil .rmtree (os .path .join (script_dir , "yazicbs.github.io" ))
247
+ print (f"{ Fore .GREEN } ✓{ Fore .RESET } 成功清理 yazicbs.github.io 仓库文件" )
248
+ except PermissionError :
249
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 清理 yazicbs.github.io 仓库文件失败: { Fore .YELLOW } 权限不足{ Fore .RESET } " )
250
+ return False
251
+ except Exception as e :
252
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 清理 yazicbs.github.io 仓库文件失败: { Fore .RED } { e } { Fore .RESET } " )
253
+ return False
254
+ if os .path .exists (os .path .join (releases_dir , "pack.iss" )):
255
+ # 移除单文件
256
+ try :
257
+ os .remove (os .path .join (releases_dir , "pack.iss" ))
258
+ print (f"{ Fore .GREEN } ✓{ Fore .RESET } 成功清理 pack.iss 文件" )
259
+ except PermissionError :
260
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 清理 pack.iss 文件失败: { Fore .YELLOW } 权限不足{ Fore .RESET } " )
261
+ return False
262
+ except Exception as e :
263
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 清理 pack.iss 文件失败: { Fore .RED } { e } { Fore .RESET } " )
264
+ return False
265
+ print (f"{ Fore .GREEN } ✓{ Fore .RESET } 成功清理工作区!" )
266
+ return True
267
+ else :
268
+ print (f"{ Fore .RED } ✕{ Fore .RESET } 未知步骤 { Fore .BLUE } { step } { Fore .RESET } " )
269
+ return False
225
270
226
271
# --- main ---
227
272
def main ():
@@ -231,7 +276,8 @@ def main():
231
276
if copy_file ():
232
277
if generate_iss_file ():
233
278
if compress_releases ():
234
- return 0
279
+ if jobs_clean_up ("finish" ):
280
+ return 0
235
281
else :
236
282
jobs_clean_up ("clone" )
237
283
else :
0 commit comments