29TEMPLATE_ROOT = os.path.join(
"RenderingEngine",
"Scripts",
"Templates")
30DEST_ROOT = os.path.join(
"UserApplications")
33def copy_template(src_dir, dst_dir, project_name):
34 for root, dirs, files
in os.walk(src_dir):
35 rel_path = os.path.relpath(root, src_dir)
36 target_root = os.path.join(dst_dir, rel_path)
37 os.makedirs(target_root, exist_ok=
True)
40 src_file = os.path.join(root, file)
41 dst_file = os.path.join(target_root, file)
43 if file.endswith(
".in")
and not rel_path.startswith(os.path.join(
"Scripts",
"Templates")):
44 dst_file = os.path.join(target_root, file.replace(
".in",
""))
46 with open(src_file,
"r")
as f:
47 content = f.read().replace(
"@PROJECT_NAME@", project_name)
49 with open(dst_file,
"w")
as f:
52 shutil.copyfile(src_file, dst_file)
54 if dst_file.endswith(
".sh")
and os.name ==
'posix':
56 st = os.stat(dst_file)
57 os.chmod(dst_file, st.st_mode | stat.S_IEXEC)
62 @brief Create a new Rendering Engine test/demo project.
64 Generates the folder structure, copies template files,
and appends
65 'add_subdirectory()' to TestApplications/CMakeLists.txt.
67 @param name Name of the project to create.
69 project_dir = os.path.join(DEST_ROOT, name)
70 if os.path.exists(project_dir):
71 print(f
"Error: Project '{name}' already exists.")
74 os.makedirs(project_dir)
75 copy_template(TEMPLATE_ROOT, project_dir, name)
76 FILE_PATH = os.path.join(DEST_ROOT,
"CMakeLists.txt")
77 CMAKE_ADD_PROJECT =
"\n" +
"add_subdirectory(" + name +
")"
78 with open(FILE_PATH,
"a")
as cmake_file:
79 cmake_file.write(CMAKE_ADD_PROJECT)
80 print(f
"Created new project at {project_dir}")
82if __name__ ==
"__main__":
84 print(
"Usage: create_project.py <ProjectName>")