use double zip

This commit is contained in:
shenjack 2023-06-10 18:24:24 +08:00
parent d62dcc2d3c
commit b9363bb245
4 changed files with 16 additions and 109 deletions

View File

@ -102,6 +102,14 @@ jobs:
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: Difficult-Rocket_v${{env.DR_version}}-${{runner.os}}${{matrix.python-version}}-Build.${{github.run_number}}+${{env.short_sha}} name: Difficult-Rocket_v${{env.DR_version}}-${{runner.os}}${{matrix.python-version}}-Build.${{github.run_number}}+${{env.short_sha}}.zip
path: | path: |
build/github/DR.dist build/github/DR.dist
# Uploads artifact
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: Difficult-Rocket_v${{env.DR_version}}-${{runner.os}}${{matrix.python-version}}-Build.${{github.run_number}}+${{env.short_sha}}.zip.zip
path: |
build/Difficult_Rocket.zip

View File

@ -1,96 +0,0 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
import os
import sys
import shutil
import zipfile
if sys.platform == "win32":
os.system('')
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)
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('-----------')
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',
]
# 删除不必要的文件
# 如果忽略不存在或无法删除的文件
os.chdir('./build/Difficult-Rocket')
print(os.listdir())
print(os.path.abspath(os.curdir))
print("=============")
for the_file in un_use_file:
print(f"file: {the_file}")
try:
os.remove(the_file)
shutil.rmtree(the_file, ignore_errors=True)
print(f"origin remove {the_file}")
except PermissionError:
print(f"Permission denied at {os.path.abspath(the_file)}")
except (IsADirectoryError, FileNotFoundError):
# 如果是目录
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("=============")
os.chdir('../../')
def copy_data_file():
files = {
'libs/pyglet': 'build/pyglet',
'libs/Difficult_Rocket_rs/lib': 'build/libs/Difficult_Rocket_rs/lib',
'libs/fonts': 'build/libs/fonts'
}
# 使用 shutil 复制文件
# os.mkdir("build/pyglet")
# os.mkdir("build/libs")
# os.mkdir("build/libs/Difficult_Rocket_rs")
# os.mkdir("build/libs/Difficult_Rocket_rs/lib")
for src, dist in files.items():
try:
shutil.copytree(src, dist)
except Exception as e:
print(f"error: {e}")
if __name__ == '__main__':
show_files()
remove_un_use()
show_files()
copy_data_file()
show_files()
make_zip()

View File

@ -1,5 +0,0 @@
# for checker
# ruff >= 0.0.253
# for dsm upload
synology-api >= 0.5.1

View File

@ -76,11 +76,11 @@ if __name__ == '__main__':
traceback.print_exc() traceback.print_exc()
print('Remove Useless Files Done!') print('Remove Useless Files Done!')
# 压缩 # 压缩
# with zipfile.ZipFile(Path('./build/Difficult_Rocket.zip'), 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as dist_zip: with zipfile.ZipFile(Path('./build/Difficult_Rocket.zip'), 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as dist_zip:
# for path, sub_paths, sub_files in os.walk(compiler.output_path / 'DR.dist'): for path, sub_paths, sub_files in os.walk(compiler.output_path / 'DR.dist'):
# print(f'writing {path}') print(f'writing {path}')
# for file in sub_files: for file in sub_files:
# file_path = os.path.join(path, file) file_path = os.path.join(path, file)
# dist_zip.write(file_path) dist_zip.write(file_path)
# print('Zip Done!') print('Zip Done!')
sys.exit(0) sys.exit(0)