32from register_project
import register_project
34TEMPLATE_ROOT = os.path.join(
"RenderingEngine",
"Scripts",
"Templates")
35DEST_ROOT = os.path.join(
"UserApplications")
38def copy_template(src_dir, dst_dir, project_name):
39 for root, dirs, files
in os.walk(src_dir):
40 rel_path = os.path.relpath(root, src_dir)
41 target_root = os.path.join(dst_dir, rel_path)
42 os.makedirs(target_root, exist_ok=
True)
45 src_file = os.path.join(root, file)
46 dst_file = os.path.join(target_root, file)
48 if file.endswith(
".in")
and not rel_path.startswith(os.path.join(
"Scripts",
"Templates")):
49 dst_file = os.path.join(target_root, file.replace(
".in",
""))
51 with open(src_file,
"r")
as f:
52 content = f.read().replace(
"@PROJECT_NAME@", project_name)
54 with open(dst_file,
"w")
as f:
57 shutil.copyfile(src_file, dst_file)
59 if dst_file.endswith(
".sh")
and os.name ==
'posix':
61 st = os.stat(dst_file)
62 os.chmod(dst_file, st.st_mode | stat.S_IEXEC)
67 @brief Create a new Rendering Engine user application.
69 Generates the project folder structure and copies template files.
70 Projects created in the default UserApplications directory are
71 automatically registered in UserApplications/CMakeLists.txt.
73 @param name Name of the project to create.
74 @param destination Directory in which the project will be created.
76 destination = os.path.abspath(destination)
77 default_destination = os.path.abspath(DEST_ROOT)
78 project_dir = os.path.join(destination, name)
80 if os.path.exists(project_dir):
81 print(f
"Error: Project '{name}' already exists at '{project_dir}'.")
84 os.makedirs(project_dir)
85 copy_template(TEMPLATE_ROOT, project_dir, name)
87 if destination == default_destination:
88 file_path = os.path.join(default_destination,
"CMakeLists.txt")
89 cmake_add_project =
"\n" +
"add_subdirectory(" + name +
")"
91 with open(file_path,
"a")
as cmake_file:
92 cmake_file.write(cmake_add_project)
96 f
"Warning: Project '{name}' was created successfully, "
97 "but could not be registered."
101 print(f
"Created new project at {project_dir}")
103if __name__ ==
"__main__":
104 if len(sys.argv) < 2
or len(sys.argv) > 3:
105 print(
"Usage: create_project.py <ProjectName> [DestinationPath]")
107 destination = sys.argv[2]
if len(sys.argv) == 3
else DEST_ROOT