From 72e66c90ce98998d2da9176e1edf8ead07b3385a Mon Sep 17 00:00:00 2001 From: ColdWindScholar <3590361911@qq.com> Date: Mon, 12 Feb 2024 18:46:16 +0800 Subject: [PATCH] Remove AIK --- .github/workflows/main.yml | 44 +++++++++++++++++++++++++ build.py | 66 ++++++++++++++++++++++++++++++++++++++ pyscripts/utils.py | 2 -- 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 build.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a60a94a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,44 @@ +name: "Build Tool" +permissions: + contents: write + discussions: write +on: + push: + paths: + - "build.py" + pull_request: + workflow_dispatch: +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.8.10 + uses: actions/setup-python@v4 + with: + # Semantic version range syntax or exact version of a Python version + python-version: '3.8.10' + # Optional - x64 or x86 architecture, defaults to x64 + architecture: 'x64' + - name: Update pip + run: python -m pip install -U --force-reinstall pip + - name: Build tool + run: | + python build.py + - name: Rename Tool + run: | + move ./NH4RomTool-win.zip ../NH4RomTool-${{ github.run_number }}-win.zip + - name: Upload release + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + omitBodyDuringUpdate: true + removeArtifacts: true + name: "NH4RomTool.${{ github.run_number }}" + tag: "CI_BUILD_${{ github.run_number }}" + body: | + Build times: ${{ github.run_number }} + Version: 4 + Note:If u cannot run it in linux,you may need do "chmod a+x ./*" + Minimum support: Ubuntu 20.04 (64bit),Windows Vista (32bit) + artifacts: "*.zip" diff --git a/build.py b/build.py new file mode 100644 index 0000000..9da081e --- /dev/null +++ b/build.py @@ -0,0 +1,66 @@ +import os +import platform +import shutil +import zipfile + +print(f'Build for {platform.system()}') +from pip._internal.cli.main import main as _main + +with open('requirements.txt', 'r', encoding='utf-8') as l: + for i in l.read().split("\n"): + print(f"Installing {i}") + _main(['install', i]) +local = os.getcwd() +name = 'NH4RomTool-win.zip' + + +def zip_folder(folder_path): + # 获取文件夹的绝对路径和文件夹名称 + abs_folder_path = os.path.abspath(folder_path) + + # 创建一个同名的zip文件 + zip_file_path = os.path.join(local, name) + archive = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) + + # 遍历文件夹中的所有文件和子文件夹 + for root, dirs, files in os.walk(abs_folder_path): + for file in files: + if file == name: + continue + file_path = os.path.join(root, file) + if ".git" in file_path: + continue + print(f"Adding: {file_path}") + # 将文件添加到zip文件中 + archive.write(file_path, os.path.relpath(file_path, abs_folder_path)) + + # 关闭zip文件 + archive.close() + print(f"Done!") + + +import PyInstaller.__main__ + +PyInstaller.__main__.run(['-F', 'ui.py', '--exclude-module=numpy', '-i', 'icon.ico']) + +if os.name == 'nt': + if os.path.exists(local + os.sep + "dist" + os.sep + "ui.exe"): + shutil.move(local + os.sep + "dist" + os.sep + "ui.exe", local) + +for i in os.listdir(local): + if i not in ['run', 'ui.exe', 'bin', 'LICENSE']: + print(f"Removing {i}") + if os.path.isdir(local + os.sep + i): + try: + shutil.rmtree(local + os.sep + i) + except Exception or OSError as e: + print(e) + elif os.path.isfile(local + os.sep + i): + try: + os.remove(local + os.sep + i) + except Exception or OSError as e: + print(e) + else: + print(i) + +zip_folder(".") diff --git a/pyscripts/utils.py b/pyscripts/utils.py index 7ead91b..ae4dc63 100755 --- a/pyscripts/utils.py +++ b/pyscripts/utils.py @@ -72,8 +72,6 @@ def unzip_file(zip_src, dst_dir): print('This is not zip') - - def zip_file(file, dst_dir): def get_all_file_paths(directory): # 初始化文件路径列表