File size: 867 Bytes
3085164
 
 
 
 
 
 
 
e15281a
3085164
 
 
 
 
 
 
 
 
 
e15281a
3085164
 
 
 
e15281a
3085164
 
 
 
e15281a
3085164
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
import os
from functools import lru_cache
from pathlib import Path


@lru_cache(maxsize=1)
def project_root() -> Path:
    """
    返回代码仓库根目录,使调用者能够构建不依赖当前工作目录的绝对路径。
    """
    env_root = os.getenv("CAMOUFOX_PROJECT_ROOT")
    if env_root:
        return Path(env_root).expanduser().resolve()

    current = Path(__file__).resolve()
    for parent in current.parents:
        if (parent / "cookies").exists():
            return parent

    # 如果标记目录缺失,则回退到原始行为
    return current.parents[min(2, len(current.parents) - 1)]


def logs_dir() -> Path:
    """存储日志文件和截图的根级目录。"""
    return project_root() / "logs"


def cookies_dir() -> Path:
    """存储持久化Cookie JSON文件的根级目录。"""
    return project_root() / "cookies"