coderholic / django-cities

Countries and cities of the world for Django projects
MIT License
921 stars 375 forks source link

Add tqdm progress bars #111

Closed blag closed 8 years ago

blag commented 8 years ago

Use tqdm to show progress bars when performing long operations, like importing each type of data and flushing alternative names for each model.

Also includes PEP-8 fixes for touched files.

The weird

data = self.get_data('...')

total = sum(1 for _ in data)

data = self.get_data('...')

is due to the fact that get_data() returns a generator instead of a list, so by the time the total is calculated the generator is reading the end of the file (so it must be reset). The get_data() function can be updated to calculate the total itself and return a (total, <generator>) tuple instead, which would make the syntax much more readable and prevent the generator from being created twice during every import. I left this change out to ease review of this PR, and I'll probably fix this in a future PR if nobody else gets to it first.

blag commented 8 years ago

Let me know if there's anything I can do to push this PR forward - I have other commits stacked up that build on this that I'd like to get merged.

coderholic commented 8 years ago

This looks great.Merged!