From 2b8987f65407562aa59c72cd2bc3db71bc96b4e6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 27 Jun 2017 12:04:42 +1000 Subject: [PATCH] fix browse add-ons command failing to load on linux --- aqt/utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/aqt/utils.py b/aqt/utils.py index e0365ddfb..2957a86cb 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -7,6 +7,14 @@ import re, os, sys, urllib.request, urllib.parse, urllib.error, subprocess import aqt from anki.sound import stripSounds from anki.utils import isWin, isMac, invalidFilename +from contextlib import contextmanager + +@contextmanager +def noBundledLibs(): + oldlpath = os.environ.pop("LD_LIBRARY_PATH", None) + yield + if oldlpath is not None: + os.environ["LD_LIBRARY_PATH"] = oldlpath def openHelp(section): link = aqt.appHelpSite @@ -16,7 +24,8 @@ def openHelp(section): def openLink(link): tooltip(_("Loading..."), period=1000) - QDesktopServices.openUrl(QUrl(link)) + with noBundledLibs(): + QDesktopServices.openUrl(QUrl(link)) def showWarning(text, parent=None, help="", title="Anki"): "Show a small warning with an OK button." @@ -351,10 +360,8 @@ def openFolder(path): if isWin: subprocess.Popen(["explorer", "file://"+path]) else: - oldlpath = os.environ.pop("LD_LIBRARY_PATH", None) - QDesktopServices.openUrl(QUrl("file://" + path)) - if oldlpath: - os.environ["LD_LIBRARY_PATH"] = oldlpath + with noBundledLibs(): + QDesktopServices.openUrl(QUrl("file://" + path)) def shortcut(key): if isMac: