Covered Theme module with tests

- Extracted `ColorReplacementGenerator`;
- Extracted `ColorConverterImpl`;
- Added documentation to some classes;
- `hex_to_rgba` now supports shorthand hex colors (#fff).
This commit is contained in:
Vladyslav Hroshev
2025-04-11 22:53:30 +03:00
parent 29485ddf1e
commit abfe1f5962
25 changed files with 877 additions and 103 deletions

View File

@@ -1,8 +1,6 @@
import os
import shutil
from scripts.utils import copy_files
class ThemeTempManager:
"""
@@ -10,18 +8,21 @@ class ThemeTempManager:
"""
def __init__(self, temp_folder: str):
self.temp_folder = temp_folder
os.makedirs(self.temp_folder, exist_ok=True)
def copy_to_temp(self, content: str):
"""
Copy a file or directory to the temporary folder.
If the content is a file, it will be copied directly.
If the content is a directory, all its contents will be copied to the temp folder.
"""
if os.path.isfile(content):
shutil.copy(content, self.temp_folder)
final_path = os.path.join(self.temp_folder, os.path.basename(content))
shutil.copy(content, final_path)
else:
shutil.copytree(content, self.temp_folder)
shutil.copytree(content, self.temp_folder, dirs_exist_ok=True)
return self
def prepare_files(self, sources_location: str):
"""Prepare files in temp folder"""
copy_files(sources_location, self.temp_folder)
def cleanup(self):
"""Remove temporary folders"""
shutil.rmtree(f"{self.temp_folder}/.css/", ignore_errors=True)