From 70881dab6ed25871899a0e9356e1028b5cc4f2f9 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 18 Aug 2017 11:52:03 +0100 Subject: [PATCH] added Android platform detection and androidhelpers module which will be used to determine base paths --- lbrynet/androidhelpers/__init__.py | 1 + lbrynet/androidhelpers/paths.py | 26 ++++++++++++++++++++++++++ lbrynet/conf.py | 18 ++++++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 lbrynet/androidhelpers/__init__.py create mode 100644 lbrynet/androidhelpers/paths.py diff --git a/lbrynet/androidhelpers/__init__.py b/lbrynet/androidhelpers/__init__.py new file mode 100644 index 000000000..672ab154e --- /dev/null +++ b/lbrynet/androidhelpers/__init__.py @@ -0,0 +1 @@ +import paths \ No newline at end of file diff --git a/lbrynet/androidhelpers/paths.py b/lbrynet/androidhelpers/paths.py new file mode 100644 index 000000000..013a7a6c3 --- /dev/null +++ b/lbrynet/androidhelpers/paths.py @@ -0,0 +1,26 @@ +# App root files dir +# https://developer.android.com/reference/android/content/ContextWrapper.html#getFilesDir%28%29 +def android_files_dir(): + return None + + +# Base internal storage path +def android_internal_storage_dir(): + return None + + +# Base external (SD card, if present) storage path +def android_external_storage_dir(): + return None + + +# Internal device storage (private app folder) +# https://developer.android.com/reference/android/content/ContextWrapper.html#getExternalFilesDirs(java.lang.String) +def android_app_internal_storage_dir(): + return None + + +# External (app folder on SD card, if present) storage +# https://developer.android.com/reference/android/content/ContextWrapper.html#getExternalFilesDirs(java.lang.String) +def android_app_external_storage_dir(): + return None \ No newline at end of file diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 1c7a041da..20579d1f4 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -9,10 +9,12 @@ import envparse from appdirs import user_data_dir, user_config_dir from lbrynet.core import utils from lbrynet.core.Error import InvalidCurrencyError +from lbrynet.androidhelpers.paths import android_internal_storage_dir, android_app_internal_storage_dir try: from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle -except (ImportError, ValueError): +except (ImportError, ValueError, NameError): + # Android platform: NameError: name 'c_wchar' is not defined pass log = logging.getLogger(__name__) @@ -31,6 +33,7 @@ APP_NAME = 'LBRY' LINUX = 1 DARWIN = 2 WINDOWS = 3 +ANDROID = 4 KB = 2 ** 10 MB = 2 ** 20 @@ -89,7 +92,11 @@ def _get_old_directories(platform): def _get_new_directories(platform): dirs = {} - if platform == WINDOWS: + if platform == ANDROID: + dirs['data'] = '%s/lbrynet' % android_app_internal_storage_dir() + dirs['lbryum'] = '%s/lbryum' % android_app_internal_storage_dir() + dirs['download'] = '%s/Download' % android_internal_storage_dir() + elif platform == WINDOWS: dirs['data'] = user_data_dir('lbrynet', 'lbry') dirs['lbryum'] = user_data_dir('lbryum', 'lbry') dirs['download'] = get_path(FOLDERID.Downloads, UserHandle.current) @@ -113,7 +120,11 @@ def _get_new_directories(platform): return dirs -if 'darwin' in sys.platform: +if 'ANDROID_ARGUMENT' in os.environ: + # https://github.com/kivy/kivy/blob/master/kivy/utils.py#L417-L421 + platform = ANDROID + dirs = _get_new_directories(ANDROID) +elif 'darwin' in sys.platform: platform = DARWIN dirs = _get_old_directories(DARWIN) elif 'win' in sys.platform: @@ -521,7 +532,6 @@ class Config(object): # type: Config settings = None - def get_default_env(): env_defaults = {} for k, v in ADJUSTABLE_SETTINGS.iteritems():