Skip to content

Commit efcea6a

Browse files
committed
adds default category paths for #20
1 parent 2eb067a commit efcea6a

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/redfetch/config.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ def normalize_and_create_path(path):
7575
return normalized_path
7676

7777

78+
def normalize_category_paths(data):
79+
"""Normalize and validate absolute paths in CATEGORY_PATHS."""
80+
if not isinstance(data, dict):
81+
return data
82+
valid_names = set(CATEGORY_MAP.values())
83+
for key, value in list(data.items()):
84+
if key not in valid_names:
85+
raise ValidationError(
86+
f"Unknown category '{key}' in CATEGORY_PATHS. "
87+
f"Valid categories: {', '.join(sorted(valid_names))}"
88+
)
89+
if isinstance(value, str) and value:
90+
normalized = os.path.normpath(value)
91+
if os.path.isabs(normalized):
92+
validate_no_eqgame(normalized)
93+
data[key] = normalized
94+
return data
95+
96+
7897
# Custom Dynaconf validator specifically for SPECIAL_RESOURCE paths
7998
def normalize_paths_in_dict(data, parent_key=None):
8099
if isinstance(data, dict):
@@ -153,7 +172,8 @@ def initialize_config():
153172
Validator("DOWNLOAD_FOLDER", cast=normalize_and_create_path),
154173
# Separate validator for EQPATH to avoid triggering eqgame.exe check
155174
Validator("EQPATH", default=None, cast=lambda x: os.path.normpath(x) if x else None),
156-
Validator("SPECIAL_RESOURCES", cast=normalize_paths_in_dict)
175+
Validator("SPECIAL_RESOURCES", cast=normalize_paths_in_dict),
176+
Validator("CATEGORY_PATHS", default={}, cast=normalize_category_paths)
157177
]
158178
)
159179

src/redfetch/settings.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
DOWNLOAD_FOLDER = "@format {env[REDFETCH_DATA_DIR]}/Downloads"
1010
EQPATH = ""
1111

12+
[DEFAULT.CATEGORY_PATHS]
13+
1214
# ========================================
1315
# XenForo OAuth2
1416
# ========================================

src/redfetch/sync_discovery.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ def resolve_root_path(resource_id: str, category_id: int | None, settings_env: s
5858
if special_destination:
5959
return special_destination
6060

61+
category_name = config.CATEGORY_MAP.get(category_id or -1, "")
62+
63+
if category_name:
64+
category_paths = getattr(settings_for_env, "CATEGORY_PATHS", None) or {}
65+
override = category_paths.get(category_name)
66+
if override:
67+
if os.path.isabs(override):
68+
return os.path.normpath(override)
69+
return os.path.normpath(os.path.join(download_folder, override))
70+
6171
base_path = download_folder
6272
vvmq_id = utils.get_current_vvmq_id(settings_env)
6373
if vvmq_id:
@@ -66,9 +76,8 @@ def resolve_root_path(resource_id: str, category_id: int | None, settings_env: s
6676
if vvmq_destination:
6777
base_path = vvmq_destination
6878

69-
category_subfolder = config.CATEGORY_MAP.get(category_id or -1, "")
70-
if category_subfolder:
71-
return os.path.normpath(os.path.join(base_path, category_subfolder))
79+
if category_name:
80+
return os.path.normpath(os.path.join(base_path, category_name))
7281
return base_path
7382

7483

0 commit comments

Comments
 (0)