added resizer for stl media
authorRodney Ewing <ewing.rj@gmail.com>
Wed, 14 Aug 2013 17:40:14 +0000 (10:40 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:21 +0000 (15:30 -0700)
mediagoblin/media_types/stl/processing.py

index 6adc68aece78d0a6eadb13c4a76b8982a6ea0ed7..2ec4241c5231cd471173a97a29d11e8885881273 100644 (file)
@@ -273,7 +273,58 @@ class InitialProcessor(CommonStlProcessor):
         self.delete_queue_file()
 
 
+class Resizer(CommonStlProcessor):
+    """
+    Resizing process steps for processed stls
+    """
+    name = 'resize'
+    description = 'Resize thumbnail and mediums'
+
+    @classmethod
+    def media_is_eligible(cls, entry=None, state=None):
+        """
+        Determine if this media type is eligible for processing
+        """
+        if not state:
+            state = entry.state
+        return state in 'processed'
+
+    @classmethod
+    def generate_parser(cls):
+        parser = argparse.ArgumentParser(
+            description=cls.description,
+            prog=cls.name)
+
+        parser.add_argument(
+            '--size',
+            nargs=2,
+            metavar=('max_width', 'max_height'),
+            type=int)
+
+        parser.add_argument(
+            'file',
+            choices=['medium', 'thumb'])
+
+        return parser
+
+    @classmethod
+    def args_to_request(cls, args):
+        return request_from_args(
+            args, ['size', 'file'])
+
+    def process(self, file, size=None):
+        self.common_setup()
+        if file == 'medium':
+            self.generate_perspective(size=size)
+            self.generate_topview(size=size)
+            self.generate_frontview(size=size)
+            self.generate_sideview(size=size)
+        elif file == 'thumb':
+            self.generate_thumb(size=size)
+
+
 class StlProcessingManager(ProcessingManager):
     def __init__(self):
         super(self.__class__, self).__init__()
         self.add_processor(InitialProcessor)
+        self.add_processor(Resizer)