You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
2 years ago
|
import os.path
|
||
|
from log import logger
|
||
|
import unzip
|
||
|
import file
|
||
|
import db
|
||
|
|
||
|
root_path = r'F:\Temp\sjry\hj'
|
||
|
|
||
|
# 初始化数据库
|
||
|
db_obj = db.DbAction()
|
||
|
file_obj = file.Files(root_path)
|
||
|
unzip_obj = unzip.UnzipFile()
|
||
|
|
||
|
|
||
|
# 开始任务
|
||
|
def start_unzip_task():
|
||
|
result = True
|
||
|
for folder in file_obj.get_root_folder_list():
|
||
|
all_file = file_obj.get_all_files(os.path.join(root_path, folder)) # 获取文件夹下的全部文件的原始数据
|
||
|
all_file = file_obj.clear_files(all_file) # 整理文件返回整理后的结果
|
||
|
print(all_file)
|
||
|
|
||
|
# 从数据库中获取数据
|
||
|
data = db_obj.get_data_by_id(folder)
|
||
|
|
||
|
# 解压
|
||
|
if all_file['handle_zip'] and unzip_obj.unzip(all_file['handle_zip'][0], data['unzip_pwd']):
|
||
|
file_obj.del_file(all_file['zip'])
|
||
|
|
||
|
# 打印未知文件
|
||
|
if all_file['unknown']:
|
||
|
logger.info("打印没有处理的文件扩展名:")
|
||
|
logger.info(', '.join(all_file['unknown']))
|
||
|
result = False
|
||
|
|
||
|
# 检查打印结果
|
||
|
if not (all_file['handle_zip'] and all_file['zip'] and all_file['unknown']):
|
||
|
logger.info('全部文件已解压')
|
||
|
return result
|
||
|
|
||
|
|
||
|
def start_collation_task():
|
||
|
result = True
|
||
|
for folder in file_obj.get_root_folder_list():
|
||
|
all_file = file_obj.get_all_files(os.path.join(root_path, folder)) # 获取文件夹下的全部文件的原始数据
|
||
|
all_file = file_obj.clear_files(all_file) # 整理文件返回整理后的结果
|
||
|
print(all_file)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
n = 5
|
||
|
while n > 0:
|
||
|
result = start_unzip_task()
|
||
|
if result:
|
||
|
break
|
||
|
n -= 1
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|