52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
|
import os
|
||
|
import shutil
|
||
|
import PyInstaller.__main__
|
||
|
|
||
|
def clean_build_dirs():
|
||
|
"""清理构建目录"""
|
||
|
dirs_to_clean = ['build', 'dist']
|
||
|
for dir_name in dirs_to_clean:
|
||
|
if os.path.exists(dir_name):
|
||
|
shutil.rmtree(dir_name)
|
||
|
|
||
|
def create_required_dirs():
|
||
|
"""创建必要的目录"""
|
||
|
os.makedirs('dist/data/xhs/json/media', exist_ok=True)
|
||
|
|
||
|
def copy_required_files():
|
||
|
"""复制必要的文件"""
|
||
|
# 复制配置文件
|
||
|
if os.path.exists('config'):
|
||
|
shutil.copytree('config', 'dist/config', dirs_exist_ok=True)
|
||
|
|
||
|
# 复制其他必要文件
|
||
|
files_to_copy = [
|
||
|
'main.py',
|
||
|
# 添加其他需要复制的文件
|
||
|
]
|
||
|
|
||
|
for file in files_to_copy:
|
||
|
if os.path.exists(file):
|
||
|
shutil.copy2(file, 'dist/')
|
||
|
|
||
|
def main():
|
||
|
# 清理旧的构建文件
|
||
|
clean_build_dirs()
|
||
|
|
||
|
# 运行PyInstaller
|
||
|
PyInstaller.__main__.run([
|
||
|
'build_exe.spec',
|
||
|
'--clean',
|
||
|
'--noconfirm'
|
||
|
])
|
||
|
|
||
|
# 创建必要的目录
|
||
|
create_required_dirs()
|
||
|
|
||
|
# 复制必要的文件
|
||
|
copy_required_files()
|
||
|
|
||
|
print("打包完成!")
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|