-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoduleCreator.py
More file actions
72 lines (58 loc) · 1.96 KB
/
moduleCreator.py
File metadata and controls
72 lines (58 loc) · 1.96 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
from datetime import date
def create_module_structure(base_category, module_name):
today = date.today().isoformat()
# Format names
root_dir = os.path.join(base_category, module_name)
module_dir = os.path.join(root_dir, module_name)
examples_dir = os.path.join(module_dir, "Examples")
# Create directories
os.makedirs(examples_dir, exist_ok=True)
# File paths
module_file = os.path.join(module_dir, f"{module_name}.py")
example_file = os.path.join(examples_dir, f"{module_name}_Example.py")
# Template contents
module_content = f"""# FILE: {module_name}.py
# AUTHOR: Soldered
# BRIEF:
# LAST UPDATED: {today}
"""
example_content = f"""# FILE: {module_name}-example.py
# AUTHOR: Soldered
# BRIEF:
# WORKS WITH: COMPONENT NAME: www.solde.red/SKU
# LAST UPDATED: {today}
"""
# Write files
with open(module_file, "w") as f:
f.write(module_content)
with open(example_file, "w") as f:
f.write(example_content)
print(
f"\nCreated module structure for '{module_name}' in category '{base_category}':"
)
print(f" - {module_file}")
print(f" - {example_file}")
if __name__ == "__main__":
categories = {
"1": "Sensors",
"2": "Actuators",
"3": "Communication",
"4": "Displays",
}
try:
print("Select a category for the module:")
for key, name in categories.items():
print(f" {key}. {name}")
choice = input("Enter the number corresponding to the category: ").strip()
base_category = categories.get(choice)
if not base_category:
print("Invalid category selection.")
else:
module_name = input("Enter the module name: ").strip()
if not module_name:
print("Module name cannot be empty.")
else:
create_module_structure(base_category, module_name)
except Exception as e:
print(f"Error: {e}")