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

index 77d3d86e3b01974f225d623e29080847aeee3cb6..39949b596d8c305d063b6f560ca6795399135566 100644 (file)
@@ -144,11 +144,30 @@ class CommonStlProcessor(MediaProcessor):
         # copy it up!
         store_public(self.entry, keyname, workbench_path, filename)
 
+    def _skip_processing(self, keyname, **kwargs):
+        file_metadata = self.entry.get_file_metadata(keyname)
+
+        if not file_metadata:
+            return False
+        skip = True
+
+        if keyname == 'thumb':
+            if kwargs.get('thumb_size') != file_metadata.get('thumb_size'):
+                skip = False
+        else:
+            if kwargs.get('size') != file_metadata.get('size'):
+                skip = False
+
+        return skip
+
     def generate_thumb(self, thumb_size=None):
         if not thumb_size:
             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
+
         self._snap(
             "thumb",
             "{basename}.thumb.jpg",
@@ -156,11 +175,16 @@ class CommonStlProcessor(MediaProcessor):
             thumb_size,
             project="PERSP")
 
+        self.entry.set_file_metadata('thumb', thumb_size=thumb_size)
+
     def generate_perspective(self, size=None):
         if not size:
             size = (mgg.global_config['media:medium']['max_width'],
                     mgg.global_config['media:medium']['max_height'])
 
+        if self._skip_processing('perspective', size=size):
+            return
+
         self._snap(
             "perspective",
             "{basename}.perspective.jpg",
@@ -168,11 +192,16 @@ class CommonStlProcessor(MediaProcessor):
             size,
             project="PERSP")
 
+        self.entry.set_file_metadata('perspective', size=size)
+
     def generate_topview(self, size=None):
         if not size:
             size = (mgg.global_config['media:medium']['max_width'],
                     mgg.global_config['media:medium']['max_height'])
 
+        if self._skip_processing('top', size=size):
+            return
+
         self._snap(
             "top",
             "{basename}.top.jpg",
@@ -180,11 +209,16 @@ class CommonStlProcessor(MediaProcessor):
              self.greatest*2],
             size)
 
+        self.entry.set_file_metadata('top', size=size)
+
     def generate_frontview(self, size=None):
         if not size:
             size = (mgg.global_config['media:medium']['max_width'],
                     mgg.global_config['media:medium']['max_height'])
 
+        if self._skip_processing('front', size=size):
+            return
+
         self._snap(
             "front",
             "{basename}.front.jpg",
@@ -192,11 +226,16 @@ class CommonStlProcessor(MediaProcessor):
              self.model.average[2]],
             size)
 
+        self.entry.set_file_metadata('front', size=size)
+
     def generate_sideview(self, size=None):
         if not size:
             size = (mgg.global_config['media:medium']['max_width'],
                     mgg.global_config['media:medium']['max_height'])
 
+        if self._skip_processing('side', size=size):
+            return
+
         self._snap(
             "side",
             "{basename}.side.jpg",
@@ -204,6 +243,8 @@ class CommonStlProcessor(MediaProcessor):
              self.model.average[2]],
             size)
 
+        self.entry.set_file_metadata('side', size=size)
+
     def store_dimensions(self):
         """
         Put model dimensions into the database