added Android platform detection and androidhelpers module which will be used to determine base paths

This commit is contained in:
Akinwale Ariwodola 2017-08-18 11:52:03 +01:00
parent e204a3b9a5
commit 70881dab6e
3 changed files with 41 additions and 4 deletions

View file

@ -0,0 +1 @@
import paths

View file

@ -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

View file

@ -9,10 +9,12 @@ import envparse
from appdirs import user_data_dir, user_config_dir from appdirs import user_data_dir, user_config_dir
from lbrynet.core import utils from lbrynet.core import utils
from lbrynet.core.Error import InvalidCurrencyError from lbrynet.core.Error import InvalidCurrencyError
from lbrynet.androidhelpers.paths import android_internal_storage_dir, android_app_internal_storage_dir
try: try:
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle 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 pass
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -31,6 +33,7 @@ APP_NAME = 'LBRY'
LINUX = 1 LINUX = 1
DARWIN = 2 DARWIN = 2
WINDOWS = 3 WINDOWS = 3
ANDROID = 4
KB = 2 ** 10 KB = 2 ** 10
MB = 2 ** 20 MB = 2 ** 20
@ -89,7 +92,11 @@ def _get_old_directories(platform):
def _get_new_directories(platform): def _get_new_directories(platform):
dirs = {} 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['data'] = user_data_dir('lbrynet', 'lbry')
dirs['lbryum'] = user_data_dir('lbryum', 'lbry') dirs['lbryum'] = user_data_dir('lbryum', 'lbry')
dirs['download'] = get_path(FOLDERID.Downloads, UserHandle.current) dirs['download'] = get_path(FOLDERID.Downloads, UserHandle.current)
@ -113,7 +120,11 @@ def _get_new_directories(platform):
return dirs 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 platform = DARWIN
dirs = _get_old_directories(DARWIN) dirs = _get_old_directories(DARWIN)
elif 'win' in sys.platform: elif 'win' in sys.platform:
@ -521,7 +532,6 @@ class Config(object):
# type: Config # type: Config
settings = None settings = None
def get_default_env(): def get_default_env():
env_defaults = {} env_defaults = {}
for k, v in ADJUSTABLE_SETTINGS.iteritems(): for k, v in ADJUSTABLE_SETTINGS.iteritems():