Save and reuse UUIDs between project generations.

This commit is contained in:
2024-10-11 16:57:31 +02:00
parent 329278c5f5
commit e3b3fd8f7c
2 changed files with 30 additions and 4 deletions

View File

@@ -483,8 +483,26 @@ def _generate_project(project_type: str) -> None:
}.get(project_type, (None, None))
if not source_folder:
_error(None, 'Invalid project type option.')
def _generate_uuid() -> str:
return str(uuid.uuid4())
uuid_cache_file = pathlib.Path(env['SHARED_CACHE_DIR'], 'uuids.json')
uuid_cache = {}
save_uuid_cache = False
if uuid_cache_file.exists():
try:
with uuid_cache_file.open('r') as f:
uuid_cache = json.load(f)
except Exception as e:
print(f'Error loading UUID cache: {e}')
def _generate_uuid(name: str = '') -> str:
nonlocal save_uuid_cache
if name and name in uuid_cache:
return uuid_cache[name]
new_uuid = str(uuid.uuid4())
if name:
uuid_cache[name] = new_uuid
save_uuid_cache = True
return new_uuid
root_path = pathlib.Path(env.Dir('#').abspath)
def _get_executables() -> list:
@@ -526,6 +544,14 @@ def _generate_project(project_type: str) -> None:
with target_file.open('w') as f:
f.write(templ.render())
if save_uuid_cache:
try:
with uuid_cache_file.open('w') as f:
json.dump(uuid_cache, f)
except Exception as e:
print(f'Error writing uuid cache: {e}')
Import('config')