made some more changes to core/__init__ and applocation

This commit is contained in:
Philip Ridout 2017-08-18 20:34:20 +01:00
parent b384e6f2fa
commit 9ee24c32bd
2 changed files with 14 additions and 25 deletions

View File

@ -394,19 +394,19 @@ def main(args=None):
application.setApplicationName('OpenLPPortable') application.setApplicationName('OpenLPPortable')
Settings.setDefaultFormat(Settings.IniFormat) Settings.setDefaultFormat(Settings.IniFormat)
# Get location OpenLPPortable.ini # Get location OpenLPPortable.ini
application_path = str(AppLocation.get_directory(AppLocation.AppDir)) portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' / '..').resolve()
set_up_logging(Path(os.path.abspath(os.path.join(application_path, '..', '..', 'Other')))) data_path = portable_path / 'Data'
set_up_logging(portable_path / 'Other')
log.info('Running portable') log.info('Running portable')
portable_settings_file = os.path.abspath(os.path.join(application_path, '..', '..', 'Data', 'OpenLP.ini')) portable_settings_path = data_path / 'OpenLP.ini'
# Make this our settings file # Make this our settings file
log.info('INI file: {name}'.format(name=portable_settings_file)) log.info('INI file: {name}'.format(name=portable_settings_path))
Settings.set_filename(portable_settings_file) Settings.set_filename(str(portable_settings_path))
portable_settings = Settings() portable_settings = Settings()
# Set our data path # Set our data path
data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',))
log.info('Data path: {name}'.format(name=data_path)) log.info('Data path: {name}'.format(name=data_path))
# Point to our data path # Point to our data path
portable_settings.setValue('advanced/data path', data_path) portable_settings.setValue('advanced/data path', str(data_path))
portable_settings.setValue('advanced/is portable', True) portable_settings.setValue('advanced/is portable', True)
portable_settings.sync() portable_settings.sync()
else: else:

View File

@ -58,9 +58,6 @@ class AppLocation(object):
CacheDir = 5 CacheDir = 5
LanguageDir = 6 LanguageDir = 6
# Base path where data/config/cache dir is located
BaseDir = None
@staticmethod @staticmethod
def get_directory(dir_type=AppDir): def get_directory(dir_type=AppDir):
""" """
@ -78,8 +75,6 @@ class AppLocation(object):
return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins' return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins'
elif dir_type == AppLocation.LanguageDir: elif dir_type == AppLocation.LanguageDir:
return get_frozen_path(FROZEN_APP_PATH, _get_os_dir_path(dir_type)) / 'i18n' return get_frozen_path(FROZEN_APP_PATH, _get_os_dir_path(dir_type)) / 'i18n'
elif dir_type == AppLocation.DataDir and AppLocation.BaseDir:
return Path(AppLocation.BaseDir, 'data')
else: else:
return _get_os_dir_path(dir_type) return _get_os_dir_path(dir_type)
@ -104,14 +99,10 @@ class AppLocation(object):
""" """
Get a list of files from the data files path. Get a list of files from the data files path.
:param section: Defaults to *None*. The section of code getting the files - used to load from a section's data :param None | str section: Defaults to *None*. The section of code getting the files - used to load from a
subdirectory. section's data subdirectory.
:type section: None | str :param str extension: Defaults to ''. The extension to search for. For example::
:param extension: Defaults to ''. The extension to search for. For example::
'.png' '.png'
:type extension: str
:return: List of files found. :return: List of files found.
:rtype: list[pathlib.Path] :rtype: list[pathlib.Path]
""" """
@ -143,14 +134,12 @@ def _get_os_dir_path(dir_type):
Return a path based on which OS and environment we are running in. Return a path based on which OS and environment we are running in.
:param dir_type: AppLocation Enum of the requested path type :param dir_type: AppLocation Enum of the requested path type
:type dir_type: AppLocation Enum
:return: The requested path :return: The requested path
:rtype: pathlib.Path :rtype: pathlib.Path
""" """
# If running from source, return the language directory from the source directory # If running from source, return the language directory from the source directory
if dir_type == AppLocation.LanguageDir: if dir_type == AppLocation.LanguageDir:
directory = Path(os.path.abspath(os.path.join(os.path.dirname(openlp.__file__), '..', 'resources'))) directory = Path(openlp.__file__, '..', '..').resolve() / 'resources'
if directory.exists(): if directory.exists():
return directory return directory
if is_win(): if is_win():
@ -158,14 +147,14 @@ def _get_os_dir_path(dir_type):
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:
return os.path.dirname(openlp.__file__) return Path(openlp.__file__).parent
return openlp_folder_path return openlp_folder_path
elif is_macosx(): elif is_macosx():
openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp') openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp')
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:
return os.path.dirname(openlp.__file__) return Path(openlp.__file__).parent
return openlp_folder_path return openlp_folder_path
else: else:
if dir_type == AppLocation.LanguageDir: if dir_type == AppLocation.LanguageDir: