龙空技术网

Qt Windows打包程序脚本

QT高级进阶 366

前言:

眼前各位老铁们对“ubuntuqt打包”大概比较关心,姐妹们都想要知道一些“ubuntuqt打包”的相关知识。那么小编也在网摘上汇集了一些关于“ubuntuqt打包””的相关资讯,希望看官们能喜欢,你们快快来学习一下吧!

Qt打包程序的原理: 使用Windeployt 将Qt相关的依赖打进文件夹中,以及Windows相关的依赖

脚本代码

# 打包安装脚本import osfrom time import timefrom traceback import format_exception_onlyimport zipfileimport datetimeimport yagmailfrom upload import cos_upload_file# 选择windeployqt.exe 以及需要执行的程序 xxxx.exeinstall_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_}成功")
需要安装的依赖:

QT开发交流+赀料君羊:714620761

cachetools==5.2.0certifi==2022.6.15charset-normalizer==2.1.0cos-python-sdk-v5==1.9.20crcmod==1.7cssselect==1.1.0cssutils==2.5.1dicttoxml==1.7.4distlib==0.3.5filelock==3.7.1idna==3.3lxml==4.9.1platformdirs==2.5.2premailer==3.10.0pycryptodome==3.15.0requests==2.28.1six==1.16.0urllib3==1.26.11virtualenv==20.16.3yagmail==0.15.280

标签: #ubuntuqt打包