Prefer phone storage so data survives Termux uninstall.
()
| 250 | |
| 251 | LOGO_DARK_URL = "https://raw.githubusercontent.com/dedsec1121fk/dedsec1121fk.github.io/c0d1f698cc38dbd0535a94f8865ac9ba9fb45086/Assets/Images/Logos/Black%20Purple%20Butterfly%20Logo.jpeg" |
| 252 | LOGO_LIGHT_URL = "https://raw.githubusercontent.com/dedsec1121fk/dedsec1121fk.github.io/c0d1f698cc38dbd0535a94f8865ac9ba9fb45086/Assets/Images/Logos/White%20Purple%20Butterfly%20Logo.jpeg" |
| 253 | |
| 254 | HOME = os.path.expanduser("~") |
| 255 | LEGACY_BASE_DIR = os.path.join(HOME, "ButSystem") # old internal (non-persistent) location |
| 256 | |
| 257 | def _termux_shared_root() -> Optional[str]: |
| 258 | """Return Termux shared storage root if termux-setup-storage was run.""" |
| 259 | try: |
| 260 | shared = os.path.join(HOME, "storage", "shared") |
| 261 | if os.path.isdir(shared): |
| 262 | ap = os.path.abspath(shared) |
| 263 | # Usually resolves to /storage/emulated/0 |
| 264 | if ap.startswith("/storage/") or os.path.islink(shared): |
| 265 | return ap |
| 266 | except Exception: |
| 267 | pass |
| 268 | return None |
| 269 | |
| 270 | def _choose_homework_root() -> str: |
| 271 | """Prefer phone storage so data survives Termux uninstall.""" |
| 272 | candidates = [] |
| 273 | ext = os.environ.get("EXTERNAL_STORAGE") |
| 274 | if ext: |
| 275 | candidates.append(os.path.join(ext, "Homework")) |
| 276 | shared = _termux_shared_root() |
| 277 | if shared: |
| 278 | candidates.append(os.path.join(shared, "Homework")) |
| 279 | candidates.append("/storage/emulated/0/Homework") |
| 280 | |
| 281 | seen = set() |
| 282 | for root in candidates: |
| 283 | if not root or root in seen: |
| 284 | continue |
no test coverage detected