mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Bump platformdirs from 4.2.1 to 4.2.2 (#2324)
* Bump platformdirs from 4.2.1 to 4.2.2 Bumps [platformdirs](https://github.com/platformdirs/platformdirs) from 4.2.1 to 4.2.2. - [Release notes](https://github.com/platformdirs/platformdirs/releases) - [Changelog](https://github.com/platformdirs/platformdirs/blob/main/CHANGES.rst) - [Commits](https://github.com/platformdirs/platformdirs/compare/4.2.1...4.2.2) --- updated-dependencies: - dependency-name: platformdirs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Update platformdirs==4.2.2 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
This commit is contained in:
parent
68bf1c70f7
commit
dc9e778111
3 changed files with 39 additions and 12 deletions
|
@ -6,7 +6,7 @@ import os
|
|||
import re
|
||||
import sys
|
||||
from functools import lru_cache
|
||||
from typing import cast
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
from .api import PlatformDirsABC
|
||||
|
||||
|
@ -117,16 +117,33 @@ class Android(PlatformDirsABC):
|
|||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_folder() -> str | None:
|
||||
def _android_folder() -> str | None: # noqa: C901, PLR0912
|
||||
""":return: base folder for the Android OS or None if it cannot be found"""
|
||||
try:
|
||||
# First try to get a path to android app via pyjnius
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
result: str | None = None
|
||||
# type checker isn't happy with our "import android", just don't do this when type checking see
|
||||
# https://stackoverflow.com/a/61394121
|
||||
if not TYPE_CHECKING:
|
||||
try:
|
||||
# First try to get a path to android app using python4android (if available)...
|
||||
from android import mActivity # noqa: PLC0415
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
result: str | None = context.getFilesDir().getParentFile().getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
# if fails find an android folder looking a path on the sys.path
|
||||
context = cast("android.content.Context", mActivity.getApplicationContext()) # noqa: F821
|
||||
result = context.getFilesDir().getParentFile().getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
result = None
|
||||
if result is None:
|
||||
try:
|
||||
# ...and fall back to using plain pyjnius, if python4android isn't available or doesn't deliver any useful
|
||||
# result...
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
result = context.getFilesDir().getParentFile().getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
result = None
|
||||
if result is None:
|
||||
# and if that fails, too, find an android folder looking at path on the sys.path
|
||||
# warning: only works for apps installed under /data, not adopted storage etc.
|
||||
pattern = re.compile(r"/data/(data|user/\d+)/(.+)/files")
|
||||
for path in sys.path:
|
||||
if pattern.match(path):
|
||||
|
@ -134,6 +151,16 @@ def _android_folder() -> str | None:
|
|||
break
|
||||
else:
|
||||
result = None
|
||||
if result is None:
|
||||
# one last try: find an android folder looking at path on the sys.path taking adopted storage paths into
|
||||
# account
|
||||
pattern = re.compile(r"/mnt/expand/[a-fA-F0-9-]{36}/(data|user/\d+)/(.+)/files")
|
||||
for path in sys.path:
|
||||
if pattern.match(path):
|
||||
result = path.split("/files")[0]
|
||||
break
|
||||
else:
|
||||
result = None
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue