def regenerate_thumbs(self):
        """
        Handle re-generating the thumbnails. All this involves is reading the
        original file, then saving the same exact thing. Kind of annoying, but
        it's simple.
        """
        Model = self.model
        instances = Model.objects.all()
        num_instances = instances.count()
        # Filenames are keys in here, to help avoid re-genning something that
        # we have already done.
        regen_tracker = {}

        counter = 1
        for instance in instances:
            file = getattr(instance, self.field)
            if not file:
                print "(%d/%d) ID: %d -- Skipped -- No file" % (counter,
                                                                num_instances,
                                                                instance.id)
                counter += 1
                continue

            file_name = os.path.basename(file.name)

            if regen_tracker.has_key(file_name):
                print "(%d/%d) ID: %d -- Skipped -- Already re-genned %s" % (
                                                    counter,
                                                    num_instances,
                                                    instance.id,
                                                    file_name)
                counter += 1
                continue

            # Keep them informed on the progress.
            print "(%d/%d) ID: %d -- %s" % (counter, num_instances,
                                            instance.id, file_name)

            try:
                fdat = file.read()
                file.close()
                del file.file
            except IOError:
                # Key didn't exist.
                print "(%d/%d) ID %d -- Error -- File missing on S3" % (
                                                              counter,
                                                              num_instances,
                                                              instance.id)
                counter += 1
                continue

            try:
                file_contents = ContentFile(fdat)
            except __HOLE__:
                # This field has no file associated with it, skip it.
                print "(%d/%d) ID %d --  Skipped -- No file on field)" % (
                                                              counter,
                                                              num_instances,
                                                              instance.id)
                counter += 1
                continue

            # Saving pumps it back through the thumbnailer, if this is a
            # ThumbnailField. If not, it's still pretty harmless.

            try:
                file.generate_thumbs(file_name, file_contents)
            except IOError, e:
                print "(%d/%d) ID %d --  Error -- Image may be corrupt)" % (
                    counter,
                    num_instances,
                    instance.id)
                counter += 1
                continue

            regen_tracker[file_name] = True
            counter += 1
dataset/ETHPy150Open gtaylor/django-athumb/athumb/management/commands/athumb_regen_field.py/Command.regenerate_thumbs