From feb46346e7c822bd7d05069db90cd30e73f53d08 Mon Sep 17 00:00:00 2001 From: MichaelBCG Date: Tue, 26 Mar 2024 21:07:02 +0100 Subject: [PATCH] Add update of ProjectPureName with .uproject's name --- set_ProjectPureName.py | 46 ++++++++++++++++++++++++++++++++++++++++++ setup.bat | 5 ++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 set_ProjectPureName.py diff --git a/set_ProjectPureName.py b/set_ProjectPureName.py new file mode 100644 index 0000000..0ff5b19 --- /dev/null +++ b/set_ProjectPureName.py @@ -0,0 +1,46 @@ +""" +Automates the update of the ProjectPureName in a config.bat file with the name of a found .uproject file. +""" + +import os +import re + +def find_uproject_file(): + """ + Find the .uproject file in the upper directory. + """ + current_directory = os.getcwd() + upper_directory = os.path.dirname(current_directory) + uproject_files = [f for f in os.listdir(upper_directory) if f.endswith('.uproject')] + + if len(uproject_files) == 1: + return os.path.splitext(uproject_files[0])[0] # Return the name without extension + else: + script_filename = os.path.basename(__file__) + print(f"[{script_filename}] Warning: Found multiple or no .uproject files in the upper directory.") + return None + +def update_config_bat(uproject_name, config_bat_file): + """ + Update the config.bat file with the ProjectPureName. + """ + if os.path.exists(config_bat_file): + with open(config_bat_file, 'r') as file: + content = file.read() + + updated_content = re.sub(r'set ProjectPureName=', f'set ProjectPureName={uproject_name}', content) + + with open(config_bat_file, 'w') as file: + file.write(updated_content) + script_filename = os.path.basename(__file__) + print(f"[{script_filename}] ProjectPureName updated successfully to '{uproject_name}' in config.bat.") + else: + script_filename = os.path.basename(__file__) + print(f"[{script_filename}] Warning: config.bat file not found.") + +if __name__ == "__main__": + current_directory = os.getcwd() + uproject_name = find_uproject_file() + if uproject_name: + config_bat_file = os.path.join(current_directory, "..", "devops_data", "config.bat") + update_config_bat(uproject_name, config_bat_file) diff --git a/setup.bat b/setup.bat index f5d8470..45290c7 100644 --- a/setup.bat +++ b/setup.bat @@ -16,6 +16,9 @@ copy "%~dp0setup\.clang-format.template" "%~dp0..\devops_data\.clang-format" copy "%~dp0setup\.gitignore.template" "%~dp0..\devops_data\.gitignore" copy "%~dp0setup\LICENSE.template" "%~dp0..\devops_data\LICENSE.md" copy "%~dp0setup\Doxyfile.template" "%~dp0..\devops_data\Doxyfile" - echo All files were copied to "%~dp0..\devops_data" + +REM Update ProjectPureName in a config.bat with the name of a found .uproject file +python set_ProjectPureName.py + pause