Skip to content

Commit

Permalink
db_manager: cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 21, 2016
1 parent d25c253 commit c55f8b7
Show file tree
Hide file tree
Showing 34 changed files with 141 additions and 157 deletions.
5 changes: 3 additions & 2 deletions python/plugins/db_manager/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import functools

from PyQt.QtCore import QObject, Qt, QSettings, QByteArray, QSize
from PyQt.QtCore import Qt, QSettings, QByteArray, QSize
from PyQt.QtWidgets import QMainWindow, QApplication, QMenu, QTabWidget, QGridLayout, QSpacerItem, QSizePolicy, QDockWidget, QStatusBar, QMenuBar, QToolBar, QTabBar
from PyQt.QtGui import QIcon, QKeySequence

Expand Down Expand Up @@ -214,7 +214,8 @@ def registerAction(self, action, menuName, callback=None):
self._registeredDbActions = {}

if callback is not None:
invoke_callback = lambda x: self.invokeCallback(callback)
def invoke_callback(x):
return self.invokeCallback(callback)

if menuName is None or menuName == "":
self.addAction(action)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/db_manager_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
***************************************************************************/
"""

from PyQt.QtCore import Qt, QObject
from PyQt.QtCore import Qt
from PyQt.QtWidgets import QAction, QApplication
from PyQt.QtGui import QIcon

from . import resources_rc
from . import resources_rc # NOQA


class DBManagerPlugin:
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/db_manager/db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

from qgis.core import QgsDataSourceURI, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils

from . import resources_rc
from . import resources_rc # NOQA

try:
from qgis.core import QgsVectorLayerImport
from qgis.core import QgsVectorLayerImport # NOQA
isImportVectorAvail = True
except:
isImportVectorAvail = False
Expand Down Expand Up @@ -491,7 +491,7 @@ def _refreshIndex(self, index, force=False):
else:
self.notPopulated.emit(index)

except BaseError as e:
except BaseError:
item.populated = False
return

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/db_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def initDbPluginList():
continue

try:
exec (u"from .%s import plugin as mod" % name, globals())
exec(u"from .%s import plugin as mod" % name, globals())
except ImportError as e:
DBPLUGIN_ERRORS.append(u"%s: %s" % (name, unicode(e)))
continue

pluginclass = mod.classFactory()
pluginclass = mod.classFactory() # NOQA
SUPPORTED_DBTYPES[pluginclass.typeName()] = pluginclass

return len(SUPPORTED_DBTYPES) > 0
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/db_manager/db_plugins/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _close_cursor(self, c):
if c and not c.closed:
c.close()

except self.error_types() as e:
except self.error_types():
pass

return
Expand Down Expand Up @@ -168,9 +168,9 @@ def _rollback(self):
def _get_cursor_columns(self, c):
try:
if c.description:
return map(lambda x: x[0], c.description)
return [x[0] for x in c.description]

except self.connection_error_types() + self.execution_error_types() as e:
except self.connection_error_types() + self.execution_error_types():
return []

@classmethod
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/db_manager/db_plugins/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def data(self, index, role):
# too much data to display, elide the string
val = val[:300]
try:
return unicode(val) # convert to unicode
return unicode(val) # convert to unicode
except UnicodeDecodeError:
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)

def headerData(self, section, orientation, role):
if role != Qt.DisplayRole:
Expand All @@ -100,7 +100,7 @@ def __init__(self, table, parent=None):
self.db = table.database().connector
self.table = table

fieldNames = map(lambda x: x.name, table.fields())
fieldNames = [x.name for x in table.fields()]
BaseTableModel.__init__(self, fieldNames, None, parent)

# get table fields
Expand Down Expand Up @@ -267,7 +267,7 @@ def __init__(self, parent, editable=False):
QApplication.translate("DBManagerPlugin", 'Column(s)')], editable, parent)

def append(self, constr):
field_names = map(lambda k_v: unicode(k_v[1].name), iter(constr.fields().items()))
field_names = [unicode(k_v[1].name) for k_v in iter(list(constr.fields().items()))]
data = [constr.name, constr.type2String(), u", ".join(field_names)]
self.appendRow(self.rowFromData(data))
row = self.rowCount() - 1
Expand Down Expand Up @@ -303,7 +303,7 @@ def __init__(self, parent, editable=False):
QApplication.translate("DBManagerPlugin", 'Column(s)')], editable, parent)

def append(self, idx):
field_names = map(lambda k_v1: unicode(k_v1[1].name), iter(idx.fields().items()))
field_names = [unicode(k_v1[1].name) for k_v1 in iter(list(idx.fields().items()))]
data = [idx.name, u", ".join(field_names)]
self.appendRow(self.rowFromData(data))
row = self.rowCount() - 1
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_plugins/oracle/QtSqlDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

from PyQt.QtCore import QVariant, QDate, QTime, QDateTime, QByteArray
from PyQt4.QtSql import QSqlDatabase, QSqlQuery, QSqlField
from PyQt.QtSql import QSqlDatabase, QSqlQuery, QSqlField

paramstyle = "qmark"
threadsafety = 1
Expand Down
26 changes: 8 additions & 18 deletions python/plugins/db_manager/db_plugins/oracle/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

from PyQt.QtCore import QPyNullVariant
from PyQt4.QtSql import QSqlDatabase
from PyQt.QtSql import QSqlDatabase

from ..connector import DBConnector
from ..plugin import ConnectionError, DbError, Table
Expand Down Expand Up @@ -101,8 +101,7 @@ def __init__(self, uri, connName):
if (os.path.isfile(sqlite_cache_file)):
try:
self.cache_connection = sqlite3.connect(sqlite_cache_file)
except sqlite3.Error as e:

except sqlite3.Error:
self.cache_connection = False

# Find if there is cache for our connection:
Expand All @@ -117,7 +116,7 @@ def __init__(self, uri, connName):
if not has_cached:
self.cache_connection = False

except sqlite3.Error as e:
except sqlite3.Error:
self.cache_connection = False

self._checkSpatial()
Expand Down Expand Up @@ -766,7 +765,7 @@ def getTableGeomTypes(self, table, geomCol):

try:
c = self._execute(None, query)
except DbError as e: # handle error views or other problems
except DbError: # handle error views or other problems
return [QGis.WKBUnknown], [-1]

rows = self._fetchall(c)
Expand Down Expand Up @@ -1071,7 +1070,7 @@ def getTableExtent(self, table, geom):

try:
c = self._execute(None, sql)
except DbError as e: # no spatial index on table, try aggregation
except DbError: # no spatial index on table, try aggregation
return None

res = self._fetchone(c)
Expand Down Expand Up @@ -1106,7 +1105,7 @@ def getTableEstimatedExtent(self, table, geom):
sql = request.format(where, dimension)
try:
c = self._execute(None, sql)
except DbError as e: # no statistics for the current table
except DbError: # no statistics for the current table
return None

res_d = self._fetchone(c)
Expand Down Expand Up @@ -1160,7 +1159,7 @@ def getSpatialRefInfo(self, srid):
None,
(u"SELECT CS_NAME FROM MDSYS.CS_SRS WHERE"
u" SRID = {}".format(srid)))
except DbError as e:
except DbError:
return
sr = self._fetchone(c)
c.close()
Expand Down Expand Up @@ -1212,8 +1211,6 @@ def deleteTable(self, table):
"""Delete table and its reference in sdo_geom_metadata."""

schema, tablename = self.getSchemaTableName(table)
schema_part = u"AND owner = {} ".format(
self.quoteString(schema)) if schema else ""

if self.isVectorTable(table):
self.deleteMetadata(table)
Expand Down Expand Up @@ -1283,8 +1280,6 @@ def createSpatialView(self, view, query):
def deleteView(self, view):
"""Delete a view."""
schema, tablename = self.getSchemaTableName(view)
schema_part = u"AND owner = {} ".format(
self.quoteString(schema)) if schema else ""

if self.isVectorTable(view):
self.deleteMetadata(view)
Expand Down Expand Up @@ -1645,7 +1640,7 @@ def _close_cursor(self, c):
if c:
c.close()

except self.error_types() as e:
except self.error_types():
pass

return
Expand Down Expand Up @@ -1682,11 +1677,6 @@ def _close_cursor(self, c):
# def _get_cursor_columns(self, c):
# pass

def getQueryBuilderDictionary(self):
from .sql_dictionary import getQueryBuilderDictionary

return getQueryBuilderDictionary()

def getSqlDictionary(self):
"""Returns the dictionary for SQL dialog."""
from .sql_dictionary import getSqlDictionary
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_plugins/oracle/info_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def generalInfo(self):
# primary key defined?
if (not self.table.isView
and self.table.objectType != u"MATERIALIZED VIEW"):
pk = filter(lambda fld: fld.primaryKey, self.table.fields())
pk = [fld for fld in self.table.fields() if fld.primaryKey]
if len(pk) <= 0:
ret.append(
HtmlParagraph(QApplication.translate(
Expand Down
17 changes: 6 additions & 11 deletions python/plugins/db_manager/db_plugins/oracle/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

from qgis.core import QgsCredentials

from . import resources_rc
from . import resources_rc # NOQA


def classFactory():
Expand Down Expand Up @@ -91,12 +91,7 @@ def connect(self, parent=None):
uri = QgsDataSourceURI()

settingsList = ["host", "port", "database", "username", "password"]
host, port, database, username, password = map(
lambda x: settings.value(x, "", type=str), settingsList)

# qgis1.5 use 'savePassword' instead of 'save' setting
savedPassword = settings.value("save", False, type=bool) or \
settings.value("savePassword", False, type=bool)
host, port, database, username, password = [settings.value(x, "", type=str) for x in settingsList]

# get all of the connexion options

Expand Down Expand Up @@ -348,14 +343,14 @@ def runAction(self, action):
QApplication.setOverrideCursor(Qt.WaitCursor)

if index_action == "rebuild":
self.emitAboutToChange()
self.aboutToChange.emit()
self.database().connector.rebuildTableIndex(
(self.schemaName(), self.name), index_name)
self.refreshIndexes()
return True
elif action.startswith(u"mview/"):
if action == "mview/refresh":
self.emitAboutToChange()
self.aboutToChange.emit()
self.database().connector.refreshMView(
(self.schemaName(), self.name))
return True
Expand Down Expand Up @@ -391,7 +386,7 @@ def getValidQGisUniqueFields(self, onlyOne=False):
ret = []

# add the pk
pkcols = filter(lambda x: x.primaryKey, self.fields())
pkcols = [x for x in self.fields() if x.primaryKey]
if len(pkcols) == 1:
ret.append(pkcols[0])

Expand Down Expand Up @@ -452,7 +447,7 @@ def info(self):
def runAction(self, action):
if action.startswith("extent/"):
if action == "extent/update":
self.emitAboutToChange()
self.aboutToChange.emit()
self.updateExtent()
return True

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/db_plugins/oracle/sql_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ def getSqlDictionary(spatial=True):
def getQueryBuilderDictionary():
# concat functions
def ff(l):
return filter(lambda s: s[0] != '*', l)
return [s for s in l if s[0] != '*']

def add_paren(l):
return map(lambda s: s + "(", l)
return [s + "(" for s in l]

foo = sorted(
add_paren(
Expand Down
Loading

0 comments on commit c55f8b7

Please sign in to comment.