Use appdirs instead of pyxdg

appdirs is used for all systems except Windows.
It has Windows support, so it could be used there as well.
This commit is contained in:
Bastian Germann 2018-10-08 01:34:00 +02:00
parent bd3015babf
commit 5f23d3adea
3 changed files with 16 additions and 18 deletions

View File

@ -26,18 +26,13 @@ import logging
import os import os
import sys import sys
import appdirs
import openlp import openlp
from openlp.core.common import get_frozen_path, is_win, is_macosx from openlp.core.common import get_frozen_path, is_win, is_macosx
from openlp.core.common.path import Path, create_paths from openlp.core.common.path import Path, create_paths
from openlp.core.common.settings import Settings from openlp.core.common.settings import Settings
if not is_win() and not is_macosx():
try:
from xdg import BaseDirectory
XDG_BASE_AVAILABLE = True
except ImportError:
XDG_BASE_AVAILABLE = False
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
FROZEN_APP_PATH = Path(sys.argv[0]).parent FROZEN_APP_PATH = Path(sys.argv[0]).parent
@ -143,8 +138,10 @@ def _get_os_dir_path(dir_type):
elif dir_type == AppLocation.LanguageDir: elif dir_type == AppLocation.LanguageDir:
return Path(openlp.__file__).parent return Path(openlp.__file__).parent
return openlp_folder_path return openlp_folder_path
elif is_macosx():
openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp') dirs = appdirs.AppDirs('openlp', multipath=True)
if is_macosx():
openlp_folder_path = Path(dirs.user_data_dir)
if dir_type == AppLocation.DataDir: if dir_type == AppLocation.DataDir:
return openlp_folder_path / 'Data' return openlp_folder_path / 'Data'
elif dir_type == AppLocation.LanguageDir: elif dir_type == AppLocation.LanguageDir:
@ -152,15 +149,15 @@ def _get_os_dir_path(dir_type):
return openlp_folder_path return openlp_folder_path
else: else:
if dir_type == AppLocation.LanguageDir: if dir_type == AppLocation.LanguageDir:
directory = Path('/usr', 'local', 'share', 'openlp') site_dirs = dirs.site_data_dir.split(os.pathsep)
directory = Path(site_dirs[0])
if directory.exists(): if directory.exists():
return directory return directory
return Path('/usr', 'share', 'openlp') return Path(site_dirs[1])
if XDG_BASE_AVAILABLE: if dir_type == AppLocation.DataDir:
if dir_type == AppLocation.DataDir: return Path(dirs.user_data_dir)
return Path(BaseDirectory.xdg_data_home, 'openlp') elif dir_type == AppLocation.CacheDir:
elif dir_type == AppLocation.CacheDir: return Path(dirs.user_cache_dir)
return Path(BaseDirectory.xdg_cache_home, 'openlp')
if dir_type == AppLocation.DataDir: if dir_type == AppLocation.DataDir:
return Path(os.getenv('HOME'), '.openlp', 'data') return Path(os.getenv('HOME'), '.openlp', 'data')
return Path(os.getenv('HOME'), '.openlp') return Path(os.getenv('HOME'), '.openlp')

View File

@ -79,6 +79,7 @@ MODULES = [
'PyQt5.QtWebKit', 'PyQt5.QtWebKit',
'PyQt5.QtMultimedia', 'PyQt5.QtMultimedia',
'pymediainfo', 'pymediainfo',
'appdirs',
'sqlalchemy', 'sqlalchemy',
'alembic', 'alembic',
'sqlite3', 'sqlite3',

View File

@ -113,6 +113,7 @@ finally:
requires = [ requires = [
'alembic', 'alembic',
'appdirs',
'beautifulsoup4', 'beautifulsoup4',
'chardet', 'chardet',
'lxml', 'lxml',
@ -198,8 +199,7 @@ using a computer and a data projector.""",
'odbc': ['pyodbc'], 'odbc': ['pyodbc'],
'postgresql': ['psycopg2'], 'postgresql': ['psycopg2'],
'spellcheck': ['pyenchant >= 1.6'], 'spellcheck': ['pyenchant >= 1.6'],
'sword-bibles': ['pysword'], 'sword-bibles': ['pysword']
'xdg': ['pyxdg']
}, },
tests_require=['nose2', 'PyICU', 'pylint'], tests_require=['nose2', 'PyICU', 'pylint'],
test_suite='nose2.collector.collector', test_suite='nose2.collector.collector',