基于7z实现的压缩,默认使用16线程极速压缩 :param path: 被压缩的资源路径 :param zip_file: 压缩完成生成的文件 :return:
(self, path, zip_file)
| 44 | self.ZIP_TOOL_NAME = "7z_ubuntu" |
| 45 | |
| 46 | def compress(self, path, zip_file): |
| 47 | """ |
| 48 | 基于7z实现的压缩,默认使用16线程极速压缩 |
| 49 | :param path: 被压缩的资源路径 |
| 50 | :param zip_file: 压缩完成生成的文件 |
| 51 | :return: |
| 52 | """ |
| 53 | logger.info("zip模块执行压缩操作...") |
| 54 | args = [ |
| 55 | os.path.join(os.environ[ZIP_HOME], self.ZIP_TOOL_NAME), |
| 56 | "a", |
| 57 | "-t7z", |
| 58 | zip_file, |
| 59 | "%s/*" % path, |
| 60 | "-mmt16", |
| 61 | "-mx1", |
| 62 | ] |
| 63 | if os.path.exists(zip_file): |
| 64 | PathMgr().rmpath(zip_file) |
| 65 | try: |
| 66 | args = PathMgr().format_cmd_arg_list(args) |
| 67 | process = SubProcController( |
| 68 | args, |
| 69 | print_enable=False, |
| 70 | shell=False, |
| 71 | stdout_filepath=None, |
| 72 | stderr_filepath=None, |
| 73 | stdout_line_callback=self.compress_subprocc_log, |
| 74 | stderr_line_callback=self.compress_subprocc_log, |
| 75 | env=EnvSet().get_origin_env(), |
| 76 | ) |
| 77 | process.wait(ZIP_TIME_LIMIT) |
| 78 | except FileNotFoundError: |
| 79 | self.zipfile_compress(path, zip_file) |
| 80 | if not os.path.exists(zip_file): |
| 81 | err_msg = "compress error! zip file is empty, please check! 如果是ubuntu环境,7z_ubuntu可能存在兼容问题," \ |
| 82 | "请自行安装:sudo apt-get install p7zip-full" |
| 83 | logger.error(err_msg) |
| 84 | raise ZIPError(err_msg) |
| 85 | return True |
| 86 | |
| 87 | def decompress_by_7z(self, zip_file, path, print_enable=False): |
| 88 | """ |
no test coverage detected