zoukankan      html  css  js  c++  java
  • python学习笔记(23)——python压缩bin包

    说明(2017-12-25 10:43:20):

    1. CZ写的压缩bin包代码,记下来以后好抄。

     1 # coding:utf-8
     2 '''
     3 Created on 2014年8月14日
     4 
     5 @author: johnsoncheng
     6 '''
     7 
     8 import zipfile, os
     9 
    10 IGNORE_POSTFIX_LIST = {".mp3", ".wav", ".jpg", ".JPG", ".wma", ".png", ".mp4", ".avi", ".wmv"}
    11 
    12 
    13 def zipFolder():
    14     # srcFolder = r"E:XZJYRootFolder
    ootMath_Video"
    15     # tarFile = r"E:XZJYRootFolder
    ootDataMath_Video.zip"
    16     rootFolder = r"D:软件发布压缩根目录"
    17     #rootFolder = r"D:XZJYRootFolder
    ootData1
    es"
    18     # 遍历所有文件夹
    19     folderList = os.listdir(rootFolder)
    20     for folder in folderList:
    21         folderPath = os.path.join(rootFolder, folder)
    22         if os.path.isdir(folderPath):
    23             # 取得二级目录
    24             folderList1 = os.listdir(folderPath)
    25             for folder1 in folderList1:
    26                 folderPath1 = os.path.join(folderPath, folder1)
    27                 if os.path.isdir(folderPath1):
    28                     zipPath = os.path.join(folderPath, folder1 + ".bin")
    29                     with zipfile.ZipFile(zipPath, 'w', allowZip64=True) as myzip:
    30                         zipSubFolder(myzip, folderPath1, folderPath)
    31     pass
    32 
    33 def zipSubFolder(zipObj, folderPath, rootFolderPath):
    34     global IGNORE_POSTFIX_LIST
    35     print("compressing " + folderPath)
    36     # 取得当前文件夹差异路径
    37     folderRelativePath = folderPath[len(rootFolderPath): ]
    38     # 插入当前文件夹
    39     zipObj.write(folderPath, folderRelativePath)
    40     # 遍历所有子实体
    41     entryList = os.listdir(folderPath)
    42     # 处理所有子文件夹
    43     for entry in entryList:
    44         entryPath = os.path.join(folderPath, entry)
    45         if os.path.isdir(entryPath):
    46             zipSubFolder(zipObj, entryPath, rootFolderPath)
    47     # 处理子文件
    48     for entry in entryList:
    49         entryPath = os.path.join(folderPath, entry)
    50         if os.path.isfile(entryPath):
    51             fileRelativePath = folderPath[len(rootFolderPath): ] + "/" + entry
    52             tempRoot, tempPostFix = os.path.splitext(fileRelativePath)
    53             if tempPostFix in IGNORE_POSTFIX_LIST:
    54                 zipObj.write(entryPath, fileRelativePath)
    55             else:
    56                 zipObj.write(entryPath, fileRelativePath, zipfile.ZIP_DEFLATED)
    57     pass
    58 
    59 
    60 if __name__ == '__main__':
    61     print("************** start *************")
    62     zipFolder()
    63     print("************** end *************")
    64     pass
  • 相关阅读:
    命令用法示例
    Elastic:用Docker部署Elastic栈
    Elastic:使用Heartbeat进行Uptime监控
    Elastic:如何在一个机器上同时模拟多个node
    Elastic 使用索引生命周期管理实现热温冷架构
    Logstash:运用jdbc_streaming来丰富我们的数据
    Logstash:多个配置文件(conf)
    Logstash:处理多个input
    使用 Logstash 和 JDBC 确保 Elasticsearch 与关系型数据库保持同步
    Logstash:把MySQL数据导入到Elasticsearch中
  • 原文地址:https://www.cnblogs.com/Jacklovely/p/8108328.html
Copyright © 2011-2022 走看看