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,24 +394,24 @@ def main(args=None):
application.setApplicationName('OpenLPPortable')
Settings.setDefaultFormat(Settings.IniFormat)
# Get location OpenLPPortable.ini
application_path = str(AppLocation.get_directory(AppLocation.AppDir))
set_up_logging(Path(os.path.abspath(os.path.join(application_path, '..', '..', 'Other'))))
portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' / '..').resolve()
data_path = portable_path / 'Data'
set_up_logging(portable_path / 'Other')
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
log.info('INI file: {name}'.format(name=portable_settings_file))
Settings.set_filename(portable_settings_file)
log.info('INI file: {name}'.format(name=portable_settings_path))
Settings.set_filename(str(portable_settings_path))
portable_settings = Settings()
# Set our data path
data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',))
log.info('Data path: {name}'.format(name=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.sync()
else:
application.setApplicationName('OpenLP')
set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
Registry.create()
Registry().register('application', application)
application.setApplicationVersion(get_application_version()['version'])

View File

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