Switch from appdirs to QStandardPaths
This commit is contained in:
parent
f09f555b68
commit
70c8df095e
@ -7,7 +7,7 @@ pkgdesc="A keyboard-driven, vim-like browser based on PyQt5 and QtWebKit.",
|
|||||||
arch=(any)
|
arch=(any)
|
||||||
url="http://www.qutebrowser.org/"
|
url="http://www.qutebrowser.org/"
|
||||||
license=('GPL')
|
license=('GPL')
|
||||||
depends=('python' 'python-setuptools' 'python-appdirs' 'python-pyqt5' 'qt5-base' 'qt5-webkit')
|
depends=('python' 'python-setuptools' 'python-pyqt5' 'qt5-base' 'qt5-webkit')
|
||||||
makedepends=('python' 'python-setuptools')
|
makedepends=('python' 'python-setuptools')
|
||||||
options=(!emptydirs)
|
options=(!emptydirs)
|
||||||
source=('qutebrowser::git://the-compiler.org/qutebrowser')
|
source=('qutebrowser::git://the-compiler.org/qutebrowser')
|
||||||
|
@ -44,7 +44,7 @@ harfbuzz.fix()
|
|||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||||
from PyQt5.QtCore import pyqtSlot, QTimer, QEventLoop
|
from PyQt5.QtCore import pyqtSlot, QTimer, QEventLoop
|
||||||
from appdirs import AppDirs
|
from PyQt5.QtCore import QStandardPaths
|
||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
import qutebrowser.commands.utils as cmdutils
|
import qutebrowser.commands.utils as cmdutils
|
||||||
@ -65,7 +65,7 @@ from qutebrowser.config.iniparsers import ReadWriteConfigParser
|
|||||||
from qutebrowser.config.lineparser import LineConfigParser
|
from qutebrowser.config.lineparser import LineConfigParser
|
||||||
from qutebrowser.browser.cookies import CookieJar
|
from qutebrowser.browser.cookies import CookieJar
|
||||||
from qutebrowser.utils.message import MessageBridge
|
from qutebrowser.utils.message import MessageBridge
|
||||||
from qutebrowser.utils.misc import dotted_getattr
|
from qutebrowser.utils.misc import dotted_getattr, get_standard_dir
|
||||||
from qutebrowser.utils.debug import set_trace # pylint: disable=unused-import
|
from qutebrowser.utils.debug import set_trace # pylint: disable=unused-import
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +90,6 @@ class QuteBrowser(QApplication):
|
|||||||
networkmanager: The global NetworkManager instance.
|
networkmanager: The global NetworkManager instance.
|
||||||
cookiejar: The global CookieJar instance.
|
cookiejar: The global CookieJar instance.
|
||||||
_keyparsers: A mapping from modes to keyparsers.
|
_keyparsers: A mapping from modes to keyparsers.
|
||||||
_dirs: AppDirs instance for config/cache directories.
|
|
||||||
_args: ArgumentParser instance.
|
_args: ArgumentParser instance.
|
||||||
_timers: List of used QTimers so they don't get GCed.
|
_timers: List of used QTimers so they don't get GCed.
|
||||||
_shutting_down: True if we're currently shutting down.
|
_shutting_down: True if we're currently shutting down.
|
||||||
@ -112,7 +111,6 @@ class QuteBrowser(QApplication):
|
|||||||
self._opened_urls = []
|
self._opened_urls = []
|
||||||
self._shutting_down = False
|
self._shutting_down = False
|
||||||
self._keyparsers = None
|
self._keyparsers = None
|
||||||
self._dirs = None
|
|
||||||
self.messagebridge = None
|
self.messagebridge = None
|
||||||
self.stateconfig = None
|
self.stateconfig = None
|
||||||
self.modeman = None
|
self.modeman = None
|
||||||
@ -126,9 +124,9 @@ class QuteBrowser(QApplication):
|
|||||||
self._init_misc()
|
self._init_misc()
|
||||||
self._init_config()
|
self._init_config()
|
||||||
self._init_modes()
|
self._init_modes()
|
||||||
websettings.init(self._dirs.user_cache_dir)
|
websettings.init()
|
||||||
proxy.init()
|
proxy.init()
|
||||||
self.cookiejar = CookieJar(self._dirs.user_data_dir)
|
self.cookiejar = CookieJar()
|
||||||
self.networkmanager = NetworkManager(self.cookiejar)
|
self.networkmanager = NetworkManager(self.cookiejar)
|
||||||
self.commandmanager = CommandManager()
|
self.commandmanager = CommandManager()
|
||||||
self.searchmanager = SearchManager()
|
self.searchmanager = SearchManager()
|
||||||
@ -168,9 +166,8 @@ class QuteBrowser(QApplication):
|
|||||||
|
|
||||||
def _init_config(self):
|
def _init_config(self):
|
||||||
"""Inizialize and read the config."""
|
"""Inizialize and read the config."""
|
||||||
self._dirs = AppDirs('qutebrowser')
|
|
||||||
if self._args.confdir is None:
|
if self._args.confdir is None:
|
||||||
confdir = self._dirs.user_config_dir
|
confdir = get_standard_dir(QStandardPaths.ConfigLocation)
|
||||||
elif self._args.confdir == '':
|
elif self._args.confdir == '':
|
||||||
confdir = None
|
confdir = None
|
||||||
else:
|
else:
|
||||||
|
@ -17,18 +17,21 @@
|
|||||||
|
|
||||||
"""Handling of HTTP cookies."""
|
"""Handling of HTTP cookies."""
|
||||||
|
|
||||||
|
from PyQt5.QtNetwork import QNetworkCookie, QNetworkCookieJar
|
||||||
|
from PyQt5.QtCore import QStandardPaths
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
from qutebrowser.config.lineparser import LineConfigParser
|
from qutebrowser.config.lineparser import LineConfigParser
|
||||||
|
from qutebrowser.utils.misc import get_standard_dir
|
||||||
from PyQt5.QtNetwork import QNetworkCookie, QNetworkCookieJar
|
|
||||||
|
|
||||||
|
|
||||||
class CookieJar(QNetworkCookieJar):
|
class CookieJar(QNetworkCookieJar):
|
||||||
|
|
||||||
"""Our own cookie jar to save cookies to disk if desired."""
|
"""Our own cookie jar to save cookies to disk if desired."""
|
||||||
|
|
||||||
def __init__(self, datadir):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
datadir = get_standard_dir(QStandardPaths.DataLocation)
|
||||||
self._linecp = LineConfigParser(datadir, 'cookies')
|
self._linecp = LineConfigParser(datadir, 'cookies')
|
||||||
cookies = []
|
cookies = []
|
||||||
for line in self._linecp.data:
|
for line in self._linecp.data:
|
||||||
|
@ -28,9 +28,11 @@ Module attributes:
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot
|
from PyQt5.QtCore import pyqtSlot
|
||||||
from PyQt5.QtWebKit import QWebSettings
|
from PyQt5.QtWebKit import QWebSettings
|
||||||
|
from PyQt5.QtCore import QStandardPaths
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
from qutebrowser.utils.usertypes import enum
|
from qutebrowser.utils.usertypes import enum
|
||||||
|
from qutebrowser.utils.misc import get_standard_dir
|
||||||
|
|
||||||
MapType = enum('attribute', 'setter', 'static_setter')
|
MapType = enum('attribute', 'setter', 'static_setter')
|
||||||
|
|
||||||
@ -144,13 +146,10 @@ def _set_setting(typ, arg, value):
|
|||||||
arg(value)
|
arg(value)
|
||||||
|
|
||||||
|
|
||||||
def init(cachedir):
|
def init():
|
||||||
"""Initialize the global QWebSettings.
|
"""Initialize the global QWebSettings."""
|
||||||
|
|
||||||
Args:
|
|
||||||
cachedir: Directory to save cache files in.
|
|
||||||
"""
|
|
||||||
global settings
|
global settings
|
||||||
|
cachedir = get_standard_dir(QStandardPaths.CacheLocation)
|
||||||
QWebSettings.enablePersistentStorage(cachedir)
|
QWebSettings.enablePersistentStorage(cachedir)
|
||||||
settings = QWebSettings.globalSettings()
|
settings = QWebSettings.globalSettings()
|
||||||
for name, (typ, arg) in MAPPINGS.items():
|
for name, (typ, arg) in MAPPINGS.items():
|
||||||
|
@ -17,14 +17,18 @@
|
|||||||
|
|
||||||
"""Other utilities which don't fit anywhere else."""
|
"""Other utilities which don't fit anywhere else."""
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import shlex
|
import shlex
|
||||||
|
import os.path
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.parse import urljoin, urlencode
|
from urllib.parse import urljoin, urlencode
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from pkg_resources import resource_string
|
from pkg_resources import resource_string
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QStandardPaths
|
||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
|
|
||||||
|
|
||||||
@ -133,3 +137,21 @@ def pastebin(text):
|
|||||||
if not url.startswith('http'):
|
if not url.startswith('http'):
|
||||||
raise ValueError("Got unexpected response: {}".format(url))
|
raise ValueError("Got unexpected response: {}".format(url))
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def get_standard_dir(typ):
|
||||||
|
"""Get the directory where files of the given type should be written to.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
typ: A member of the QStandardPaths::StandardLocation enum,
|
||||||
|
see http://qt-project.org/doc/qt-5/qstandardpaths.html#StandardLocation-enum
|
||||||
|
"""
|
||||||
|
# FIXME we could easily add some unittests for this
|
||||||
|
path = QStandardPaths.writableLocation(typ)
|
||||||
|
if (typ == QStandardPaths.ConfigLocation and
|
||||||
|
os.path.split(path)[-1] != 'qutebrowser'):
|
||||||
|
# Workaround for https://bugreports.qt-project.org/browse/QTBUG-38872
|
||||||
|
path = os.path.join(path, 'qutebrowser')
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
return path
|
||||||
|
1
setup.py
1
setup.py
@ -45,6 +45,5 @@ setup(
|
|||||||
package_data={'qutebrowser': ['html/*']},
|
package_data={'qutebrowser': ['html/*']},
|
||||||
entry_points={'gui_scripts': ['qutebrowser = qutebrowser.__main__:main']},
|
entry_points={'gui_scripts': ['qutebrowser = qutebrowser.__main__:main']},
|
||||||
test_suite='qutebrowser.test',
|
test_suite='qutebrowser.test',
|
||||||
install_requires=['appdirs >= 1.3.0'],
|
|
||||||
zip_safe=True,
|
zip_safe=True,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user