Skip to content
Permalink
Browse files

Code style

  • Loading branch information
m-kuhn committed May 5, 2020
1 parent f9f5a94 commit a7e0831dcf1d4b8faa14212b3da364a10b56a802
@@ -69,7 +69,7 @@ def __init__(self, connection, sql=None):
self.result = None
self.cursor = 0
self.closed = False
if (self.sql != None):
if (self.sql is not None):
self._execute()

def _toStrResultSet(self, res):
@@ -87,11 +87,11 @@ def _toStrResultSet(self, res):
return newres

def _execute(self, sql=None):
if self.sql == sql and self.result != None:
if self.sql == sql and self.result is not None:
return
if (sql != None):
if (sql is not None):
self.sql = sql
if (self.sql == None):
if (self.sql is None):
return
self._debug("execute called with sql " + self.sql)
try:
@@ -1155,7 +1155,7 @@ def connection_error_types(self):
return psycopg2.InterfaceError, psycopg2.OperationalError

def _execute(self, cursor, sql):
if cursor != None:
if cursor is not None:
cursor._execute(sql)
return cursor
return CursorAdapter(self.core_connection, sql)
@@ -45,7 +45,7 @@ def setUpClass(self):
self.old_pgdatabase_env = os.environ.get('PGDATABASE')
# QGIS_PGTEST_DB contains the full connection string and not only the DB name!
QGIS_PGTEST_DB = os.environ.get('QGIS_PGTEST_DB')
if not QGIS_PGTEST_DB is None:
if QGIS_PGTEST_DB is not None:
test_uri = QgsDataSourceUri(QGIS_PGTEST_DB)
self.testdb = test_uri.database()
else:
@@ -190,7 +190,7 @@ def preprocessParameters(self, parameters):
#- metadata with 'group_key' and 'group_key' is a valid parameter and it's value == metadata()['group_value']
if 'group_key' in param.metadata() and not param.metadata()['group_key'] in parameters:
valid_params[k] = v
elif not 'group_key' in param.metadata() or parameters[param.metadata()['group_key']] == param.metadata()['group_value']:
elif 'group_key' not in param.metadata() or parameters[param.metadata()['group_key']] == param.metadata()['group_value']:
valid_params[k] = v

return valid_params
@@ -96,7 +96,7 @@ def __setWrapperVisibility(self, wrapper, v):

def updateAllParameters(self, current_value):
for parameter in self.get_algorithm().parameterDefinitions():
if not 'group_key' in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
if 'group_key' not in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
continue
name = parameter.name()
choice_key = parameter.metadata()['group_key']
@@ -105,7 +105,7 @@ def updateAllParameters(self, current_value):
if current_value is None:
current_value = choice_param.defaultValue()
pattern = "{}.{}.".format(choice_key, choice_param.getValueAsText(current_value))
if not pattern in name:
if pattern not in name:
flags = self.get_algorithm().parameterDefinition(name).flags()
if not flags & QgsProcessingParameterDefinition.FlagOptional:
self.flagsModified[name] = True
@@ -131,7 +131,7 @@ def postInitialize(self, wrappers):
# return
self.updateAllParameters(current_value=None)
for parameter in self.get_algorithm().parameterDefinitions():
if not 'group_key' in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
if 'group_key' not in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
continue
for wrapper in wrappers:
if wrapper.param.name() == parameter.name():
@@ -162,7 +162,7 @@ def __init__(self, name='', description='', options=[], default=None, isSource=F
self.value = self.default

def getValueAsText(self, value):
if not value in self.options:
if value not in self.options:
value = self.options[int(value)]
return value

@@ -219,10 +219,10 @@ def renderSingleMetatile(self, metatile):
job.renderSynchronously()
painter.end()

## For analysing metatiles (labels, etc.)
## metatile_dir = os.path.join(output_dir, str(zoom))
## os.makedirs(metatile_dir, exist_ok=True)
## image.save(os.path.join(metatile_dir, 'metatile_%s.png' % i))
# For analysing metatiles (labels, etc.)
# metatile_dir = os.path.join(output_dir, str(zoom))
# os.makedirs(metatile_dir, exist_ok=True)
# image.save(os.path.join(metatile_dir, 'metatile_%s.png' % i))

for r, c, tile in metatile.tiles:
tileImage = image.copy(self.tile_width * r, self.tile_height * c, self.tile_width, self.tile_height)
@@ -270,7 +270,7 @@ def generate(self, writer, parameters, context, feedback):
if self.tile_format == 'PNG':
self.settingsDictionary[thread].setBackgroundColor(self.color)

## disable partial labels (they would be cut at the edge of tiles)
# disable partial labels (they would be cut at the edge of tiles)
labeling_engine_settings = self.settingsDictionary[thread].labelingEngineSettings()
labeling_engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, False)
self.settingsDictionary[thread].setLabelingEngineSettings(labeling_engine_settings)
@@ -89,7 +89,7 @@ def processAlgorithm(self, parameters, context, feedback):
directory = self.parameterAsString(parameters, self.OUTPUT, context)

output_format = context.preferredVectorFormat()
if not output_format in QgsVectorFileWriter.supportedFormatExtensions():
if output_format not in QgsVectorFileWriter.supportedFormatExtensions():
# fallback to gpkg if preferred format is not available
output_format = 'gpkg'

@@ -153,7 +153,7 @@ def getParameterFromString(s, context=''):
params[3] = True if params[3].lower() == 'true' else False
if len(params) > 4:
# For multiple values; default value is a list of int
if params[3] == True:
if params[3] is True:
params[4] = [int(v) for v in params[4].split(',')] if params[4] is not None else None
else:
params[4] = int(params[4]) if params[4] is not None else None
@@ -291,7 +291,7 @@ def execute_in_place(alg, parameters, context=None, feedback=None):
if context is None:
context = dataobjects.createContext(feedback)

if not 'INPUT' in parameters or not parameters['INPUT']:
if 'INPUT' not in parameters or not parameters['INPUT']:
parameters['INPUT'] = iface.activeLayer()
ok, results = execute_in_place_run(alg, parameters, context=context, feedback=feedback)
if ok:
@@ -190,7 +190,7 @@ def fillTreeUsingProviders(self):
emptyItem.setEditable(False)

rootItem.insertRow(0, [groupItem, emptyItem])
if not group in settings:
if group not in settings:
continue

# add menu item only if it has any search matches
@@ -113,7 +113,7 @@ def check_algorithm(self, name, defs):
parameters[k] = p

for r, p in list(defs['results'].items()):
if not 'in_place_result' in p or not p['in_place_result']:
if 'in_place_result' not in p or not p['in_place_result']:
parameters[r] = self.load_result_param(p)

expectFailure = False
@@ -448,7 +448,7 @@ def _unloadPluginModules(packageName):
mods = _plugin_modules[packageName]

for mod in mods:
if not mod in sys.modules:
if mod not in sys.modules:
continue

# if it looks like a Qt resource file, try to do a cleanup

0 comments on commit a7e0831

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