Fix default directories

This commit is contained in:
Zestyr 2017-06-18 04:21:33 +02:00
parent 2dab24ea14
commit e0ff3171d8

View file

@ -2,10 +2,11 @@ import base58
import json import json
import logging import logging
import os import os
import re
import sys import sys
import yaml import yaml
import envparse import envparse
from appdirs import user_data_dir from appdirs import user_data_dir, user_config_dir
from lbrynet.core import utils from lbrynet.core import utils
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -43,25 +44,34 @@ settings_encoders = {
'.yml': yaml.safe_dump '.yml': yaml.safe_dump
} }
if sys.platform.startswith('darwin'): if 'darwin' in sys.platform:
platform = DARWIN platform = DARWIN
default_download_directory = os.path.join(os.path.expanduser('~'), 'Downloads') default_download_directory = os.path.expanduser('~/Downloads')
default_data_dir = user_data_dir('LBRY') default_data_dir = user_data_dir('LBRY')
default_lbryum_dir = os.path.join(os.path.expanduser('~'), '.lbryum') default_lbryum_dir = os.path.expanduser('~/.lbryum')
elif sys.platform.startswith('win'): elif 'nt' in sys.platform:
platform = WINDOWS platform = WINDOWS
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
default_download_directory = get_path(FOLDERID.Downloads, UserHandle.current) default_download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
default_data_dir = os.path.join( default_data_dir = user_data_dir('lbrynet', 'LBRY', roaming=True)
get_path(FOLDERID.RoamingAppData, UserHandle.current), 'lbrynet') default_lbryum_dir = user_data_dir('lbryum', 'LBRY', roaming=True)
default_lbryum_dir = os.path.join(
get_path(FOLDERID.RoamingAppData, UserHandle.current), 'lbryum')
else: else:
platform = LINUX platform = LINUX
default_download_directory = os.path.join(os.path.expanduser('~'), 'Downloads')
default_data_dir = os.path.join(os.path.expanduser('~'), '.lbrynet') try:
default_lbryum_dir = os.path.join(os.path.expanduser('~'), '.lbryum') with open(os.path.join(user_config_dir(), "/user-dirs.dirs"), 'r') as xdg:
down_dir = re.search(r'XDG_DOWNLOAD_DIR=(.+)', xdg.read()).group(1)
down_dir = re.sub('\$HOME', os.getenv('HOME'), down_dir)
default_download_directory = re.sub('\"', "", down_dir)
except:
default_download_directory = os.getenv('XDG_DOWNLOAD_DIR')
finally:
if not default_download_directory:
default_download_directory = os.path.join(os.getenv('HOME'), 'Downloads')
default_data_dir = user_data_dir('LBRY')
default_lbryum_dir = user_config_dir('LBRY')
ICON_PATH = 'icons' if platform is WINDOWS else 'app.icns' ICON_PATH = 'icons' if platform is WINDOWS else 'app.icns'