批量写入代码文件到本地仓库 Args: file_contents: [{"filename": "1.two-sum.py", "code": "..."}, ...] Returns: 成功写入的文件名列表
(self, file_contents: List[Dict[str, str]])
| 442 | # ==================== 批量提交方法 ==================== |
| 443 | |
| 444 | async def batch_write_files(self, file_contents: List[Dict[str, str]]) -> List[str]: |
| 445 | """ |
| 446 | 批量写入代码文件到本地仓库 |
| 447 | |
| 448 | Args: |
| 449 | file_contents: [{"filename": "1.two-sum.py", "code": "..."}, ...] |
| 450 | |
| 451 | Returns: |
| 452 | 成功写入的文件名列表 |
| 453 | """ |
| 454 | written_files = [] |
| 455 | for item in file_contents: |
| 456 | filename = item["filename"] |
| 457 | code = item["code"] |
| 458 | file_path = os.path.join(self.repo_path, filename) |
| 459 | |
| 460 | try: |
| 461 | os.makedirs(os.path.dirname(file_path), exist_ok=True) |
| 462 | with open(file_path, 'w', encoding='utf-8') as f: |
| 463 | f.write(code) |
| 464 | written_files.append(filename) |
| 465 | logger.info(f"| 📝 Written: {filename}") |
| 466 | except Exception as e: |
| 467 | logger.error(f"| ❌ Failed to write {filename}: {e}") |
| 468 | |
| 469 | return written_files |
| 470 | |
| 471 | async def batch_push(self, filenames: List[str], max_retries: int = 3, sync_codespace: bool = True) -> bool: |
| 472 | """ |