From 6dd056541cafcf831cc54af2f02cd9012fae41f1 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Thu, 3 Dec 2020 18:41:04 +0100 Subject: [PATCH] fixed data path on ubuntu --- keymapper/data.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/keymapper/data.py b/keymapper/data.py index 84d1173e..cf64bb08 100644 --- a/keymapper/data.py +++ b/keymapper/data.py @@ -30,6 +30,9 @@ import pkg_resources from keymapper.logger import logger +logged = False + + def get_data_path(filename=''): """Depending on the installation prefix, return the data dir. @@ -58,8 +61,10 @@ def get_data_path(filename=''): '/usr/share/key-mapper' ] - print('source_path', source_path) - if '/site-packages' not in source_path: + global logged + data_path = None + # python3.8/dist-packages python3.7/site-packages, /usr/share, /usr/local/share, endless options + if '-packages' not in source_path and 'python' not in source_path: # probably installed with -e, running from the cloned git source data_path = os.path.join(source_path, 'data') else: @@ -68,6 +73,12 @@ def get_data_path(filename=''): if os.path.exists(candidate): data_path = candidate break - logger.error('Could not find the application data') + if data_path is None: + logger.error('Could not find the application data') + sys.exit(1) + + if not logged: + logger.debug('Found data at "%s"', data_path) + logged = True return os.path.join(data_path, filename)