more formatting fixes

Found by flake8.
This commit is contained in:
Sarah Hoffmann
2021-07-12 17:45:42 +02:00
parent b4fec57b6d
commit cf98cff2a1
21 changed files with 62 additions and 53 deletions

View File

@@ -103,7 +103,7 @@ class CommandlineParser:
return 1
##### Subcommand classes
# Subcommand classes
#
# Each class needs to implement two functions: add_args() adds the CLI parameters
# for the subfunction, run() executes the subcommand.

View File

@@ -61,7 +61,7 @@ class UpdateRefresh:
args.threads or 1)
indexer.index_postcodes()
else:
LOG.error("The place table doesn\'t exist. " \
LOG.error("The place table doesn't exist. "
"Postcode updates on a frozen database is not possible.")
if args.word_counts:

View File

@@ -24,6 +24,7 @@ def _check(hint=None):
"""
def decorator(func):
title = func.__doc__.split('\n', 1)[0].strip()
def run_check(conn, config):
print(title, end=' ... ')
ret = func(conn, config)
@@ -98,13 +99,12 @@ def _get_indexes(conn):
if conn.table_exists('place'):
indexes.extend(('idx_placex_pendingsector',
'idx_location_area_country_place_id',
'idx_place_osm_unique'
))
'idx_place_osm_unique'))
return indexes
### CHECK FUNCTIONS
# CHECK FUNCTIONS
#
# Functions are exectured in the order they appear here.

View File

@@ -184,8 +184,10 @@ def truncate_data_tables(conn):
conn.commit()
_COPY_COLUMNS = 'osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry'
def load_data(dsn, threads):
""" Copy data into the word and placex table.
"""
@@ -250,6 +252,7 @@ def create_search_indices(conn, config, drop=False):
sql.run_sql_file(conn, 'indices.sql', drop=drop)
def create_country_names(conn, tokenizer, languages=None):
""" Add default country names to search index. `languages` is a comma-
separated list of language codes as used in OSM. If `languages` is not
@@ -261,8 +264,7 @@ def create_country_names(conn, tokenizer, languages=None):
def _include_key(key):
return key == 'name' or \
(key.startswith('name:') \
and (not languages or key[5:] in languages))
(key.startswith('name:') and (not languages or key[5:] in languages))
with conn.cursor() as cur:
psycopg2.extras.register_hstore(cur)

View File

@@ -142,7 +142,8 @@ def change_housenumber_transliteration(conn, **_):
BEGIN
SELECT array_to_string(array_agg(trans), ';')
INTO normtext
FROM (SELECT lookup_word as trans, getorcreate_housenumber_id(lookup_word)
FROM (SELECT lookup_word as trans,
getorcreate_housenumber_id(lookup_word)
FROM (SELECT make_standard_name(h) as lookup_word
FROM regexp_split_to_table(housenumber, '[,;]') h) x) y;
return normtext;

View File

@@ -166,10 +166,13 @@ def update_postcodes(dsn, project_dir, tokenizer):
cur.execute("""
SELECT cc as country_code, pc, ST_X(centroid), ST_Y(centroid)
FROM (SELECT
COALESCE(plx.country_code, get_country_code(ST_Centroid(pl.geometry))) as cc,
COALESCE(plx.country_code,
get_country_code(ST_Centroid(pl.geometry))) as cc,
token_normalized_postcode(pl.address->'postcode') as pc,
ST_Centroid(ST_Collect(COALESCE(plx.centroid, ST_Centroid(pl.geometry)))) as centroid
FROM place AS pl LEFT OUTER JOIN placex AS plx ON pl.osm_id = plx.osm_id AND pl.osm_type = plx.osm_type
ST_Centroid(ST_Collect(COALESCE(plx.centroid,
ST_Centroid(pl.geometry)))) as centroid
FROM place AS pl LEFT OUTER JOIN placex AS plx
ON pl.osm_id = plx.osm_id AND pl.osm_type = plx.osm_type
WHERE pl.address ? 'postcode' AND pl.geometry IS NOT null
GROUP BY cc, pc) xx
WHERE pc IS NOT null AND cc IS NOT null

View File

@@ -174,10 +174,10 @@ class SPImporter():
if table_name in self.table_phrases_to_delete:
self.statistics_handler.notify_one_table_ignored()
#Remove this table from the ones to delete as it match a class/type
#still existing on the special phrases of the wiki.
# Remove this table from the ones to delete as it match a
# class/type still existing on the special phrases of the wiki.
self.table_phrases_to_delete.remove(table_name)
#So dont need to create the table and indexes.
# So don't need to create the table and indexes.
continue
# Table creation
@@ -248,10 +248,12 @@ class SPImporter():
Delete the place_classtype tables.
"""
LOG.warning('Cleaning database...')
#Array containing all queries to execute. Contain tuples of format (query, parameters)
# Array containing all queries to execute.
# Contains tuples of format (query, parameters)
queries_parameters = []
#Delete place_classtype tables corresponding to class/type which are not on the wiki anymore
# Delete place_classtype tables corresponding to class/type which
# are not on the wiki anymore.
for table in self.table_phrases_to_delete:
self.statistics_handler.notify_one_table_deleted()
query = SQL('DROP TABLE IF EXISTS {}').format(Identifier(table))

View File

@@ -65,5 +65,6 @@ class SPWikiLoader(Iterator):
Requested URL Example :
https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/EN
"""
url = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/' + lang.upper() # pylint: disable=line-too-long
url = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/' \
+ lang.upper()
return get_url(url)