Working with local resources path

This commit is contained in:
Vinicius Moreira
2019-06-17 12:52:25 -03:00
parent ef3294a8c1
commit 30fe0c62fa
3 changed files with 23 additions and 10 deletions

View File

@@ -1,10 +1,13 @@
import os
import getpass
local_resource_path = '/home/{}/.local/share/fpakman/resources'.format(getpass.getuser())
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def get_path(resource_path):
app_dir = get_app_dir()
return app_dir + '/resources/' + resource_path
def get_app_dir():
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if os.path.exists(local_resource_path):
return local_resource_path + resource_path
else:
return app_dir + '/resources/' + resource_path

View File

@@ -8,10 +8,11 @@ def get_locale_keys():
current_locale = locale.getdefaultlocale()
locale_path = None
if current_locale:
current_locale = current_locale[0]
locale_dir = '{}/resources/locale'.format(resource.get_app_dir())
locale_dir = resource.get_path('/locale')
for locale_file in glob.glob(locale_dir + '/*'):
name = locale_file.split('/')[-1]
@@ -21,7 +22,7 @@ def get_locale_keys():
break
if not locale_path:
locale_path = '{}/resources/locale/en'.format(resource.get_app_dir())
locale_path = resource.get_path('locale/en')
with open(locale_path, 'r') as f:
locale_keys = f.readlines()