pyhton文件压缩

import os,os.path
import zipfile
import configparser
import win32process
import win32event#zip file
def zip_updatepkg(dirname, zipfilename):filelist = []if os.path.isfile(dirname):filelist.append(dirname)else :for root, dirs, files in os.walk(dirname):for name in files:filelist.append(os.path.join(root, name))zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED)for tar in filelist:arcname = tar[len(dirname):]#print arcnamezf.write(tar,arcname)zf.close()#copy file
def copyfile(sourceFile, targetFile):if os.path.exists(targetFile) is True:os.remove(targetFile)open(targetFile, "wb").write(open(sourceFile, "rb").read())
#copy dir
def copyFiles(sourceDir,  targetDir):if sourceDir.find(".svn") > 0:returnfor file in os.listdir(sourceDir):sourceFile = os.path.join(sourceDir,  file)targetFile = os.path.join(targetDir,  file)if os.path.isfile(sourceFile):if not os.path.exists(targetDir):os.makedirs(targetDir)copyfile(sourceFile, targetFile)if os.path.isdir(sourceFile):First_Directory = FalsecopyFiles(sourceFile, targetFile)#generate update pkg, flag: 209 or p2nhz
def generate_updatepkg(release_path, zip_path, installpkg_path, flag, version):configFilePath = release_path + r'constsettings_' + flag + r'.ini'print(configFilePath)#read configconfig = configparser.ConfigParser()config.read(configFilePath)#config.add_section('AppInfo')config.set('AppInfo', 'version', version)#save configcfg = open(configFilePath, 'w')config.write(cfg)cfg.close()copyfile(configFilePath, installpkg_path + r'constsettings.ini')copyfile(configFilePath, release_path + r'constsettings.ini')zip_updatepkg(installpkg_path, zip_path + r'updatepkg_' + flag + r'_' + version + r'.zip')#build inno setupcurrpath = os.path.dirname(__file__)innosetup_path = r'D:\\Program Files (x86)\\Inno Setup 5\\Compil32.exe'innosetup_script = os.path.abspath(currpath + r'\\****.iss')print(innosetup_script)handle = win32process.CreateProcess(innosetup_path, " /cc \"" + innosetup_script + "\"", None, None, 0, win32process.CREATE_NO_WINDOW, None, None, win32process.STARTUPINFO())win32event.WaitForSingleObject(handle[0], 600000)setup_name = r'hzxf_client_setup_' + flag + r'.exe' copyfile(currpath + r'/Output/****_setup.exe', zip_path + setup_name)if __name__ == '__main__':currpath = os.path.dirname(__file__)release_path = os.path.join(currpath, r'../bin/release/')release_path = os.path.abspath(release_path) + r'\\'#version tag pathzip_path = os.path.join(currpath, r'../../../tags/pc-client/2.0.6/2.0.6.9963-20160705/')zip_path = os.path.abspath(zip_path) + r'\\'if os.path.exists(zip_path) is False :os.makedirs(zip_path)#installpkg pathinstallpkg_path = zip_path + r'install_pkg/'if os.path.exists(installpkg_path) is False :os.makedirs(installpkg_path)#copy files to installpkg_path for compress zipprint(r'----------------------------------------')images_path = release_path + r'Images/'copyFiles(images_path, installpkg_path + r'Images/')#copyfile(release_path + r'constsettings.ini', installpkg_path + r'constsettings.ini')copyfile(release_path + r'hello.exe', installpkg_path + r'hello.exe')#build and zip to zip_path for different versiongenerate_updatepkg(release_path, zip_path, installpkg_path, r'209', '12')generate_updatepkg(release_path, zip_path, installpkg_path, r'202', '5')

转载于:https://www.cnblogs.com/jiushishuai/p/9452098.html

python文件压缩相关推荐

  1. python读写压缩文件使用gzip和bz2

    python读写压缩文件使用gzip和bz2 #读取压缩文件 # gzip compression import gzip with gzip.open('somefile.gz', 'rt') as ...

  2. python编写的软件界面-用Python写一个带图形界面的文件压缩软件

    这又是一篇用Python写小软件系列,最近有点写上瘾了,文件压缩和解压我们在日常工作学习中会经常用到,比如winrar.快压.好压等压缩软件,猿人学用Python做个简易图形界面的压缩软件. 打开之后 ...

  3. python打开指定文件-python打包压缩、读取指定目录下的指定类型文件

    下面通过代码给大家介绍python打包压缩指定目录下的指定类型文件,具体代码如下所示: import os import datetime import tarfile import fnmatch ...

  4. python解压文件_使用Python实现文件压缩和解压

    大家可能都熟悉.zip格式的文件.它可以把多个文件,压缩成一个文件.这在网络上传输时很有用,而且节省硬盘空间. 接下来,我们使用Python实现压缩和解压. 读取ZIP文件信息 要读取ZIP文件的内容 ...

  5. Python的压缩文件处理 zipfile tarfile

    本文从以下两个方面, 阐述Python的压缩文件处理方式: 一. zipfile 二. tarfile 一. zipfile 虽然叫zipfile,但是除了zip之外,rar,war,jar这些压缩( ...

  6. php 批量压缩png,利用Python批量压缩png方法实例(支持过滤个别文件与文件夹)...

    前言 本文主要给大家介绍的关于Python批量压缩png的相关资料,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 1.需求 为什么会有这个需求?是因为游戏的资源大多是png图片,需要 ...

  7. python解压到指定文件夹_在Python中压缩和解压文件

    Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. 如果你已经使用计算机一段时间,你可能遇到了.zip扩展名的文件.它们是可以保存许多其他文件,文件夹和子文件 ...

  8. c++创建文件_使用Python实现文件压缩和解压

    (点击上方快速关注并设置为星标,一起学Python) 来源:网络 大家可能都熟悉.zip格式的文件.它可以把多个文件,压缩成一个文件.这在网络上传输时很有用,而且节省硬盘空间. 接下来,我们使用Pyt ...

  9. python读压缩文件内容_Python读写压缩文件的方法

    问题 你想读写一个gzip或bz2格式的压缩文件. 解决方案 gzip 和bz2模块可以很容易的处理这些文件. 两个模块都为 open()函数提供了另外的实现来解决这个问题. 比如,为了以文本形式读取 ...

最新文章

  1. 数据库 user schema sqlserver 关系
  2. 中通知设置响铃_iOS 13.1.3 正式版:解决来电不响铃问题
  3. 二项分布和Beta分布
  4. Mysql的sql语句,Delete 中包含 not in
  5. 新华三的背景_智能联接,新华三在重新勾勒拓扑图
  6. MySql 你真的会使用字符串索引吗???
  7. Cortex-M3的存储器系统
  8. Java多线程学习四:共有哪 3 类线程安全问题
  9. weex android 交互,weex项目接入到Android studio中
  10. PHP之数组函数(2)
  11. zzzkkk666用户名密码
  12. 《涂抹Oracle—三思笔记之一步一步学Oracle》看书笔记(序言)
  13. 闻之色变-翻译公司用翻译工具翻译?!
  14. 什么是Adobe Creative Cloud,值得吗?
  15. WebWork + Spring + iBatis + MySql 实例(Jonson)
  16. 时间序列学习(5):ARMA模型定阶(AIC、BIC准则、Ljung-Box检验)
  17. 解决:元素内容必须由格式正确的字符数据或标记组成。
  18. Vue - 加载静态图片的方式
  19. HashCat配GPU
  20. 基于JAVA的停车场管理系统

热门文章

  1. python画五角星-Python第八课 绘制五角星1.0
  2. python对文件的读操作方法有哪些-python--文件的读写操作
  3. python3.8.5怎么用-Python 3.8 新功能大揭秘【新手必学】
  4. python写文件读文件-Python 实例:读写文件
  5. 怎么用python处理excel文件-用python处理excel文件有多轻松?工作从未如此简单
  6. python画图简单代码-简单画图 - python代码库 - 云代码
  7. python基础代码-python基础知识和练习代码
  8. python跟java-Java与Python两大幸存者谁更胜一筹呢
  9. python画动态爱心-使用Python画出小人发射爱心的代码
  10. 编程爱好者学vb还是python-编程语言Java和Python对比哪个比较好