tar compress update
This commit is contained in:
parent
98394ab03d
commit
d69094169a
|
@ -15,7 +15,7 @@ from utils.hotkey import hotkey_judge
|
|||
from utils.frame_opt import frame_opt
|
||||
from utils.log import is_logSuffix, log_management
|
||||
from utils.args_yaml import argsYaml
|
||||
from utils.compress import webcam_zip
|
||||
from utils.compress import webcam_zip, webcam_tar
|
||||
|
||||
ROOT_PATH = sys.path[0] # 项目根目录
|
||||
|
||||
|
@ -193,8 +193,9 @@ def webcam_opencv(device_index="0",
|
|||
# ------------------压缩文件------------------
|
||||
if (is_compress and (is_autoSaveFrame or is_handSaveFrame)):
|
||||
# 自定义压缩文件名称
|
||||
webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath, zipMode)
|
||||
|
||||
# webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath, zipMode)
|
||||
webcam_tar(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath)
|
||||
|
||||
|
||||
def main(args):
|
||||
device_index = args.device
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# 创建时间:2022-01-19
|
||||
|
||||
import zipfile
|
||||
import tarfile
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
@ -17,6 +18,14 @@ def is_zipFile(zipName):
|
|||
sys.exit()
|
||||
|
||||
|
||||
# 判断tar文件名称
|
||||
def is_tarFile(tarName):
|
||||
tarNameSuffix = tarName.split('.')[-1]
|
||||
if tarNameSuffix != "tar":
|
||||
print(f'{tarName}:格式不正确!程序退出!')
|
||||
sys.exit()
|
||||
|
||||
|
||||
# zip压缩
|
||||
def webcam_zip(is_autoZipName, zipName, preZipFilePath, zipMode):
|
||||
if (is_autoZipName):
|
||||
|
@ -37,3 +46,26 @@ def webcam_zip(is_autoZipName, zipName, preZipFilePath, zipMode):
|
|||
# ----------压缩结束----------
|
||||
zip_file.close()
|
||||
print(f'压缩成功!已保存在:{zipName}')
|
||||
|
||||
|
||||
# zip压缩
|
||||
def webcam_tar(is_autoTarName, tarName, preTarFilePath, tarMode="w:gz"):
|
||||
if (is_autoTarName):
|
||||
# 自动命名
|
||||
tarNameTmp = str(preTarFilePath).split('/')[-1]
|
||||
tarName = f'{ROOT_PATH}/{tarNameTmp}.tar'
|
||||
else:
|
||||
# 手动命名
|
||||
is_tarFile(tarName) # 判断tar名称格式
|
||||
|
||||
# ----------压缩开始----------
|
||||
tar_file = tarfile.open(tarName, tarMode) # 实例化tarfile对象
|
||||
|
||||
file_list = os.listdir(preTarFilePath) # 获取目录下的文件名称
|
||||
for i in range(len(file_list)):
|
||||
# 写入压缩文件
|
||||
tar_file.add(f'{preTarFilePath}/{file_list[i]}') # 压缩单个文件
|
||||
|
||||
# ----------压缩结束----------
|
||||
tar_file.close()
|
||||
print(f'压缩成功!已保存在:{tarName}')
|
||||
|
|
Loading…
Reference in New Issue