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_insee_comm_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_insee_comm_csv.py')
-rw-r--r-- | ishtar_common/management/commands/import_insee_comm_csv.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/ishtar_common/management/commands/import_insee_comm_csv.py b/ishtar_common/management/commands/import_insee_comm_csv.py index 24eb2013e..d3bbc4a61 100644 --- a/ishtar_common/management/commands/import_insee_comm_csv.py +++ b/ishtar_common/management/commands/import_insee_comm_csv.py @@ -34,12 +34,18 @@ class Command(BaseCommand): parser.add_argument( '--year', type=int, default=2015, dest='year', help='Year to affect to new towns') + 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 {} for new towns\n'.format(default_year)) - sys.stdout.write('* opening file {}\n'.format(csv_file)) + quiet = options['quiet'] + if not quiet: + sys.stdout.write('* using year {} for new towns\n'.format( + default_year)) + sys.stdout.write('* opening file {}\n'.format(csv_file)) r = re.compile(r"(.*)\((.*)\)") nb_created = 0 nb_link = 0 @@ -49,8 +55,9 @@ class Command(BaseCommand): 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() old_insee = row['DepComA'] if len(old_insee) < 5: @@ -86,10 +93,13 @@ class Command(BaseCommand): old_town.children.add(new_town) linked.add(new_town) nb_limit = 0 - sys.stdout.write('\nGenerate limits...'.format(nb_created)) + if not quiet: + sys.stdout.write('\nGenerate limits...'.format(nb_created)) for town in linked: if town.generate_geo(): nb_limit += 1 + if quiet: + return sys.stdout.write('\n* {} town created\n'.format(nb_created)) sys.stdout.write('* {} link created\n'.format(nb_link)) sys.stdout.write('* {} limit generated\n'.format(nb_limit)) |