1Egyb commited on
Commit
65c302d
·
verified ·
1 Parent(s): c2c6ffb

Create builder.py

Browse files
Files changed (1) hide show
  1. builder.py +29 -0
builder.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import zipfile
3
+ import shutil
4
+
5
+ def create_full_project(files_map, project_name="generated_project"):
6
+ base_path = os.path.join("sandbox", project_name)
7
+
8
+ # تنظيف المكان قبل البدء
9
+ if os.path.exists(base_path):
10
+ shutil.rmtree(base_path)
11
+ os.makedirs(base_path, exist_ok=True)
12
+
13
+ # إنشاء الملفات
14
+ for file_path, content in files_map.items():
15
+ full_file_path = os.path.join(base_path, file_path)
16
+ os.makedirs(os.path.dirname(full_file_path), exist_ok=True)
17
+ with open(full_file_path, "w", encoding="utf-8") as f:
18
+ f.write(content)
19
+
20
+ # ضغط المشروع في ZIP
21
+ zip_path = f"{project_name}.zip"
22
+ with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
23
+ for root, dirs, files in os.walk(base_path):
24
+ for file in files:
25
+ zipf.write(os.path.join(root, file),
26
+ os.path.relpath(os.path.join(root, file), base_path))
27
+
28
+ return zip_path, base_path
29
+