fix
This commit is contained in:
parent
cfc1c698df
commit
f869222686
@ -488,22 +488,30 @@ class CBZUtils:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def zip_compression(cls, source_dir=None, target_file=None, remove=True):
|
def zip_compression(cls, source_dir=None, target_file=None, remove=True, min_files=1):
|
||||||
target_dir = os.path.dirname(target_file)
|
target_dir = os.path.dirname(target_file)
|
||||||
if not os.path.exists(target_dir):
|
if not os.path.exists(target_dir):
|
||||||
os.makedirs(target_dir)
|
os.makedirs(target_dir)
|
||||||
|
count_files = 0
|
||||||
if not os.path.exists(target_file) and source_dir is not None:
|
if not os.path.exists(target_file) and source_dir is not None:
|
||||||
with ZipFile(target_file, mode='w') as zf:
|
with ZipFile(target_file, mode='w') as zf:
|
||||||
for path, dir_names, filenames in os.walk(source_dir):
|
for path, dir_names, filenames in os.walk(source_dir):
|
||||||
|
count_files = len(filenames)
|
||||||
path = Path(path)
|
path = Path(path)
|
||||||
arc_dir = path.relative_to(source_dir)
|
arc_dir = path.relative_to(source_dir)
|
||||||
y = 0
|
y = 0
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
y = y + 1
|
y = y + 1
|
||||||
print("打包中:" + str(y) + "/" + str(len(filenames)), os.path.join(source_dir, filename))
|
print("打包中:" + str(y) + "/" + str(count_files), os.path.join(source_dir, filename))
|
||||||
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
|
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
|
||||||
zf.close()
|
zf.close()
|
||||||
logging.info(f"打包完成:{target_file}")
|
logging.info(f"打包完成:{target_file}")
|
||||||
|
if count_files <= min_files:
|
||||||
|
try:
|
||||||
|
os.path.remove(target_file)
|
||||||
|
logging.info(f"{target_file} 文件不符合最小文件数规则,已删除")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"{target_file} 删除报错")
|
||||||
|
|
||||||
@DeprecationWarning
|
@DeprecationWarning
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user