Qt Windows打包程序脚本
2023-09-14 09:05:11 时间
Qt打包程序的原理: 使用Windeployt 将Qt相关的依赖打进文件夹中,以及Windows相关的依赖
脚本代码
# 打包安装脚本
import os
from time import time
from traceback import format_exception_only
import zipfile
import datetime
import yagmail
from upload import cos_upload_file
# 选择windeployqt.exe 以及需要执行的程序 xxxx.exe
install_path = '''C:\\Qt\\Qt5.14.2\\5.14.2\\msvc2017_64\\bin\\windeployqt.exe ..\\bin\\xxxx.exe'''
def send_email(file_path, email_address,cc_email, str_content,str_title):
"""
通知相关
"""
yag = yagmail.SMTP( user='0011@qq.com', pwd='0011', host=xlook.cn',port=587, smtp_starttls=True, smtp_ssl=False)
if file_path != "":
yag.send(to = email_address, cc=cc_email ,subject = str_title ,contents=str_content, attachments=file_path)
else:
yag.send(to = email_address, cc=cc_email ,subject = str_title ,contents=str_content)
def get_file_path(root_path, file_list, dir_list):
# 获取该目录下所有的文件名称和目录名称
dir_or_files = os.listdir(root_path)
for dir_file in dir_or_files:
# 获取目录或者文件的路径
dir_file_path = os.path.join(root_path, dir_file)
# 判断该路径为文件还是路径
if os.path.isdir(dir_file_path):
dir_list.append(dir_file_path)
# 递归获取所有文件和目录的路径
get_file_path(dir_file_path, file_list, dir_list)
else:
file_list.append(dir_file_path)
def delete_file(file_list):
for file_name in file_list:
if file_name.endswith(".ilk") or file_name.endswith(".exp") or file_name.endswith(".pdb") or file_name.endswith(".bmp") or file_name.endswith(".log") or file_name.endswith(".lib") or file_name.endswith(".txt"):
print(file_name)
os.remove(file_name)
def get_zip(dirpath, outFullName):
"""
压缩指定文件夹
:param dirpath: 目标文件夹路径
:param outFullName: 压缩文件保存路径+xxxx.zip
:return: 无
"""
zip = zipfile.ZipFile(outFullName, "w", zipfile.ZIP_DEFLATED)
for path, dirnames, filenames in os.walk(dirpath):
# 去掉目标跟路径,只对目标文件夹下边的文件及文件夹进行压缩
fpath = path.replace(dirpath, '')
for filename in filenames:
zip.write(os.path.join(path, filename),
os.path.join(fpath, filename))
zip.close()
if __name__ == "__main__":
# 1. Qt依赖环境放在里面
os.system(install_path)
# 2. 删除debug文件
root_path = r"..\bin"
file_list = []
dir_list = []
get_file_path(root_path, file_list, dir_list)
delete_file(file_list)
# 3.Log文件夹删除
if os.path.exists("..\\bin\\Logs"):
os.removedirs("..\\bin\\Logs")
# 4.压缩文件夹
if not os.path.exists("..\\package"):
os.mkdir("..\\package")
times= datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
get_zip("..\\bin",f"..\\package\\{times}.zip")
print(f"《----当前安装包..\\package\\{times}.zip打包成功----》")
email_ = [""] # 需要发送的url
cc_email = ["xxx.com"]
res_url = cos_upload_file(f"..\\package\\{times}.zip")
# 安装包下载链接:{res_url}
send_email("",email_, cc_email, f"xxxx安装包 \n 打包时间:{times}\n 安装包下载链接: {res_url}","xxxx安装包")
print(f"发送安装包到{email_}成功")
需要安装的依赖:
cachetools==5.2.0
certifi==2022.6.15
charset-normalizer==2.1.0
cos-python-sdk-v5==1.9.20
crcmod==1.7
cssselect==1.1.0
cssutils==2.5.1
dicttoxml==1.7.4
distlib==0.3.5
filelock==3.7.1
idna==3.3
lxml==4.9.1
platformdirs==2.5.2
premailer==3.10.0
pycryptodome==3.15.0
requests==2.28.1
six==1.16.0
urllib3==1.26.11
virtualenv==20.16.3
yagmail==0.15.280
本文福利,莬费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击莬费领取↓↓
相关文章
- Qt动画播放之QMovie类[通俗易懂]
- Qt 之自定义搜索框
- Qt: 中文-常量中有换行符[通俗易懂]
- qt串口通信接收数据不完整_qt串口接收数据
- Qt —— QWebEngineView加载谷歌离线地图(包含离线地图瓦片下载制作)
- C/C++ Qt 常用数据结构
- C/C++ Qt 基础通用组件的应用
- 让Qt会说话
- 实现Windows客户端通过SSH连接Linux服务器(windows连接linux服务器)
- Windows与Linux远程连接:实现跨平台无缝通讯(windows远程连接linux)
- Qt MDI及其使用方法(详解版)
- Linux安装Qt:实现轻松易用之旅(linux中安装qt)
- 在windows 中无效Oracle Preferences Invalid on Windows Platform(oracle首选项)
- 如何在Linux平台上配置Qt环境(linux下qt配置)
- Linux下构建Qt程序步骤(linux打开qt)
- Linux Qt快速入门教程(linuxqt教程)
- 快速搭建 Qt 与 MySQL 的数据库应用(qt使用mysql)
- “Linux轻松与Windows双启:引导快速添加方法”(linux添加windows引导)
- 利用Qt轻松操作Oracle数据库(qt操作oracle)
- 使用Windows启动Redis命令:简单易学,让你轻松玩转Redis(windows启动redis命令)
- Qt在Linux操作系统中的运行和应用(qt运行linux)
- 如何在Linux上运行QT程序?(linux运行qt程序)
- Qt实现图片移动实例(图文教程)