Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
create_project.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# This file is part of the Rendering Engine project.
3# Author: Alexander Obzherin <alexanderobzherin@gmail.com>
4# Copyright (c) 2026 Alexander Obzherin
5# Distributed under the terms of the zlib License. See LICENSE.md for details.
6##
7# @file create_project.py
8# @brief Rendering Engine demo/test application generator.
9#
10# This script creates a new project inside TestApplications/ by copying the
11# template folder structure, exposing template variables, and registering
12# the project in TestApplications/CMakeLists.txt.
13#
14# Usage:
15# python3 create_project.py <ProjectName>
16#
17# Platform notes:
18# - On Unix systems, .sh files copied from the template are given +x permission.
19# - On Windows, permissions remain unchanged.
20#
21# @author
22# Alexander Obzherin
23#
24
25import os
26import sys
27import shutil
28
29TEMPLATE_ROOT = os.path.join("RenderingEngine", "Scripts", "Templates")
30DEST_ROOT = os.path.join("UserApplications")
31
32## @cond INTERNAL
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)
38
39 for file in files:
40 src_file = os.path.join(root, file)
41 dst_file = os.path.join(target_root, file)
42 # Do not process .in files inside Scripts/Templates
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", ""))
45
46 with open(src_file, "r") as f:
47 content = f.read().replace("@PROJECT_NAME@", project_name)
48
49 with open(dst_file, "w") as f:
50 f.write(content)
51 else:
52 shutil.copyfile(src_file, dst_file)
53
54 if dst_file.endswith(".sh") and os.name == 'posix':
55 import stat
56 st = os.stat(dst_file)
57 os.chmod(dst_file, st.st_mode | stat.S_IEXEC)
58## @endcond
59
61 """
62 @brief Create a new Rendering Engine test/demo project.
63
64 Generates the folder structure, copies template files, and appends
65 'add_subdirectory()' to TestApplications/CMakeLists.txt.
66
67 @param name Name of the project to create.
68 """
69 project_dir = os.path.join(DEST_ROOT, name)
70 if os.path.exists(project_dir):
71 print(f"Error: Project '{name}' already exists.")
72 return
73
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}")
81
82if __name__ == "__main__":
83 if len(sys.argv) < 2:
84 print("Usage: create_project.py <ProjectName>")
85 sys.exit(1)
86 create_project(sys.argv[1])
def create_project(name)