From b6a9a928dd32ac6ad46b8d012a688deee14e4356 Mon Sep 17 00:00:00 2001 From: Lev Lybin Date: Mon, 24 Sep 2018 22:56:32 +0700 Subject: [PATCH] 1. grouping messages in sentry: https://www.python.org/dev/peps/pep-0282/ 2. also correction https://www.python.org/dev/peps/pep-0008/#indentation --- .../management/commands/cities_light.py | 31 ++++++++++--------- .../commands/cities_light_fixtures.py | 3 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cities_light/management/commands/cities_light.py b/cities_light/management/commands/cities_light.py index 887294da..66418aba 100644 --- a/cities_light/management/commands/cities_light.py +++ b/cities_light/management/commands/cities_light.py @@ -136,7 +136,7 @@ def handle(self, *args, **options): self._clear_identity_maps() if not os.path.exists(DATA_DIR): - self.logger.info('Creating %s' % DATA_DIR) + self.logger.info('Creating %s', DATA_DIR) os.mkdir(DATA_DIR) install_file_path = os.path.join(DATA_DIR, 'install_datetime') @@ -180,20 +180,21 @@ def handle(self, *args, **options): force_import = True 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) + 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) force_import = True if downloaded or force_import: - self.logger.info('Importing %s' % destination_file_name) + self.logger.info('Importing %s', destination_file_name) if url in TRANSLATION_SOURCES: if options.get('hack_translations', False): if os.path.exists(translation_hack_path): self.logger.debug( - 'Using translation parsed data: %s' % + 'Using translation parsed data: %s', translation_hack_path) continue @@ -577,12 +578,12 @@ 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)) - self.region_ids = set(Region.objects.values_list('geoname_id', - flat=True)) - self.city_ids = set(City.objects.values_list('geoname_id', - flat=True)) + self.country_ids = set(Country.objects.values_list( + 'geoname_id', flat=True)) + self.region_ids = set(Region.objects.values_list( + 'geoname_id', flat=True)) + self.city_ids = set(City.objects.values_list( + 'geoname_id', flat=True)) self.translation_data = collections.OrderedDict(( (Country, {}), @@ -683,7 +684,7 @@ def translation_import(self): def save(self, model, force_insert=False, force_update=False): try: with transaction.atomic(): - self.logger.debug('Saving %s' % model.name) + self.logger.debug('Saving %s', model.name) model.save( force_insert=force_insert, force_update=force_update @@ -691,4 +692,4 @@ def save(self, model, force_insert=False, force_update=False): except IntegrityError as e: # Regarding %r see the https://code.djangoproject.com/ticket/20572 # Also related to http://bugs.python.org/issue2517 - self.logger.warning('Saving %s failed: %r' % (model, e)) + self.logger.warning('Saving %s failed: %r', model, e) diff --git a/cities_light/management/commands/cities_light_fixtures.py b/cities_light/management/commands/cities_light_fixtures.py index 6e845661..10f06602 100644 --- a/cities_light/management/commands/cities_light_fixtures.py +++ b/cities_light/management/commands/cities_light_fixtures.py @@ -59,7 +59,8 @@ def create_parser(self, *args, **kwargs): parser.formatter_class = RawTextHelpFormatter return parser - def add_arguments(self, parser): + @staticmethod + def add_arguments(parser): parser.add_argument( 'subcommand', type=str,