mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer SanitizeLibraryPath
This commit is contained in:
parent
459f6706c3
commit
4718175542
@ -1001,27 +1001,26 @@ class SanitizeLibraryPath(object):
|
|||||||
'''Remove the bundled calibre libraries from LD_LIBRARY_PATH on linux. This
|
'''Remove the bundled calibre libraries from LD_LIBRARY_PATH on linux. This
|
||||||
is needed to prevent library conflicts when launching external utilities.'''
|
is needed to prevent library conflicts when launching external utilities.'''
|
||||||
|
|
||||||
|
env_vars = {'LD_LIBRARY_PATH':'/lib', 'QT_PLUGIN_PATH':'/lib/qt_plugins'}
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.orig = os.environ.get('LD_LIBRARY_PATH', '')
|
self.originals = {x:os.environ.get(x, '') for x in self.env_vars}
|
||||||
self.changed = False
|
self.changed = {x:False for x in self.env_vars}
|
||||||
paths = [x for x in self.orig.split(os.pathsep) if x]
|
if isfrozen and islinux:
|
||||||
if isfrozen and islinux and paths:
|
for var, suffix in self.env_vars.iteritems():
|
||||||
npaths = [x for x in paths if x != sys.frozen_path+'/lib']
|
paths = [x for x in self.originals[var].split(os.pathsep) if x]
|
||||||
os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(npaths)
|
npaths = [x for x in paths if x != sys.frozen_path + suffix]
|
||||||
self.changed = True
|
if len(npaths) < len(paths):
|
||||||
self.orig2 = os.environ.get('QT_PLUGIN_PATH', '')
|
if npaths:
|
||||||
self.changed2 = False
|
os.environ[var] = os.pathsep.join(npaths)
|
||||||
paths = [x for x in self.orig2.split(os.pathsep) if x]
|
else:
|
||||||
if isfrozen and islinux and paths:
|
del os.environ[var]
|
||||||
npaths = [x for x in paths if x != sys.frozen_path+'/lib/qt_plugins']
|
self.changed[var] = True
|
||||||
os.environ['QT_PLUGIN_PATH'] = os.pathsep.join(npaths)
|
|
||||||
self.changed2 = True
|
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
if self.changed:
|
for var, orig in self.originals.iteritems():
|
||||||
os.environ['LD_LIBRARY_PATH'] = self.orig
|
if self.changed[var]:
|
||||||
if self.changed2:
|
os.environ[var] = orig
|
||||||
os.environ['QT_PLUGIN_PATH'] = self.orig2
|
|
||||||
|
|
||||||
def open_url(qurl):
|
def open_url(qurl):
|
||||||
if isinstance(qurl, basestring):
|
if isinstance(qurl, basestring):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user