-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
58 lines (46 loc) · 1.71 KB
/
utils.py
File metadata and controls
58 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import shutil
import yaml
README_CONFIG = """
---
title: {class_name} ({class_number})
description: AI Assistant for {class_name} class ({class_number})
emoji: 🎓
colorFrom: red
colorTo: green
sdk: docker
app_port: 7860
---
"""
def update_repo(class_dir, class_info):
ai_tutor_dir = os.path.join(class_dir, "apps", "ai_tutor")
config_path = os.path.join(ai_tutor_dir, "config", "project_config.yml")
storage_path = os.path.join(ai_tutor_dir, "storage")
urls_file = os.path.join(storage_path, "urls.txt")
with open(urls_file, "w+") as f:
f.write(class_info["class_url"])
with open(config_path, "r") as f:
config_file = yaml.safe_load(f)
config_file["metadata"]["class_name"] = class_info["class_name"]
config_file["metadata"]["class_number"] = class_info["class_number"]
config_file["metadata"]["instructor_name"] = class_info["instructor_name"]
with open(config_path, "w+") as f:
yaml.dump(config_file, f, indent=4)
shutil.copy(os.path.join(os.path.dirname(__file__),
'assets/Dockerfile'), os.path.join(class_dir, 'Dockerfile'))
with open(os.path.join(class_dir, "README.md"), "w") as f:
f.write(README_CONFIG.format(
class_name=class_info["class_name"], class_number=class_info["class_number"]))
with open(os.path.join(class_dir, "requirements.txt"), "w") as f:
f.write("edubotics-core")
return True
if __name__ == "__main__":
update_repo(
"instances/thomas gardos_DS542",
{
"class_name": "Something else",
"class_number": "DS542",
"instructor_name": "Thomas Gardos",
"class_url": "https://x.com",
},
)