Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
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) 2025 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 if ".in" in file:
43 dst_file = os.path.join(target_root, file.replace(".in", ""))
44
45 with open(src_file, "r") as f:
46 content = f.read().replace("@PROJECT_NAME@", project_name)
47
48 with open(dst_file, "w") as f:
49 f.write(content)
50 else:
51 shutil.copyfile(src_file, dst_file)
52
53 if dst_file.endswith(".sh") and os.name == 'posix':
54 import stat
55 st = os.stat(dst_file)
56 os.chmod(dst_file, st.st_mode | stat.S_IEXEC)
57## @endcond
58
60 """
61 @brief Create a new Rendering Engine test/demo project.
62
63 Generates the folder structure, copies template files, and appends
64 'add_subdirectory()' to TestApplications/CMakeLists.txt.
65
66 @param name Name of the project to create.
67 """
68 project_dir = os.path.join(DEST_ROOT, name)
69 if os.path.exists(project_dir):
70 print(f"Error: Project '{name}' already exists.")
71 return
72
73 os.makedirs(project_dir)
74 copy_template(TEMPLATE_ROOT, project_dir, name)
75 FILE_PATH = os.path.join(DEST_ROOT, "CMakeLists.txt")
76 CMAKE_ADD_PROJECT = "\n" + "add_subdirectory(" + name + ")"
77 with open(FILE_PATH, "a") as cmake_file:
78 cmake_file.write(CMAKE_ADD_PROJECT)
79 print(f"Created new project at {project_dir}")
80
81if __name__ == "__main__":
82 if len(sys.argv) < 2:
83 print("Usage: create_project.py <ProjectName>")
84 sys.exit(1)
85 create_project(sys.argv[1])