文件服务器下载 :param path_dict: { '文件服务器上的文件名': '拉取下来后存放的位置' } :return:
(path_dict)
| 25 | class Downloader(object): |
| 26 | @staticmethod |
| 27 | def file_server_download(path_dict): |
| 28 | ''' |
| 29 | 文件服务器下载 |
| 30 | :param path_dict: { '文件服务器上的文件名': '拉取下来后存放的位置' } |
| 31 | :return: |
| 32 | ''' |
| 33 | for file_name in path_dict.keys(): |
| 34 | temp_zip_file = tempfile.mktemp(prefix='zip_', dir=settings.DATA_DIR, suffix='.zip') |
| 35 | file_server = RetryFileServer(retry_times=2).get_server() |
| 36 | file_server.download_file(f"sourcedir/{file_name}", temp_zip_file) |
| 37 | if not os.path.exists(temp_zip_file): |
| 38 | raise TransferModuleError('文件服务器中拉取文件失败...') |
| 39 | Zip().decompress(temp_zip_file, os.path.join(settings.DATA_DIR, path_dict[file_name])) |
| 40 | logger.info('decompress done: %s' % os.path.join(settings.DATA_DIR, path_dict[file_name])) |
| 41 | PathMgr().rmpath(temp_zip_file) |
| 42 | return True |
| 43 | |
| 44 | |
| 45 | if __name__ == "__main__": |
no test coverage detected