skip pdf processing if necessary
authorRodney Ewing <ewing.rj@gmail.com>
Tue, 27 Aug 2013 22:56:11 +0000 (15:56 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Thu, 19 Sep 2013 15:12:10 +0000 (08:12 -0700)
mediagoblin/media_types/pdf/processing.py

index 549def695f991bbea532c524ec2a5127b7ab548b..b60495ebb9d692932a5625d2babe46482ea5ada5 100644 (file)
@@ -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):
     """