Skip to content

Commit

Permalink
Pick files from /usr/(local/)share with sys.prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Aug 31, 2020
1 parent 77aa66f commit bf9e237
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions printrun/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import locale
import logging

DATADIR = os.path.join(sys.prefix, 'share')


def set_utf8_locale():
"""Make sure we read/write all text files in UTF-8"""
Expand All @@ -34,10 +36,9 @@ def set_utf8_locale():
# searching for installed locales on /usr/share; uses relative folder if not
# found (windows)
def install_locale(domain):
if os.path.exists('/usr/share/locale'):
gettext.install(domain, '/usr/share/locale')
elif os.path.exists('/usr/local/share/locale'):
gettext.install(domain, '/usr/local/share/locale')
shared_locale_dir = os.path.join(DATADIR, 'locale')
if os.path.exists(shared_locale_dir):
gettext.install(domain, shared_locale_dir)
else:
gettext.install(domain, './locale')

Expand Down Expand Up @@ -78,11 +79,10 @@ def iconfile(filename):
return pixmapfile(filename)

def imagefile(filename):
for prefix in ['/usr/local/share/pronterface/images',
'/usr/share/pronterface/images']:
candidate = os.path.join(prefix, filename)
if os.path.exists(candidate):
return candidate
shared_pronterface_images_dir = os.path.join(DATADIR, 'pronterface/images')
candidate = os.path.join(shared_pronterface_images_dir, filename)
if os.path.exists(candidate):
return candidate
local_candidate = os.path.join(os.path.dirname(sys.argv[0]),
"images", filename)
if os.path.exists(local_candidate):
Expand All @@ -105,12 +105,12 @@ def lookup_file(filename, prefixes):
return filename

def pixmapfile(filename):
return lookup_file(filename, ['/usr/local/share/pixmaps',
'/usr/share/pixmaps'])
shared_pixmaps_dir = os.path.join(DATADIR, 'pixmaps')
return lookup_file(filename, [shared_pixmaps_dir])

def sharedfile(filename):
return lookup_file(filename, ['/usr/local/share/pronterface',
'/usr/share/pronterface'])
shared_pronterface_dir = os.path.join(DATADIR, 'pronterface')
return lookup_file(filename, [shared_pronterface_dir])

def configfile(filename):
return lookup_file(filename, [os.path.expanduser("~/.printrun/"), ])
Expand Down

0 comments on commit bf9e237

Please sign in to comment.