Skip to content

Commit

Permalink
PEP8 & fix for #215
Browse files Browse the repository at this point in the history
  • Loading branch information
marianoeramirez committed Apr 17, 2020
1 parent 5beaa8a commit 6dfcd3c
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions cities_light/management/commands/cities_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from argparse import RawTextHelpFormatter
import sys

if sys.platform != 'win32':
import resource

Expand Down Expand Up @@ -72,33 +73,33 @@ def create_parser(self, *args, **kwargs):

def add_arguments(self, parser):
parser.add_argument('--force-import-all', action='store_true',
default=False, help='Import even if files are up-to-date.'
),
default=False, help='Import even if files are up-to-date.'
),
parser.add_argument('--force-all', action='store_true', default=False,
help='Download and import if files are up-to-date.'
),
help='Download and import if files are up-to-date.'
),
parser.add_argument('--force-import', action='append', default=[],
help='Import even if files matching files are up-to-date'
),
help='Import even if files matching files are up-to-date'
),
parser.add_argument('--force', action='append', default=[],
help='Download and import even if matching files are up-to-date'
),
help='Download and import even if matching files are up-to-date'
),
parser.add_argument('--noinsert', action='store_true',
default=False,
help='Update existing data only'
),
default=False,
help='Update existing data only'
),
parser.add_argument('--hack-translations', action='store_true',
default=False,
help='Set this if you intend to import translations a lot'
),
default=False,
help='Set this if you intend to import translations a lot'
),
parser.add_argument('--keep-slugs', action='store_true',
default=False,
help='Do not update slugs'
),
default=False,
help='Do not update slugs'
),
parser.add_argument('--progress', action='store_true',
default=False,
help='Show progress bar'
),
default=False,
help='Show progress bar'
),

def progress_init(self):
"""Initialize progress bar."""
Expand Down Expand Up @@ -181,9 +182,9 @@ def handle(self, *args, **options):

if not os.path.exists(install_file_path):
self.logger.info('Forced import of %s because data do not seem'
' to have installed successfuly yet, note that this is'
' equivalent to --force-import-all.' %
destination_file_name)
' to have installed successfuly yet, note that this is'
' equivalent to --force-import-all.' %
destination_file_name)
force_import = True

if downloaded or force_import:
Expand Down Expand Up @@ -283,7 +284,7 @@ def _get_subregion_id(self, country_code2, region_id, subregion_id):
if subregion_id not in self._subregion_codes[country_id]:
self._subregion_codes[country_id][subregion_id] = \
SubRegion.objects.get(
country_id=country_id, geoname_code=subregion_id).pk
country_id=country_id, geoname_code=subregion_id).pk
return self._subregion_codes[country_id][subregion_id]

def country_import(self, items):
Expand All @@ -292,9 +293,10 @@ def country_import(self, items):
except InvalidItems:
return

force_insert = False
force_update = False
try:
force_insert = False
force_update = False

country = Country.objects.get(geoname_id=items[ICountry.geonameid])
force_update = True
except Country.DoesNotExist:
Expand Down Expand Up @@ -335,9 +337,9 @@ def region_import(self, items):
except InvalidItems:
return

force_insert = False
force_update = False
try:
force_insert = False
force_update = False
region = Region.objects.get(geoname_id=items[IRegion.geonameid])
force_update = True
except Region.DoesNotExist:
Expand Down Expand Up @@ -392,8 +394,8 @@ def subregion_import(self, items):
except InvalidItems:
return

force_insert = force_update = False
try:
force_insert = force_update = False
subregion = SubRegion.objects.filter(
geoname_id=items[ISubRegion.geonameid]).first()
if subregion:
Expand Down Expand Up @@ -470,9 +472,9 @@ def city_import(self, items):
except InvalidItems:
return

force_insert = False
force_update = False
try:
force_insert = False
force_update = False
city = City.objects.get(geoname_id=items[ICity.geonameid])
force_update = True
except City.DoesNotExist:
Expand Down Expand Up @@ -503,7 +505,7 @@ def city_import(self, items):
items[ICity.admin1Code],
items[ICity.admin2Code]
)
except SubRegion.DoesNotExist:
except (SubRegion.DoesNotExist, Region.DoesNotExist):
subregion_id = None

save = False
Expand Down Expand Up @@ -578,11 +580,11 @@ def city_import(self, items):
def translation_parse(self, items):
if not hasattr(self, 'translation_data'):
self.country_ids = set(Country.objects.values_list('geoname_id',
flat=True))
flat=True))
self.region_ids = set(Region.objects.values_list('geoname_id',
flat=True))
flat=True))
self.city_ids = set(City.objects.values_list('geoname_id',
flat=True))
flat=True))

self.translation_data = collections.OrderedDict((
(Country, {}),
Expand Down

0 comments on commit 6dfcd3c

Please sign in to comment.