29 lines
1,003 B
Python
29 lines
1,003 B
Python
import json
|
|
import sys
|
|
|
|
|
|
def load_project_map(path: str | None) -> dict:
|
|
"""Load a project map JSON file. Returns an empty dict if path is None or missing."""
|
|
if not path:
|
|
return {}
|
|
try:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
except FileNotFoundError:
|
|
print(f"Warning: project map file not found: {path}", file=sys.stderr)
|
|
return {}
|
|
except json.JSONDecodeError as e:
|
|
print(f"Warning: could not parse project map file: {e}", file=sys.stderr)
|
|
return {}
|
|
|
|
|
|
def resolve_project_task(raw_project: str, project_map: dict) -> tuple[str, str]:
|
|
"""
|
|
Look up a raw project key in the project map.
|
|
Returns (Project, Task) if found, or (raw_project, "") as fallback.
|
|
"""
|
|
key = raw_project.strip().lower()
|
|
entry = project_map.get(key) or project_map.get(raw_project.strip())
|
|
if entry:
|
|
return entry.get("Project", raw_project), entry.get("Task", "")
|
|
return raw_project, ""
|