ArchiveFile.py 904 B

123456789101112131415161718192021222324
  1. import os.path
  2. import shutil
  3. from etl.common.PathsAndTable import PathsAndTable
  4. from service.trans_conf_service import update_archive_success
  5. from utils.log.trans_log import trans_print
  6. class ArchiveFile(object):
  7. def __init__(self, pathsAndTable: PathsAndTable, exec_id):
  8. self.pathsAndTable = pathsAndTable
  9. self.exec_id = exec_id
  10. def run(self):
  11. """
  12. 归档文件
  13. """
  14. if os.path.exists(self.pathsAndTable.get_tmp_formal_path()):
  15. shutil.make_archive(self.pathsAndTable.get_archive_path(), 'zip', self.pathsAndTable.get_tmp_formal_path())
  16. update_archive_success(self.exec_id, f"{self.pathsAndTable.get_archive_path()}.zip")
  17. trans_print(f"文件夹已归档为 {self.pathsAndTable.get_archive_path()}.zip")
  18. else:
  19. trans_print(f"文件夹 {self.pathsAndTable.get_tmp_formal_path()} 不存在")