From: Rodney Ewing Date: Tue, 27 Aug 2013 22:56:11 +0000 (-0700) Subject: skip pdf processing if necessary X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=be49edba0516eb4ebfbf4773bd09e07f665c8254;p=mediagoblin.git skip pdf processing if necessary --- diff --git a/mediagoblin/media_types/pdf/processing.py b/mediagoblin/media_types/pdf/processing.py index 549def69..b60495eb 100644 --- a/mediagoblin/media_types/pdf/processing.py +++ b/mediagoblin/media_types/pdf/processing.py @@ -261,6 +261,22 @@ class CommonPdfProcessor(MediaProcessor): else: self.pdf_filename = self._generate_pdf() + def _skip_processing(self, keyname, **kwargs): + file_metadata = self.entry.get_file_metadata(keyname) + skip = True + + if not file_metadata: + return False + + if keyname == 'thumb': + if kwargs.get('thumb_size') != file_metadata.get('thumb_size'): + skip = False + elif keyname == 'medium': + if kwargs.get('size') != file_metadata.get('size'): + skip = False + + return skip + def copy_original(self): copy_original( self.entry, self.process_filename, @@ -271,6 +287,9 @@ class CommonPdfProcessor(MediaProcessor): thumb_size = (mgg.global_config['media:thumb']['max_width'], mgg.global_config['media:thumb']['max_height']) + if self._skip_processing('thumb', thumb_size=thumb_size): + return + # Note: pdftocairo adds '.png', so don't include an ext thumb_filename = os.path.join(self.workbench.dir, self.name_builder.fill( @@ -288,6 +307,8 @@ class CommonPdfProcessor(MediaProcessor): store_public(self.entry, 'thumb', thumb_filename + '.png', self.name_builder.fill('{basename}.thumbnail.png')) + self.entry.set_file_metadata('thumb', thumb_size=thumb_size) + def _generate_pdf(self): """ Store the pdf. If the file is not a pdf, make it a pdf @@ -317,6 +338,9 @@ class CommonPdfProcessor(MediaProcessor): size = (mgg.global_config['media:medium']['max_width'], mgg.global_config['media:medium']['max_height']) + if self._skip_processing('medium', size=size): + return + # Note: pdftocairo adds '.png', so don't include an ext filename = os.path.join(self.workbench.dir, self.name_builder.fill('{basename}.medium')) @@ -333,6 +357,8 @@ class CommonPdfProcessor(MediaProcessor): store_public(self.entry, 'medium', filename + '.png', self.name_builder.fill('{basename}.medium.png')) + self.entry.set_file_metadata('medium', size=size) + class InitialProcessor(CommonPdfProcessor): """