Fix pylint and flake8 for SQL work.
Vanity commit. This also touches up a few comments.
This commit is contained in:
parent
ea9217a61f
commit
ffd044b52b
@ -36,7 +36,7 @@ class Entry:
|
||||
Attributes:
|
||||
atime: The time the page was accessed.
|
||||
url: The URL which was accessed as QUrl.
|
||||
redirect: If True, don't save this entry to disk
|
||||
redirect: If True, don't show this entry in completion
|
||||
"""
|
||||
|
||||
def __init__(self, atime, url, title, redirect=False):
|
||||
|
@ -22,13 +22,13 @@
|
||||
import re
|
||||
|
||||
from PyQt5.QtCore import Qt, QModelIndex, QAbstractItemModel
|
||||
from PyQt5.QtSql import QSqlQuery, QSqlQueryModel, QSqlDatabase
|
||||
from PyQt5.QtSql import QSqlQueryModel
|
||||
|
||||
from qutebrowser.utils import log
|
||||
from qutebrowser.misc import sql
|
||||
|
||||
|
||||
class SqlCompletionCategory(QSqlQueryModel):
|
||||
class _SqlCompletionCategory(QSqlQueryModel):
|
||||
def __init__(self, name, sort_by, sort_order, limit, select, where,
|
||||
columns_to_filter, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
@ -105,10 +105,10 @@ class SqlCompletionModel(QAbstractItemModel):
|
||||
|
||||
Return: A new CompletionCategory.
|
||||
"""
|
||||
cat = SqlCompletionCategory(name, parent=self, sort_by=sort_by,
|
||||
sort_order=sort_order, limit=limit,
|
||||
select=select, where=where,
|
||||
columns_to_filter=self.columns_to_filter)
|
||||
cat = _SqlCompletionCategory(name, parent=self, sort_by=sort_by,
|
||||
sort_order=sort_order, limit=limit,
|
||||
select=select, where=where,
|
||||
columns_to_filter=self.columns_to_filter)
|
||||
self._categories.append(cat)
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
|
@ -39,13 +39,13 @@ def _delete_url(completion):
|
||||
category = index.parent()
|
||||
index = category.child(index.row(), _URLCOL)
|
||||
catname = category.data()
|
||||
url = index.data()
|
||||
qtutils.ensure_valid(category)
|
||||
|
||||
if catname == 'Bookmarks':
|
||||
log.completion.debug('Deleting bookmark {}'.format(url))
|
||||
urlstr = index.data()
|
||||
log.completion.debug('Deleting bookmark {}'.format(urlstr))
|
||||
bookmark_manager = objreg.get('bookmark-manager')
|
||||
bookmark_manager.delete(url)
|
||||
bookmark_manager.delete(urlstr)
|
||||
else:
|
||||
assert catname == 'Quickmarks', 'Unknown category {}'.format(catname)
|
||||
quickmark_manager = objreg.get('quickmark-manager')
|
||||
|
@ -65,6 +65,7 @@ class SqlTable(QObject):
|
||||
"""Interface to a sql table.
|
||||
|
||||
Attributes:
|
||||
Entry: The class wrapping row data from this table.
|
||||
_name: Name of the SQL table this wraps.
|
||||
_primary_key: The primary key of the table.
|
||||
|
||||
@ -87,8 +88,9 @@ class SqlTable(QObject):
|
||||
super().__init__(parent)
|
||||
self._name = name
|
||||
self._primary_key = primary_key
|
||||
run_query("CREATE TABLE {} ({}, PRIMARY KEY ({}))"
|
||||
.format(name, ','.join(fields), primary_key))
|
||||
run_query("CREATE TABLE {} ({}, PRIMARY KEY ({}))".format(
|
||||
name, ','.join(fields), primary_key))
|
||||
# pylint: disable=invalid-name
|
||||
self.Entry = collections.namedtuple(name + '_Entry', fields)
|
||||
|
||||
def __iter__(self):
|
||||
@ -104,8 +106,8 @@ class SqlTable(QObject):
|
||||
Args:
|
||||
key: Primary key value to search for.
|
||||
"""
|
||||
query = run_query("SELECT * FROM {} where {} = ?"
|
||||
.format(self._name, self._primary_key), [key])
|
||||
query = run_query("SELECT * FROM {} where {} = ?".format(
|
||||
self._name, self._primary_key), [key])
|
||||
return query.next()
|
||||
|
||||
def __len__(self):
|
||||
@ -120,8 +122,8 @@ class SqlTable(QObject):
|
||||
Args:
|
||||
key: Primary key value to fetch.
|
||||
"""
|
||||
result = run_query("SELECT * FROM {} where {} = ?"
|
||||
.format(self._name, self._primary_key), [key])
|
||||
result = run_query("SELECT * FROM {} where {} = ?".format(
|
||||
self._name, self._primary_key), [key])
|
||||
result.next()
|
||||
rec = result.record()
|
||||
return self.Entry(*[rec.value(i) for i in range(rec.count())])
|
||||
@ -137,8 +139,8 @@ class SqlTable(QObject):
|
||||
The number of rows deleted.
|
||||
"""
|
||||
field = field or self._primary_key
|
||||
query = run_query("DELETE FROM {} where {} = ?"
|
||||
.format(self._name, field), [value])
|
||||
query = run_query("DELETE FROM {} where {} = ?".format(
|
||||
self._name, field), [value])
|
||||
if not query.numRowsAffected():
|
||||
raise KeyError('No row with {} = "{}"'.format(field, value))
|
||||
self.changed.emit()
|
||||
@ -152,8 +154,8 @@ class SqlTable(QObject):
|
||||
"""
|
||||
cmd = "REPLACE" if replace else "INSERT"
|
||||
paramstr = ','.join(['?'] * len(values))
|
||||
run_query("{} INTO {} values({})"
|
||||
.format(cmd, self._name, paramstr), values)
|
||||
run_query("{} INTO {} values({})".format(cmd, self._name, paramstr),
|
||||
values)
|
||||
self.changed.emit()
|
||||
|
||||
def delete_all(self):
|
||||
|
@ -36,7 +36,7 @@ class FakeCompletionModel(QStandardItemModel):
|
||||
def __init__(self, kind, *pos_args, parent=None):
|
||||
super().__init__(parent)
|
||||
self.kind = kind
|
||||
self.pos_args = [*pos_args]
|
||||
self.pos_args = list(pos_args)
|
||||
|
||||
|
||||
class CompletionWidgetStub(QObject):
|
||||
|
@ -232,6 +232,7 @@ def test_where():
|
||||
model.new_category('test_where', where='not c')
|
||||
_check_model(model, [('test_where', [('foo', 'bar', False)])])
|
||||
|
||||
|
||||
def test_entry():
|
||||
table = sql.SqlTable('test_entry', ['a', 'b', 'c'], primary_key='a')
|
||||
assert hasattr(table.Entry, 'a')
|
||||
|
Loading…
Reference in New Issue
Block a user