Add a context manager to unset organizationName.
This commit is contained in:
parent
83b636a0a7
commit
9534deb2e7
@ -37,6 +37,7 @@ import contextlib
|
||||
|
||||
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
|
||||
QIODevice, QSaveFile)
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
|
||||
|
||||
MAXVALS = {
|
||||
@ -200,6 +201,21 @@ def savefile_open(filename, binary=False, encoding='utf-8'):
|
||||
raise OSError(f.errorString())
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def unset_organization():
|
||||
"""Temporarily unset QApplication.organizationName().
|
||||
|
||||
This is primarily needed in config.py.
|
||||
"""
|
||||
qapp = QApplication.instance()
|
||||
orgname = qapp.organizationName()
|
||||
qapp.setOrganizationName(None)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
qapp.setOrganizationName(orgname)
|
||||
|
||||
|
||||
class PyQIODevice(io.BufferedIOBase):
|
||||
|
||||
"""Wrapper for a QIODevice which provides a python interface.
|
||||
|
@ -24,21 +24,13 @@ import os.path
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication, QStandardPaths
|
||||
|
||||
from qutebrowser.utils import log
|
||||
from qutebrowser.utils import log, qtutils
|
||||
|
||||
|
||||
def _writable_location(typ):
|
||||
"""Wrapper around QStandardPaths.writableLocation."""
|
||||
qapp = QCoreApplication.instance()
|
||||
orgname = qapp.organizationName()
|
||||
# We need to temporarily unset the organisationname here since the
|
||||
# webinspector wants it to be set to store its persistent data correctly,
|
||||
# but we don't want that to happen.
|
||||
qapp.setOrganizationName(None)
|
||||
try:
|
||||
with qtutils.unset_organization():
|
||||
path = QStandardPaths.writableLocation(typ)
|
||||
finally:
|
||||
qapp.setOrganizationName(orgname)
|
||||
if not path:
|
||||
raise ValueError("QStandardPaths returned an empty value!")
|
||||
# Qt seems to use '/' as path separator even on Windows...
|
||||
|
Loading…
Reference in New Issue
Block a user