Switch from appdirs to QStandardPaths

This commit is contained in:
Florian Bruhin 2014-05-08 22:33:24 +02:00
parent f09f555b68
commit 70c8df095e
6 changed files with 39 additions and 19 deletions

View File

@ -7,7 +7,7 @@ pkgdesc="A keyboard-driven, vim-like browser based on PyQt5 and QtWebKit.",
arch=(any)
url="http://www.qutebrowser.org/"
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')
options=(!emptydirs)
source=('qutebrowser::git://the-compiler.org/qutebrowser')

View File

@ -44,7 +44,7 @@ harfbuzz.fix()
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
from PyQt5.QtCore import pyqtSlot, QTimer, QEventLoop
from appdirs import AppDirs
from PyQt5.QtCore import QStandardPaths
import qutebrowser
import qutebrowser.commands.utils as cmdutils
@ -65,7 +65,7 @@ from qutebrowser.config.iniparsers import ReadWriteConfigParser
from qutebrowser.config.lineparser import LineConfigParser
from qutebrowser.browser.cookies import CookieJar
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
@ -90,7 +90,6 @@ class QuteBrowser(QApplication):
networkmanager: The global NetworkManager instance.
cookiejar: The global CookieJar instance.
_keyparsers: A mapping from modes to keyparsers.
_dirs: AppDirs instance for config/cache directories.
_args: ArgumentParser instance.
_timers: List of used QTimers so they don't get GCed.
_shutting_down: True if we're currently shutting down.
@ -112,7 +111,6 @@ class QuteBrowser(QApplication):
self._opened_urls = []
self._shutting_down = False
self._keyparsers = None
self._dirs = None
self.messagebridge = None
self.stateconfig = None
self.modeman = None
@ -126,9 +124,9 @@ class QuteBrowser(QApplication):
self._init_misc()
self._init_config()
self._init_modes()
websettings.init(self._dirs.user_cache_dir)
websettings.init()
proxy.init()
self.cookiejar = CookieJar(self._dirs.user_data_dir)
self.cookiejar = CookieJar()
self.networkmanager = NetworkManager(self.cookiejar)
self.commandmanager = CommandManager()
self.searchmanager = SearchManager()
@ -168,9 +166,8 @@ class QuteBrowser(QApplication):
def _init_config(self):
"""Inizialize and read the config."""
self._dirs = AppDirs('qutebrowser')
if self._args.confdir is None:
confdir = self._dirs.user_config_dir
confdir = get_standard_dir(QStandardPaths.ConfigLocation)
elif self._args.confdir == '':
confdir = None
else:

View File

@ -17,18 +17,21 @@
"""Handling of HTTP cookies."""
from PyQt5.QtNetwork import QNetworkCookie, QNetworkCookieJar
from PyQt5.QtCore import QStandardPaths
import qutebrowser.config.config as config
from qutebrowser.config.lineparser import LineConfigParser
from PyQt5.QtNetwork import QNetworkCookie, QNetworkCookieJar
from qutebrowser.utils.misc import get_standard_dir
class CookieJar(QNetworkCookieJar):
"""Our own cookie jar to save cookies to disk if desired."""
def __init__(self, datadir):
def __init__(self):
super().__init__()
datadir = get_standard_dir(QStandardPaths.DataLocation)
self._linecp = LineConfigParser(datadir, 'cookies')
cookies = []
for line in self._linecp.data:

View File

@ -28,9 +28,11 @@ Module attributes:
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtCore import QStandardPaths
import qutebrowser.config.config as config
from qutebrowser.utils.usertypes import enum
from qutebrowser.utils.misc import get_standard_dir
MapType = enum('attribute', 'setter', 'static_setter')
@ -144,13 +146,10 @@ def _set_setting(typ, arg, value):
arg(value)
def init(cachedir):
"""Initialize the global QWebSettings.
Args:
cachedir: Directory to save cache files in.
"""
def init():
"""Initialize the global QWebSettings."""
global settings
cachedir = get_standard_dir(QStandardPaths.CacheLocation)
QWebSettings.enablePersistentStorage(cachedir)
settings = QWebSettings.globalSettings()
for name, (typ, arg) in MAPPINGS.items():

View File

@ -17,14 +17,18 @@
"""Other utilities which don't fit anywhere else."""
import os
import re
import sys
import shlex
import os.path
import urllib.request
from urllib.parse import urljoin, urlencode
from functools import reduce
from pkg_resources import resource_string
from PyQt5.QtCore import QStandardPaths
import qutebrowser
@ -133,3 +137,21 @@ def pastebin(text):
if not url.startswith('http'):
raise ValueError("Got unexpected response: {}".format(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

View File

@ -45,6 +45,5 @@ setup(
package_data={'qutebrowser': ['html/*']},
entry_points={'gui_scripts': ['qutebrowser = qutebrowser.__main__:main']},
test_suite='qutebrowser.test',
install_requires=['appdirs >= 1.3.0'],
zip_safe=True,
)