Skip to content
Permalink
Browse files

fix more flake8 warnings

  • Loading branch information
jef-n committed Mar 5, 2017
1 parent f00a87c commit c77172ed3d50800c80c9165daa061dbe5b6a63c3
Showing 328 changed files with 827 additions and 1,065 deletions.
@@ -57,6 +57,7 @@ def __ne__(self, other):
def __hash__(self):
return 2178309


QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)
QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant)
QPyNullVariant.__eq__ = MethodType(__eq__, None, QPyNullVariant)
@@ -2,6 +2,7 @@

from types import MethodType


_QVariant__repr__ = QVariant.__repr__
_QVariant__eq__ = QVariant.__eq__
_QVariant__ne__ = QVariant.__ne__
@@ -39,6 +40,7 @@ def __hash__(self):
else:
return _QVariant__hash__(self)


QVariant.__bool__ = __bool__
QVariant.__repr__ = __repr__
QVariant.__eq__ = __eq__
@@ -44,5 +44,6 @@ def mapping_geometry(geometry):
# back a string that looks like a dictionary.
return eval(geo)


QgsFeature.__geo_interface__ = property(mapping_feature)
QgsGeometry.__geo_interface__ = property(mapping_geometry)
@@ -38,6 +38,8 @@

def _geometryNonZero(self):
return not self.isEmpty()


QgsGeometry.__nonzero__ = _geometryNonZero
QgsGeometry.__bool__ = _geometryNonZero

@@ -253,4 +255,5 @@ def calculation_finished(exception, value=None):
assert function
return QgsTaskWrapper(description, flags, function, on_finished, *args, **kwargs)


QgsTask.fromFunction = fromFunction
@@ -26,7 +26,6 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsProject, QgsMapLayer, QgsDataSourceUri
import re

from . import resources_rc # NOQA

@@ -93,7 +92,7 @@ def onLayerWasAdded(self, aMapLayer):
def onUpdateSqlLayer(self):
l = self.iface.activeLayer()
if l.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
table = uri.table()
table = QgsDataSourceUri(l.source()).table()
if table.startswith('(') and table.endswith(')'):
self.run()
self.dlg.runSqlLayerWindow(l)
@@ -22,10 +22,6 @@
from builtins import str
from builtins import range

import sys
if sys.version_info < (3,):
memoryview = buffer

from qgis.PyQt.QtCore import Qt, QTime, QRegExp, QAbstractTableModel
from qgis.PyQt.QtGui import QFont, QStandardItemModel, QStandardItem
from qgis.PyQt.QtWidgets import QApplication
@@ -286,7 +286,7 @@ def getTables(self, schema=None, add_sys_tables=False):
pass

for i, tbl in enumerate(items):
tbl.insert(3, False) # not system table
tbl.insert(3, False) # not system table

return sorted(items, key=cmp_to_key(lambda x, y: (x[1] > y[1]) - (x[1] < y[1])))

@@ -351,12 +351,12 @@ def getVectorTables(self, schema=None):
if geomtype == ogr.wkbNone:
item = list([Table.TableType,
lyr.GetName(),
False, # is_view
False, # is_view
])
else:
item = list([Table.VectorType,
lyr.GetName(),
False, # is_view
False, # is_view
lyr.GetName(),
lyr.GetGeometryColumn(),
geomname,
@@ -776,7 +776,7 @@ def addGeometryColumn(self, table, geom_column='geometry', geom_type='POINT', sr
return True

def deleteGeometryColumn(self, table, geom_column):
return False # not supported
return False # not supported

def addTableUniqueConstraint(self, table, column):
""" add a unique constraint to a table """
@@ -150,9 +150,9 @@ def fetchone(self):
row = []
for i in range(len(self.description)):
value = self.qry.value(i)
if (isinstance(value, QDate)
or isinstance(value, QTime)
or isinstance(value, QDateTime)):
if (isinstance(value, QDate) or
isinstance(value, QTime) or
isinstance(value, QDateTime)):
value = value.toString()
elif isinstance(value, QByteArray):
value = u"GEOMETRY"
@@ -35,6 +35,8 @@
from . import QtSqlDB
import sqlite3

from functools import cmp_to_key


def classFactory():
if QSqlDatabase.isDriverAvailable("QOCISPATIAL"):
@@ -473,16 +475,16 @@ def updateCache(self, tableList, schema=None):

def singleGeomTypes(self, geomtypes, srids):
"""Intelligent wkbtype grouping (multi with non multi)"""
if (QgsWkbTypes.Polygon in geomtypes
and QgsWkbTypes.MultiPolygon in geomtypes):
if (QgsWkbTypes.Polygon in geomtypes and
QgsWkbTypes.MultiPolygon in geomtypes):
srids.pop(geomtypes.index(QgsWkbTypes.Polygon))
geomtypes.pop(geomtypes.index(QgsWkbTypes.Polygon))
if (QgsWkbTypes.Point in geomtypes
and QgsWkbTypes.MultiPoint in geomtypes):
if (QgsWkbTypes.Point in geomtypes and
QgsWkbTypes.MultiPoint in geomtypes):
srids.pop(geomtypes.index(QgsWkbTypes.Point))
geomtypes.pop(geomtypes.index(QgsWkbTypes.Point))
if (QgsWkbTypes.LineString in geomtypes
and QgsWkbTypes.MultiLineString in geomtypes):
if (QgsWkbTypes.LineString in geomtypes and
QgsWkbTypes.MultiLineString in geomtypes):
srids.pop(geomtypes.index(QgsWkbTypes.LineString))
geomtypes.pop(geomtypes.index(QgsWkbTypes.LineString))
if QgsWkbTypes.Unknown in geomtypes and len(geomtypes) > 1:
@@ -1431,8 +1433,8 @@ def deleteMetadata(self, table, geom_column=None):
schema, tablename = self.getSchemaTableName(table)
if not (self.getRawTablePrivileges('USER_SDO_GEOM_METADATA',
'MDSYS',
'PUBLIC')[3]
and schema == self.user):
'PUBLIC')[3] and
schema == self.user):
return False

where = u"WHERE TABLE_NAME = {}".format(self.quoteString(tablename))
@@ -1451,8 +1453,8 @@ def updateMetadata(self, table, geom_column, new_geom_column=None,
schema, tablename = self.getSchemaTableName(table)
if not (self.getRawTablePrivileges('USER_SDO_GEOM_METADATA',
'MDSYS',
'PUBLIC')[2]
and schema == self.user):
'PUBLIC')[2] and
schema == self.user):
return False

where = u"WHERE TABLE_NAME = {}".format(self.quoteString(tablename))
@@ -1501,8 +1503,8 @@ def insertMetadata(self, table, geom_column, extent, srid, dim=2):
schema, tablename = self.getSchemaTableName(table)
if not (self.getRawTablePrivileges('USER_SDO_GEOM_METADATA',
'MDSYS',
'PUBLIC')[1]
and schema == self.user):
'PUBLIC')[1] and
schema == self.user):
return False

# in Metadata view, geographic column is always in uppercase
@@ -87,8 +87,8 @@ def __del__(self):
self._deleteCursor()

def getData(self, row, col):
if (row < self.fetchedFrom
or row >= self.fetchedFrom + self.fetchedCount):
if (row < self.fetchedFrom or
row >= self.fetchedFrom + self.fetchedCount):
margin = self.fetchedCount / 2
if row + margin >= self.rowCount():
start = self.rowCount() - margin
@@ -24,7 +24,7 @@
"""

from qgis.PyQt.QtWidgets import QApplication
from qgis.core import Qgis, QgsWkbTypes
from qgis.core import Qgis

from ..info_model import TableInfo, VectorTableInfo, DatabaseInfo
from ..html_elems import HtmlContent, HtmlSection, HtmlParagraph, \
@@ -108,9 +108,9 @@ def generalInfo(self):

# if the estimation is less than 100 rows, try to count them - it
# shouldn't take long time
if (not self.table.isView
and not self.table.rowCount
and self.table.estimatedRowCount < 100):
if (not self.table.isView and
not self.table.rowCount and
self.table.estimatedRowCount < 100):
# row count information is not displayed yet, so just block
# table signals to avoid double refreshing
# (infoViewer->refreshRowCount->tableChanged->infoViewer)
@@ -207,18 +207,18 @@ def generalInfo(self):
ret.append(HtmlTable(tbl))

if schema_priv and schema_priv[1]:
if (table_priv[0]
and not table_priv[1]
and not table_priv[2]
and not table_priv[3]):
if (table_priv[0] and
not table_priv[1] and
not table_priv[2] and
not table_priv[3]):
ret.append(
HtmlParagraph(QApplication.translate(
"DBManagerPlugin",
"<warning> This user has read-only privileges.")))

# primary key defined?
if (not self.table.isView
and self.table.objectType != u"MATERIALIZED VIEW"):
if (not self.table.isView and
self.table.objectType != u"MATERIALIZED VIEW"):
pk = [fld for fld in self.table.fields() if fld.primaryKey]
if len(pk) <= 0:
ret.append(
@@ -639,9 +639,9 @@ def spatialInfo(self):
ret.append(HtmlTable(tbl))

# Handle extent update metadata
if (self.table.extent
and self.table.extent != self.table.estimatedExtent
and self.table.canUpdateMetadata()):
if (self.table.extent and
self.table.extent != self.table.estimatedExtent and
self.table.canUpdateMetadata()):
ret.append(
HtmlParagraph(
QApplication.translate(
@@ -27,7 +27,7 @@
from functools import cmp_to_key

from qgis.PyQt.QtCore import QRegExp
from qgis.core import QgsCredentials, QgsDataSourceUri
from qgis.core import Qgis, QgsCredentials, QgsDataSourceUri

from ..connector import DBConnector
from ..plugin import ConnectionError, DbError, Table
@@ -219,8 +219,6 @@ def hasRasterSupport(self):
return self.has_raster

def hasCustomQuerySupport(self):
from qgis.core import Qgis, QgsWkbTypes

return Qgis.QGIS_VERSION[0:3] >= "1.5"

def hasTableColumnEditingSupport(self):
@@ -712,7 +710,7 @@ def deleteTable(self, table):
if self.isVectorTable(table):
sql = u"SELECT DropGeometryTable(%s%s)" % (schema_part, self.quoteString(tablename))
elif self.isRasterTable(table):
## Fix #8521: delete raster table and references from raster_columns table
# Fix #8521: delete raster table and references from raster_columns table
sql = u"DROP TABLE %s" % self.quoteId(table)
else:
sql = u"DROP TABLE %s" % self.quoteId(table)
@@ -986,31 +984,31 @@ def connection_error_types(self):
# pass

# moved into the parent class: DbConnector._execute_and_commit()
#def _execute_and_commit(self, sql):
# def _execute_and_commit(self, sql):
# pass

# moved into the parent class: DbConnector._get_cursor()
#def _get_cursor(self, name=None):
# def _get_cursor(self, name=None):
# pass

# moved into the parent class: DbConnector._fetchall()
#def _fetchall(self, c):
# def _fetchall(self, c):
# pass

# moved into the parent class: DbConnector._fetchone()
#def _fetchone(self, c):
# def _fetchone(self, c):
# pass

# moved into the parent class: DbConnector._commit()
#def _commit(self):
# def _commit(self):
# pass

# moved into the parent class: DbConnector._rollback()
#def _rollback(self):
# def _rollback(self):
# pass

# moved into the parent class: DbConnector._get_cursor_columns()
#def _get_cursor_columns(self, c):
# def _get_cursor_columns(self, c):
# pass

def getSqlDictionary(self):
@@ -30,7 +30,7 @@ def load(dbplugin, mainwindow):
if not os.path.isdir(os.path.join(current_dir, name)):
continue
try:
exec (u"from .%s import load" % name)
exec(u"from .%s import load" % name)
except ImportError:
continue

@@ -23,8 +23,9 @@
from builtins import str

from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsProject, QgsVectorLayer, Qgis, QgsWkbTypes
from qgis.core import QgsProject, QgsVectorLayer, QgsWkbTypes, QgsLayerTreeGroup
from qgis.gui import QgsMessageBar

import os
@@ -225,7 +226,9 @@ def run(item, action, mainwindow):

faceLayers = [layerFaceMbr, layerFaceGeom, layerFaceSeed]
nodeLayers = [layerNode, layerNodeLabel]
edgeLayers = [layerEdge, layerDirectedEdge, layerEdgeLabel, layerEdgeFaceLeft, layerEdgeFaceRight, layerEdgeNextLeft, layerEdgeNextRight]
edgeLayers = [layerEdge, layerDirectedEdge, layerEdgeLabel
# , layerEdgeFaceLeft, layerEdgeFaceRight, layerEdgeNextLeft, layerEdgeNextRight
]

QgsProject.instance().addMapLayers(faceLayers, False)

@@ -236,13 +239,13 @@ def run(item, action, mainwindow):
nodeLayer.setExpanded(False)

groupNodes = QgsLayerTreeGroup(u'Nodes')
for layer in faceLayers:
for layer in nodeLayers:
nodeLayer = groupNodes.addLayer(layer)
nodeLayer.setVisible(Qt.Unchecked)
nodeLayer.setExpanded(False)

groupEdges = QgsLayerTreeGroup(u'Edges')
for layer in faceLayers:
for layer in edgeLayers:
nodeLayer = groupEdges.addLayer(layer)
nodeLayer.setVisible(Qt.Unchecked)
nodeLayer.setExpanded(False)
@@ -20,11 +20,10 @@
***************************************************************************/
"""
from builtins import str
from builtins import map

from functools import cmp_to_key

from qgis.PyQt.QtCore import QFile
from qgis.PyQt.QtCore import QFile, Qgis
from qgis.PyQt.QtWidgets import QApplication

from ..connector import DBConnector
@@ -141,8 +140,6 @@ def hasRasterSupport(self):
return self.has_raster

def hasCustomQuerySupport(self):
from qgis.core import Qgis, QgsWkbTypes

return Qgis.QGIS_VERSION[0:3] >= "1.6"

def hasTableColumnEditingSupport(self):
@@ -26,7 +26,7 @@
from ..connector import DBConnector
from ..plugin import Table

from qgis.core import Qgis, QgsDataSourceUri, QgsVirtualLayerDefinition, QgsProject, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsWkbTypes, QgsVirtualLayerDefinition
from qgis.core import QgsDataSourceUri, QgsVirtualLayerDefinition, QgsProject, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsWkbTypes

import sqlite3

0 comments on commit c77172e

Please sign in to comment.
You can’t perform that action at this time.