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
|
2022-12-29 17:26:39 +08:00
|
|
|
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
|
|
|
|
2022-12-29 17:26:39 +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:28:48 +08:00
|
|
|
def show_files():
|
|
|
|
print("----------")
|
|
|
|
try:
|
|
|
|
print(os.listdir('libs'))
|
|
|
|
print(os.listdir('build'))
|
|
|
|
print(os.listdir('build/libs'))
|
|
|
|
print(os.listdir('build/libs/fonts'))
|
|
|
|
print(os.listdir("build/libs/Difficult_Rocket_rs"))
|
|
|
|
except Exception as e:
|
|
|
|
print(f'list file error {e}')
|
|
|
|
print('-----------')
|
|
|
|
|
|
|
|
|
2023-03-02 13:15:29 +08:00
|
|
|
def remove_un_use():
|
|
|
|
un_use_file = [
|
2023-03-02 13:28:48 +08:00
|
|
|
'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')
|
2023-03-02 13:28:48 +08:00
|
|
|
print(os.listdir())
|
|
|
|
print(os.path.abspath(os.curdir))
|
|
|
|
print("=============")
|
|
|
|
for the_file in un_use_file:
|
|
|
|
print(f"file: {the_file}")
|
2023-03-02 13:15:29 +08:00
|
|
|
try:
|
2023-03-02 13:28:48 +08:00
|
|
|
os.remove(the_file)
|
|
|
|
shutil.rmtree(the_file, ignore_errors=True)
|
|
|
|
print(f"origin remove {the_file}")
|
2023-03-02 13:15:29 +08:00
|
|
|
except PermissionError:
|
2023-03-02 13:28:48 +08:00
|
|
|
print(f"Permission denied at {os.path.abspath(the_file)}")
|
|
|
|
except (IsADirectoryError, FileNotFoundError):
|
2023-03-02 13:25:11 +08:00
|
|
|
# 如果是目录
|
2023-03-02 13:28:48 +08:00
|
|
|
try:
|
|
|
|
shutil.rmtree(the_file)
|
|
|
|
print(f"remove dir {os.path.abspath(the_file)}")
|
|
|
|
except FileNotFoundError:
|
|
|
|
print(f"FileNotFoundError at {os.path.abspath(the_file)}")
|
|
|
|
print("=============")
|
2023-03-02 13:15:29 +08:00
|
|
|
os.chdir('../../')
|
|
|
|
|
|
|
|
|
|
|
|
def copy_data_file():
|
|
|
|
files = {
|
2023-03-02 13:28:48 +08:00
|
|
|
'libs/pyglet': 'build/pyglet',
|
|
|
|
'libs/Difficult_Rocket_rs/lib': 'build/libs/Difficult_Rocket_rs/lib',
|
|
|
|
'libs/fonts': 'build/libs/fonts'
|
2023-03-02 13:15:29 +08:00
|
|
|
}
|
|
|
|
# 使用 shutil 复制文件
|
2023-03-02 13:28:48 +08:00
|
|
|
# os.mkdir("build/pyglet")
|
|
|
|
# os.mkdir("build/libs")
|
|
|
|
# os.mkdir("build/libs/Difficult_Rocket_rs")
|
|
|
|
# os.mkdir("build/libs/Difficult_Rocket_rs/lib")
|
2023-03-02 13:15:29 +08:00
|
|
|
for src, dist in files.items():
|
2023-03-02 13:28:48 +08:00
|
|
|
try:
|
|
|
|
shutil.copytree(src, dist)
|
|
|
|
except Exception as e:
|
|
|
|
print(f"error: {e}")
|
2023-01-22 09:19:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-03-02 13:28:48 +08:00
|
|
|
show_files()
|
2023-03-02 13:15:29 +08:00
|
|
|
remove_un_use()
|
2023-03-02 13:28:48 +08:00
|
|
|
show_files()
|
2023-03-02 13:15:29 +08:00
|
|
|
copy_data_file()
|
2023-03-02 13:28:48 +08:00
|
|
|
show_files()
|
2023-01-22 09:19:13 +08:00
|
|
|
make_zip()
|