Difficult-Rocket/.github/workflows/post_compile.py

65 lines
1.7 KiB
Python
Raw Normal View History

2022-12-29 11:15:00 +08:00
# -------------------------------
# Difficult Rocket
2023-01-20 14:08:12 +08:00
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
2022-12-29 11:15:00 +08:00
# All rights reserved
# -------------------------------
import os
import sys
2022-12-29 12:08:08 +08:00
import zipfile
2023-03-02 13:15:29 +08:00
import shutil
2022-12-29 12:08:08 +08:00
if sys.platform == "win32":
os.system('')
2022-12-29 12:08:08 +08:00
2023-01-22 09:19:13 +08:00
def make_zip():
with zipfile.ZipFile('./build/main.zip', 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as dist_zip:
for path, sub_paths, sub_files in os.walk('./build/Difficult-Rocket'):
print(f'writing {path}')
for file in sub_files:
file_path = os.path.join(path, file)
dist_zip.write(file_path)
2022-12-29 12:08:08 +08:00
2023-01-22 09:19:13 +08:00
2023-03-02 13:15:29 +08:00
def remove_un_use():
un_use_file = [
'./libs/fonts/Fira_Code',
'./libs/fonts/scientifica'
'./libs/fonts/Monocraft.otf',
'./libs/fonts/SmileySans-Oblique.ttf'
'./libs/fonts/HarmonyOS_Sans/HarmonyOS_Sans_Condensed',
'./libs/fonts/HarmonyOS_Sans/HarmonyOS_Sans'
2023-01-22 17:21:21 +08:00
]
2023-03-02 13:15:29 +08:00
# 删除不必要的文件
# 如果忽略不存在或无法删除的文件
os.chdir('./build/Difficult-Rocket')
for file in un_use_file:
try:
os.remove(file)
except FileNotFoundError:
pass
except PermissionError:
pass
2023-03-02 13:25:11 +08:00
except IsADirectoryError:
# 如果是目录
shutil.rmtree(file)
2023-03-02 13:15:29 +08:00
os.chdir('../../')
def copy_data_file():
files = {
'./libs/pyglet': './build/pyglet',
'./libs/Difficult_Rocket_rs/lib': './build/libs/Difficult_Rocket_rs/lib',
}
# 使用 shutil 复制文件
for src, dist in files.items():
shutil.copytree(src, dist)
2023-01-22 09:19:13 +08:00
if __name__ == '__main__':
print(os.listdir('./build'))
2023-03-02 13:15:29 +08:00
remove_un_use()
copy_data_file()
2023-01-22 09:19:13 +08:00
make_zip()