Rendering Engine 0.2.17
Modular Graphics Rendering Engine | v0.2.17
Loading...
Searching...
No Matches
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 Rendering Engine user application by copying the
11# template folder structure and exposing template variables.
12#
13# By default, the project is created inside UserApplications/ and registered
14# in UserApplications/CMakeLists.txt. An optional destination path can be
15# provided to create and register an external UserApplication.
16#
17# Usage:
18# python3 create_project.py <ProjectName> [DestinationPath]
19#
20# Platform notes:
21# - On Unix systems, .sh files copied from the template are given +x permission.
22# - On Windows, permissions remain unchanged.
23#
24# @author
25# Alexander Obzherin
26#
27
28import os
29import sys
30import shutil
31
32from register_project import register_project
33
34TEMPLATE_ROOT = os.path.join("RenderingEngine", "Scripts", "Templates")
35DEST_ROOT = os.path.join("UserApplications")
36
37## @cond INTERNAL
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)
43
44 for file in files:
45 src_file = os.path.join(root, file)
46 dst_file = os.path.join(target_root, file)
47 # Do not process .in files inside Scripts/Templates
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", ""))
50
51 with open(src_file, "r") as f:
52 content = f.read().replace("@PROJECT_NAME@", project_name)
53
54 with open(dst_file, "w") as f:
55 f.write(content)
56 else:
57 shutil.copyfile(src_file, dst_file)
58
59 if dst_file.endswith(".sh") and os.name == 'posix':
60 import stat
61 st = os.stat(dst_file)
62 os.chmod(dst_file, st.st_mode | stat.S_IEXEC)
63## @endcond
64
65def create_project(name, destination=DEST_ROOT):
66 """
67 @brief Create a new Rendering Engine user application.
68
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.
72
73 @param name Name of the project to create.
74 @param destination Directory in which the project will be created.
75 """
76 destination = os.path.abspath(destination)
77 default_destination = os.path.abspath(DEST_ROOT)
78 project_dir = os.path.join(destination, name)
79
80 if os.path.exists(project_dir):
81 print(f"Error: Project '{name}' already exists at '{project_dir}'.")
82 return
83
84 os.makedirs(project_dir)
85 copy_template(TEMPLATE_ROOT, project_dir, name)
86
87 if destination == default_destination:
88 file_path = os.path.join(default_destination, "CMakeLists.txt")
89 cmake_add_project = "\n" + "add_subdirectory(" + name + ")"
90
91 with open(file_path, "a") as cmake_file:
92 cmake_file.write(cmake_add_project)
93 else:
94 if not register_project(project_dir):
95 print(
96 f"Warning: Project '{name}' was created successfully, "
97 "but could not be registered."
98 )
99 return
100
101 print(f"Created new project at {project_dir}")
102
103if __name__ == "__main__":
104 if len(sys.argv) < 2 or len(sys.argv) > 3:
105 print("Usage: create_project.py <ProjectName> [DestinationPath]")
106 sys.exit(1)
107 destination = sys.argv[2] if len(sys.argv) == 3 else DEST_ROOT
108 create_project(sys.argv[1], destination)