Skip to content

Commit c55f8b7

Browse files
committedMar 21, 2016
db_manager: cleanups
1 parent d25c253 commit c55f8b7

34 files changed

+141
-157
lines changed
 

‎python/plugins/db_manager/db_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import functools
2626

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

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

216216
if callback is not None:
217-
invoke_callback = lambda x: self.invokeCallback(callback)
217+
def invoke_callback(x):
218+
return self.invokeCallback(callback)
218219

219220
if menuName is None or menuName == "":
220221
self.addAction(action)

‎python/plugins/db_manager/db_manager_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
***************************************************************************/
2121
"""
2222

23-
from PyQt.QtCore import Qt, QObject
23+
from PyQt.QtCore import Qt
2424
from PyQt.QtWidgets import QAction, QApplication
2525
from PyQt.QtGui import QIcon
2626

27-
from . import resources_rc
27+
from . import resources_rc # NOQA
2828

2929

3030
class DBManagerPlugin:

‎python/plugins/db_manager/db_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

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

33-
from . import resources_rc
33+
from . import resources_rc # NOQA
3434

3535
try:
36-
from qgis.core import QgsVectorLayerImport
36+
from qgis.core import QgsVectorLayerImport # NOQA
3737
isImportVectorAvail = True
3838
except:
3939
isImportVectorAvail = False
@@ -491,7 +491,7 @@ def _refreshIndex(self, index, force=False):
491491
else:
492492
self.notPopulated.emit(index)
493493

494-
except BaseError as e:
494+
except BaseError:
495495
item.populated = False
496496
return
497497

‎python/plugins/db_manager/db_plugins/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def initDbPluginList():
4242
continue
4343

4444
try:
45-
exec (u"from .%s import plugin as mod" % name, globals())
45+
exec(u"from .%s import plugin as mod" % name, globals())
4646
except ImportError as e:
4747
DBPLUGIN_ERRORS.append(u"%s: %s" % (name, unicode(e)))
4848
continue
4949

50-
pluginclass = mod.classFactory()
50+
pluginclass = mod.classFactory() # NOQA
5151
SUPPORTED_DBTYPES[pluginclass.typeName()] = pluginclass
5252

5353
return len(SUPPORTED_DBTYPES) > 0

‎python/plugins/db_manager/db_plugins/connector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _close_cursor(self, c):
112112
if c and not c.closed:
113113
c.close()
114114

115-
except self.error_types() as e:
115+
except self.error_types():
116116
pass
117117

118118
return
@@ -168,9 +168,9 @@ def _rollback(self):
168168
def _get_cursor_columns(self, c):
169169
try:
170170
if c.description:
171-
return map(lambda x: x[0], c.description)
171+
return [x[0] for x in c.description]
172172

173-
except self.connection_error_types() + self.execution_error_types() as e:
173+
except self.connection_error_types() + self.execution_error_types():
174174
return []
175175

176176
@classmethod

‎python/plugins/db_manager/db_plugins/data_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def data(self, index, role):
7878
# too much data to display, elide the string
7979
val = val[:300]
8080
try:
81-
return unicode(val) # convert to unicode
81+
return unicode(val) # convert to unicode
8282
except UnicodeDecodeError:
83-
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)
83+
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)
8484

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

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

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

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

305305
def append(self, idx):
306-
field_names = map(lambda k_v1: unicode(k_v1[1].name), iter(idx.fields().items()))
306+
field_names = [unicode(k_v1[1].name) for k_v1 in iter(list(idx.fields().items()))]
307307
data = [idx.name, u", ".join(field_names)]
308308
self.appendRow(self.rowFromData(data))
309309
row = self.rowCount() - 1

‎python/plugins/db_manager/db_plugins/oracle/QtSqlDB.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"""
2222

2323
from PyQt.QtCore import QVariant, QDate, QTime, QDateTime, QByteArray
24-
from PyQt4.QtSql import QSqlDatabase, QSqlQuery, QSqlField
24+
from PyQt.QtSql import QSqlDatabase, QSqlQuery, QSqlField
2525

2626
paramstyle = "qmark"
2727
threadsafety = 1

‎python/plugins/db_manager/db_plugins/oracle/connector.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""
2525

2626
from PyQt.QtCore import QPyNullVariant
27-
from PyQt4.QtSql import QSqlDatabase
27+
from PyQt.QtSql import QSqlDatabase
2828

2929
from ..connector import DBConnector
3030
from ..plugin import ConnectionError, DbError, Table
@@ -101,8 +101,7 @@ def __init__(self, uri, connName):
101101
if (os.path.isfile(sqlite_cache_file)):
102102
try:
103103
self.cache_connection = sqlite3.connect(sqlite_cache_file)
104-
except sqlite3.Error as e:
105-
104+
except sqlite3.Error:
106105
self.cache_connection = False
107106

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

120-
except sqlite3.Error as e:
119+
except sqlite3.Error:
121120
self.cache_connection = False
122121

123122
self._checkSpatial()
@@ -766,7 +765,7 @@ def getTableGeomTypes(self, table, geomCol):
766765

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

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

10721071
try:
10731072
c = self._execute(None, sql)
1074-
except DbError as e: # no spatial index on table, try aggregation
1073+
except DbError: # no spatial index on table, try aggregation
10751074
return None
10761075

10771076
res = self._fetchone(c)
@@ -1106,7 +1105,7 @@ def getTableEstimatedExtent(self, table, geom):
11061105
sql = request.format(where, dimension)
11071106
try:
11081107
c = self._execute(None, sql)
1109-
except DbError as e: # no statistics for the current table
1108+
except DbError: # no statistics for the current table
11101109
return None
11111110

11121111
res_d = self._fetchone(c)
@@ -1160,7 +1159,7 @@ def getSpatialRefInfo(self, srid):
11601159
None,
11611160
(u"SELECT CS_NAME FROM MDSYS.CS_SRS WHERE"
11621161
u" SRID = {}".format(srid)))
1163-
except DbError as e:
1162+
except DbError:
11641163
return
11651164
sr = self._fetchone(c)
11661165
c.close()
@@ -1212,8 +1211,6 @@ def deleteTable(self, table):
12121211
"""Delete table and its reference in sdo_geom_metadata."""
12131212

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

12181215
if self.isVectorTable(table):
12191216
self.deleteMetadata(table)
@@ -1283,8 +1280,6 @@ def createSpatialView(self, view, query):
12831280
def deleteView(self, view):
12841281
"""Delete a view."""
12851282
schema, tablename = self.getSchemaTableName(view)
1286-
schema_part = u"AND owner = {} ".format(
1287-
self.quoteString(schema)) if schema else ""
12881283

12891284
if self.isVectorTable(view):
12901285
self.deleteMetadata(view)
@@ -1645,7 +1640,7 @@ def _close_cursor(self, c):
16451640
if c:
16461641
c.close()
16471642

1648-
except self.error_types() as e:
1643+
except self.error_types():
16491644
pass
16501645

16511646
return
@@ -1682,11 +1677,6 @@ def _close_cursor(self, c):
16821677
# def _get_cursor_columns(self, c):
16831678
# pass
16841679

1685-
def getQueryBuilderDictionary(self):
1686-
from .sql_dictionary import getQueryBuilderDictionary
1687-
1688-
return getQueryBuilderDictionary()
1689-
16901680
def getSqlDictionary(self):
16911681
"""Returns the dictionary for SQL dialog."""
16921682
from .sql_dictionary import getSqlDictionary

‎python/plugins/db_manager/db_plugins/oracle/info_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def generalInfo(self):
219219
# primary key defined?
220220
if (not self.table.isView
221221
and self.table.objectType != u"MATERIALIZED VIEW"):
222-
pk = filter(lambda fld: fld.primaryKey, self.table.fields())
222+
pk = [fld for fld in self.table.fields() if fld.primaryKey]
223223
if len(pk) <= 0:
224224
ret.append(
225225
HtmlParagraph(QApplication.translate(

‎python/plugins/db_manager/db_plugins/oracle/plugin.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
from qgis.core import QgsCredentials
4040

41-
from . import resources_rc
41+
from . import resources_rc # NOQA
4242

4343

4444
def classFactory():
@@ -91,12 +91,7 @@ def connect(self, parent=None):
9191
uri = QgsDataSourceURI()
9292

9393
settingsList = ["host", "port", "database", "username", "password"]
94-
host, port, database, username, password = map(
95-
lambda x: settings.value(x, "", type=str), settingsList)
96-
97-
# qgis1.5 use 'savePassword' instead of 'save' setting
98-
savedPassword = settings.value("save", False, type=bool) or \
99-
settings.value("savePassword", False, type=bool)
94+
host, port, database, username, password = [settings.value(x, "", type=str) for x in settingsList]
10095

10196
# get all of the connexion options
10297

@@ -348,14 +343,14 @@ def runAction(self, action):
348343
QApplication.setOverrideCursor(Qt.WaitCursor)
349344

350345
if index_action == "rebuild":
351-
self.emitAboutToChange()
346+
self.aboutToChange.emit()
352347
self.database().connector.rebuildTableIndex(
353348
(self.schemaName(), self.name), index_name)
354349
self.refreshIndexes()
355350
return True
356351
elif action.startswith(u"mview/"):
357352
if action == "mview/refresh":
358-
self.emitAboutToChange()
353+
self.aboutToChange.emit()
359354
self.database().connector.refreshMView(
360355
(self.schemaName(), self.name))
361356
return True
@@ -391,7 +386,7 @@ def getValidQGisUniqueFields(self, onlyOne=False):
391386
ret = []
392387

393388
# add the pk
394-
pkcols = filter(lambda x: x.primaryKey, self.fields())
389+
pkcols = [x for x in self.fields() if x.primaryKey]
395390
if len(pkcols) == 1:
396391
ret.append(pkcols[0])
397392

@@ -452,7 +447,7 @@ def info(self):
452447
def runAction(self, action):
453448
if action.startswith("extent/"):
454449
if action == "extent/update":
455-
self.emitAboutToChange()
450+
self.aboutToChange.emit()
456451
self.updateExtent()
457452
return True
458453

‎python/plugins/db_manager/db_plugins/oracle/sql_dictionary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ def getSqlDictionary(spatial=True):
289289
def getQueryBuilderDictionary():
290290
# concat functions
291291
def ff(l):
292-
return filter(lambda s: s[0] != '*', l)
292+
return [s for s in l if s[0] != '*']
293293

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

297297
foo = sorted(
298298
add_paren(

0 commit comments

Comments
 (0)
Please sign in to comment.