打开文件
(self, path, mode="rb")
| 252 | raise |
| 253 | |
| 254 | def open(self, path, mode="rb"): |
| 255 | """打开文件""" |
| 256 | try: |
| 257 | with self._temp_container() as container_id: |
| 258 | cmd = f"docker export {container_id} | tar -xOf - {path.lstrip('/')}" |
| 259 | result = subprocess.run(cmd, shell=True, capture_output=True) |
| 260 | |
| 261 | if result.returncode != 0: |
| 262 | raise Exception("无法读取文件") |
| 263 | |
| 264 | class FileWrapper: |
| 265 | def __init__(self, data): |
| 266 | self.data = data |
| 267 | self.position = 0 |
| 268 | |
| 269 | def read(self): |
| 270 | return self.data |
| 271 | |
| 272 | def close(self): |
| 273 | pass |
| 274 | |
| 275 | return FileWrapper(result.stdout) |
| 276 | |
| 277 | except Exception as e: |
| 278 | raise |
| 279 | |
| 280 | def cleanup(self): |
| 281 | """清理所有活动的临时容器""" |
no test coverage detected