def run(): image_urls = list(Image.objects.values_list('file', flat=True)) progress = Progress(len(image_urls), 100) progress.draw() for path in image_urls: url = BASE_URL + '/' + path try: os.makedirs(os.path.dirname(path)) except OSError as e: if e.errno != 17: raise e try: urllib.urlretrieve(url, path) except urllib.ContentTooShortError: print "Couldn't download", path progress.tick() print '\nDone'