-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
77 lines (60 loc) · 2.84 KB
/
Copy pathconfig.py
File metadata and controls
77 lines (60 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""config.py — Single source of truth for mail-triage Python configuration.
Import this at the top of any lib/ module that needs paths:
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
Or from a module already on the Python path:
import config
Environment variable overrides:
MAIL_TRIAGE_DIR — override the repo root (default: directory of this file)
MAIL_TRIAGE_PYTHON — override the python binary (default: sys.executable)
QUEUE_PATH — override the queue.json path directly
"""
import json
import os
import sys
# ---------------------------------------------------------------------------
# Repo root
# ---------------------------------------------------------------------------
# Allow an explicit override (useful when running from a different cwd).
ROOT = os.environ.get(
"MAIL_TRIAGE_DIR",
os.path.dirname(os.path.abspath(__file__)),
)
# ---------------------------------------------------------------------------
# Derived directories (all relative to ROOT)
# ---------------------------------------------------------------------------
LIB_DIR = os.path.join(ROOT, "lib")
DRAFTS_DIR = os.path.join(ROOT, "drafts")
LOGS_DIR = os.path.join(ROOT, "logs")
KNOWLEDGE_DIR = os.path.join(ROOT, "knowledge")
# ---------------------------------------------------------------------------
# Key file paths
# ---------------------------------------------------------------------------
ACCOUNTS_FILE = os.path.join(ROOT, "accounts.json")
CATEGORIES_PATH = os.path.join(ROOT, "categories.json")
QUEUE_PATH = os.environ.get("QUEUE_PATH", os.path.join(DRAFTS_DIR, "queue.json"))
MISSED_PATH = os.path.join(DRAFTS_DIR, "missed_today.json")
PROFILE_PATH = os.path.join(KNOWLEDGE_DIR, os.environ.get("PROFILE_FILE", "profile.md"))
# ---------------------------------------------------------------------------
# Python binary
# ---------------------------------------------------------------------------
# sys.executable is correct for venv-aware callers.
# Allow an override for the rare case where a subprocess must use a specific binary.
PYTHON_BIN = os.environ.get("MAIL_TRIAGE_PYTHON", sys.executable)
# ---------------------------------------------------------------------------
# Accounts helper
# ---------------------------------------------------------------------------
def load_accounts() -> list[dict]:
"""Return the list of account dicts from accounts.json."""
with open(ACCOUNTS_FILE, encoding="utf-8") as fh:
data = json.load(fh)
if isinstance(data, list):
return data
return data.get("accounts", [])
def primary_account() -> dict:
"""Return the first account (primary/digest sender)."""
accounts = load_accounts()
if not accounts:
raise RuntimeError("accounts.json is empty")
return accounts[0]