diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-02-02 17:28:25 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-02-02 17:28:25 +0100 | 
| commit | 44242c7775a14a5df3ff1bdff23916f52b908d25 (patch) | |
| tree | ddeb3935c1ab69b2cb564441c822f6559836fabd /ishtar_common/management/commands/import_geofla_csv.py | |
| parent | 3000f31733b40fe8818c9b4299a579b031623e00 (diff) | |
| download | Ishtar-44242c7775a14a5df3ff1bdff23916f52b908d25.tar.bz2 Ishtar-44242c7775a14a5df3ff1bdff23916f52b908d25.zip | |
Quiet version of town imports. Fix test evaluation for the new UI.
Diffstat (limited to 'ishtar_common/management/commands/import_geofla_csv.py')
| -rw-r--r-- | ishtar_common/management/commands/import_geofla_csv.py | 17 | 
1 files changed, 13 insertions, 4 deletions
| diff --git a/ishtar_common/management/commands/import_geofla_csv.py b/ishtar_common/management/commands/import_geofla_csv.py index 7ef0e0a38..3ef5eff1c 100644 --- a/ishtar_common/management/commands/import_geofla_csv.py +++ b/ishtar_common/management/commands/import_geofla_csv.py @@ -34,18 +34,25 @@ class Command(BaseCommand):          parser.add_argument(              '--year', type=int, default=2014, dest='year',              help='Default year to affect to the town') +        parser.add_argument( +            '--quiet', dest='quiet', action='store_true', +            help='Quiet output')      def handle(self, *args, **options):          csv_file = options['csv_file']          default_year = options['year'] -        sys.stdout.write('* using year {} as a default\n'.format(default_year)) -        sys.stdout.write('* Opening file {}\n'.format(csv_file)) +        quiet = options['quiet'] +        if not quiet: +            sys.stdout.write('* using year {} as a default\n'.format( +                default_year)) +            sys.stdout.write('* Opening file {}\n'.format(csv_file))          nb_created, nb_changed = 0, 0          with open(csv_file, 'rb') as csvfile:              reader = csv.DictReader(csvfile)              for idx, row in enumerate(reader): -                sys.stdout.write('Processing town %d.\r' % (idx + 1)) -                sys.stdout.flush() +                if not quiet: +                    sys.stdout.write('Processing town %d.\r' % (idx + 1)) +                    sys.stdout.flush()                  num_insee = row['INSEE_COM']                  if len(num_insee) < 5:                      num_insee = '0' + num_insee @@ -79,6 +86,8 @@ class Command(BaseCommand):                  if not created:                      nb_changed += 1                  town.save() +        if quiet: +            return          sys.stdout.write('\n* {} town created'.format(nb_created))          sys.stdout.write('\n* {} town changed\n'.format(nb_changed))          sys.stdout.flush() | 
