|
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | 4 |
|
| 5 | + |
| 6 | +class FileSystemManager: |
| 7 | + @staticmethod |
| 8 | + def ensure_dir(dir_path): |
| 9 | + """Ensure the directory exists, create if it doesn't""" |
| 10 | + path = Path(dir_path) |
| 11 | + if not path.exists(): |
| 12 | + path.mkdir(parents=True, exist_ok=True) |
| 13 | + return path |
| 14 | + |
| 15 | + @staticmethod |
| 16 | + def ensure_file(file_path, default_content=""): |
| 17 | + """Ensure the file exists, create if it doesn't""" |
| 18 | + path = Path(file_path) |
| 19 | + if not path.parent.exists(): |
| 20 | + FileSystemManager.ensure_dir(path.parent) |
| 21 | + if not path.exists(): |
| 22 | + with open(path, "w") as f: |
| 23 | + f.write(default_content) |
| 24 | + return path |
| 25 | + |
| 26 | + |
5 | 27 | # Get the directory where the script is located |
6 | 28 | PACKAGE_DIR = Path(__file__).resolve().parent |
7 | 29 |
|
8 | 30 | # Get the root directory of the MindSearch project |
9 | 31 | PROJECT_ROOT = PACKAGE_DIR.parent.parent |
10 | 32 |
|
11 | 33 | # Get the temp directory path, which is actually the working directory for executing the docker compose up command |
12 | | -TEMP_DIR = PACKAGE_DIR / "temp" |
| 34 | +TEMP_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "temp") |
13 | 35 |
|
14 | 36 | # Configuration file name list |
15 | 37 | TEMPLATE_FILES = ["docker-compose.yaml"] |
|
28 | 50 | REACT_DOCKERFILE = "react.dockerfile" |
29 | 51 |
|
30 | 52 | # i18n translations directory |
31 | | -TRANSLATIONS_DIR = PACKAGE_DIR / "translations" |
| 53 | +TRANSLATIONS_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "translations") |
32 | 54 |
|
33 | 55 | # Get the path of the .env file |
34 | | -ENV_FILE_PATH = TEMP_DIR / ".env" |
| 56 | +ENV_FILE_PATH = FileSystemManager.ensure_file(TEMP_DIR / ".env") |
0 commit comments