MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / _choose_homework_root

Function _choose_homework_root

Scripts/ButSystem.py:252–281  ·  view source on GitHub ↗

Prefer phone storage so data survives Termux uninstall.

()

Source from the content-addressed store, hash-verified

250
251LOGO_DARK_URL = "https://raw.githubusercontent.com/dedsec1121fk/dedsec1121fk.github.io/c0d1f698cc38dbd0535a94f8865ac9ba9fb45086/Assets/Images/Logos/Black%20Purple%20Butterfly%20Logo.jpeg"
252LOGO_LIGHT_URL = "https://raw.githubusercontent.com/dedsec1121fk/dedsec1121fk.github.io/c0d1f698cc38dbd0535a94f8865ac9ba9fb45086/Assets/Images/Logos/White%20Purple%20Butterfly%20Logo.jpeg"
253
254HOME = os.path.expanduser("~")
255LEGACY_BASE_DIR = os.path.join(HOME, "ButSystem") # old internal (non-persistent) location
256
257def _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
270def _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

Callers 1

ButSystem.pyFile · 0.70

Calls 2

_termux_shared_rootFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected