Spaces:
Sleeping
Sleeping
| import os | |
| import zipfile | |
| import shutil | |
| def create_full_project(files_map, project_name="generated_project"): | |
| base_path = os.path.join("sandbox", project_name) | |
| # تنظيف المكان قبل البدء | |
| if os.path.exists(base_path): | |
| shutil.rmtree(base_path) | |
| os.makedirs(base_path, exist_ok=True) | |
| # إنشاء الملفات | |
| for file_path, content in files_map.items(): | |
| full_file_path = os.path.join(base_path, file_path) | |
| os.makedirs(os.path.dirname(full_file_path), exist_ok=True) | |
| with open(full_file_path, "w", encoding="utf-8") as f: | |
| f.write(content) | |
| # ضغط المشروع في ZIP | |
| zip_path = f"{project_name}.zip" | |
| with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf: | |
| for root, dirs, files in os.walk(base_path): | |
| for file in files: | |
| zipf.write(os.path.join(root, file), | |
| os.path.relpath(os.path.join(root, file), base_path)) | |
| return zip_path, base_path | |