def handle(self, *args, **kwargs):
        for screenshot in models.Screenshot.load():
            print screenshot.name
            img = Image.open(staticfiles_storage.path(screenshot.path))

            # Ensure we're in RGB
            if img.mode not in ('L', 'RGB'):
                img = img.convert('RGB')

            # Magic!
            # The thumbnail is only limited by width, so use
            # a larger-than-needed height.
            img.thumbnail((200 * screenshot.screens, 1000), Image.ANTIALIAS)

            # Save the thumbnail to a tmpfile
            fd, tmp = tempfile.mkstemp()
            file = os.fdopen(fd, 'w+b')
            type = mimetypes.guess_type(screenshot.name)[0].split('/')[1]
            img.save(file, type)
            file.close()

            # Nuke previous version if it exists
            if staticfiles_storage.exists(screenshot.thumbnail):
                staticfiles_storage.delete(screenshot.thumbnail)

            # save thumbnail to stattic dir
            file = File(open(tmp, 'rb'))
            staticfiles_storage.save(screenshot.thumbnail, file)
            file.close()
            os.unlink(tmp)
Exemple #2
0
 def handle(self, *args, **options):
     locale = options["locale"]
     content = generate_js(locale)
     file_name = staticfiles_storage.path(f"choices-{locale}.js")
     if staticfiles_storage.exists(file_name):
         staticfiles_storage.delete(file_name)
     staticfiles_storage.save(file_name, ContentFile(content))
     self.stdout.write(f"{file_name} saved to static root!")
 def copy_files_to_original_staticfiles_storage(self, paths, dry_run = False):
     if dry_run:
         return {}
     new_paths = SortedDict()
     for name in sorted(paths.keys(), key=path_level, reverse=True):
         if name not in new_paths:
             staticfiles_storage.save(name, self.open(name))
             new_paths[name] = (self, name)
     return new_paths
    def handle(self, *args, **options):
        local_storage = StaticFilesStorage()
        base_path = local_storage.base_location

        # Ignore files in our ignore patterns
        ignore_patterns = getattr(settings, 'SYNCSTATIC_IGNORE_PATTERNS', None)
        files = set(utils.get_files(local_storage, ignore_patterns=ignore_patterns))

        # Remove any files that went into compilation
        files -= set(settings.PIPELINE_JS['main']['source_filenames'])
        files -= set(settings.PIPELINE_CSS['main']['source_filenames'])

        for file in files:
            print('syncing to s3: %s' % file)
            staticfiles_storage.save(file, local_storage.open(file, 'r'))
    def handle(self, *args, **options):
        local_storage = StaticFilesStorage()
        base_path = local_storage.base_location

        # Ignore files in our ignore patterns
        ignore_patterns = getattr(settings, 'SYNCSTATIC_IGNORE_PATTERNS', None)
        files = set(
            utils.get_files(local_storage, ignore_patterns=ignore_patterns))

        # Remove any files that went into compilation
        files -= set(settings.PIPELINE_JS['main']['source_filenames'])
        files -= set(settings.PIPELINE_CSS['main']['source_filenames'])

        for file in files:
            print('syncing to s3: %s' % file)
            staticfiles_storage.save(file, local_storage.open(file, 'r'))
Exemple #6
0
 def update_content(self, fileobj):
     staticfiles_storage.save(self.full_path, fileobj)