'Post process the given SortedDict of files (called from collectstatic).
Processing is actually two separate operations:
1. renaming files to include a hash of their content for cache-busting,
and copying those files to the target storage.
2. adjusting files which contain references to other files so they
refer to the cache-busting filenames.
If either of these are performed on a file, then that file is considered
post-processed.'

def post_process(self, paths, dry_run=False, **options):

    if dry_run:
        return
    hashed_paths = {}
    matches = (lambda path: matches_patterns(path, self._patterns.keys()))
    adjustable_paths = [path for path in paths if matches(path)]
    path_level = (lambda name: len(name.split(os.sep)))
    for name in sorted(paths.keys(), key=path_level, reverse=True):
        (storage, path) = paths[name]
        with storage.open(path) as original_file:
            hashed_name = self.hashed_name(name, original_file)
            if hasattr(original_file, u'seek'):
                original_file.seek(0)
            hashed_file_exists = self.exists(hashed_name)
            processed = False
            if (name in adjustable_paths):
                content = original_file.read().decode(settings.FILE_CHARSET)
                for patterns in self._patterns.values():
                    for (pattern, template) in patterns:
                        converter = self.url_converter(name, template)
                        try:
                            content = pattern.sub(converter, content)
                        except ValueError as exc:
                            (yield (name, None, exc))
                if hashed_file_exists:
                    self.delete(hashed_name)
                content_file = ContentFile(force_bytes(content))
                saved_name = self._save(hashed_name, content_file)
                hashed_name = force_text(saved_name.replace(u'\\', u'/'))
                processed = True
            elif (not hashed_file_exists):
                processed = True
                saved_name = self._save(hashed_name, original_file)
                hashed_name = force_text(saved_name.replace(u'\\', u'/'))
            hashed_paths[self.cache_key(name.replace(u'\\', u'/'))] = hashed_name
            (yield (name, hashed_name, processed))
    self.cache.set_many(hashed_paths)
