Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __call__(self, tile):
if tile is None:
logger.warning("The tile is None")
return None
if tile.error:
action = 'error'
elif tile.data:
action = 'create'
else:
action = 'delete'
layer = tile.metadata.get('layer', '- No layer -')
run = tile.metadata.get('run', -1)
with stats.timer_context(['db_logger', 'insert']):
with self.connection.cursor() as cursor:
try:
cursor.execute(
'INSERT INTO {} (layer, run, action, tile) '
'VALUES (%(layer)s, %(run)s, %(action)s::varchar(7), %(tile)s)'.
format(self.full_table),
{'layer': layer, 'action': action, 'tile': str(tile.tilecoord), 'run': run}
)
except psycopg2.IntegrityError:
self.connection.rollback()
cursor.execute(
'UPDATE {} SET action = %(action)s '
'WHERE layer = %(layer)s AND run = %(run)s AND tile = %(tile)s'.
format(self.full_table),
{'layer': layer, 'action': action, 'tile': str(tile.tilecoord), 'run': run}
)
def get_status(gene):
store = get_queue_store(gene.config, False)
kind = 'redis' if 'redis' in gene.config else 'sqs'
stats_prefix = [kind, gene.config[kind]['queue']]
with stats.timer_context(stats_prefix + ['get_stats']):
status = store.get_status()
return [name + ': ' + str(value) for name, value in status.items()]
def put_one(self, tile):
with stats.timer_context(self._get_stats_name('put_one', tile)):
return self._tile_store.put_one(tile)
def __len__(self):
with stats.timer_context(self._get_stats_name('len')):
return self._tile_store.__len__()
def get_one(self, tile):
with stats.timer_context(self._get_stats_name('get_one', tile)):
return self._tile_store.get_one(tile)
def delete_one(self, tile):
with stats.timer_context(self._get_stats_name('delete_one', tile)):
return self._tile_store.delete_one(tile)
self._layers_geoms[layer['name']] = layer_geoms
if extent:
geom = Polygon((
(extent[0], extent[1]),
(extent[0], extent[3]),
(extent[2], extent[3]),
(extent[2], extent[1]),
))
for z, r in enumerate(layer['grid_ref']['resolutions']):
layer_geoms[z] = geom
if self.options is None or (
self.options.near is None and self.options.geom
):
for g in layer['geoms']:
with stats.timer_context(['geoms_get', layer['name']]):
connection = psycopg2.connect(g['connection'])
cursor = connection.cursor()
sql = 'SELECT ST_AsBinary(geom) FROM (SELECT {}) AS g'.format(g['sql'])
logger.info('Execute SQL: {}.'.format(sql))
cursor.execute(sql)
geoms = [loads_wkb(bytes(r[0])) for r in cursor.fetchall()]
geom = cascaded_union(geoms)
if extent:
geom = geom.intersection(Polygon((
(extent[0], extent[1]),
(extent[0], extent[3]),
(extent[2], extent[3]),
(extent[2], extent[1]),
)))
for z, r in enumerate(layer['grid_ref']['resolutions']):
if ('min_resolution' not in g or g['min_resolution'] <= r) and \