converted stl media_type to plugin
authorRodney Ewing <ewing.rj@gmail.com>
Tue, 2 Jul 2013 15:52:33 +0000 (08:52 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Tue, 2 Jul 2013 16:00:57 +0000 (09:00 -0700)
mediagoblin/media_types/stl/__init__.py
mediagoblin/media_types/stl/processing.py

index 6ae8a8b9b5f926b4c98b09b32bc265617e7aacca..192b576174f4a68519c993f4616288e4498039ed 100644 (file)
 from mediagoblin.media_types import MediaManagerBase
 from mediagoblin.media_types.stl.processing import process_stl, \
     sniff_handler
+from mediagoblin.tools import pluginapi
+
+MEDIA_TYPE = 'mediagoblin.media_types.stl'
+ACCEPTED_EXTENSIONS = ["obj", "stl"]
+
+
+def setup_plugin():
+    config = pluginapi.get_config(MEDIA_TYPE)
 
 
 class STLMediaManager(MediaManagerBase):
     human_readable = "stereo lithographics"
     processor = staticmethod(process_stl)
-    sniff_handler = staticmethod(sniff_handler)
     display_template = "mediagoblin/media_displays/stl.html"
     default_thumb = "images/media_thumbs/video.jpg"
-    accepted_extensions = ["obj", "stl"]
 
 
-MEDIA_MANAGER = STLMediaManager
+def get_media_manager(media_type):
+    if media_type == MEDIA_TYPE:
+        return STLMediaManager
+
+
+def get_media_type_and_manager(ext):
+    if ext in ACCEPTED_EXTENSIONS:
+        return MEDIA_TYPE, STLMediaManager
+
+hooks = {
+    'setup': setup_plugin,
+    'get_media_type_and_manager': get_media_type_and_manager,
+    'sniff_handler': sniff_handler,
+    'get_media_manager': get_media_manager,
+}
index ce7a5d3711fbd0d9a2f6de83d401c46f45c7e35f..537514165d92d281218096a7de8782b077c39989 100644 (file)
@@ -29,6 +29,7 @@ from mediagoblin.media_types.stl import model_loader
 
 _log = logging.getLogger(__name__)
 SUPPORTED_FILETYPES = ['stl', 'obj']
+MEDIA_TYPE = 'mediagoblin.media_types.stl'
 
 BLEND_FILE = pkg_resources.resource_filename(
     'mediagoblin.media_types.stl',
@@ -43,13 +44,14 @@ BLEND_SCRIPT = pkg_resources.resource_filename(
 
 
 def sniff_handler(media_file, **kw):
+    _log.info('Sniffing {0}'.format(MEDIA_TYPE))
     if kw.get('media') is not None:
         name, ext = os.path.splitext(kw['media'].filename)
         clean_ext = ext[1:].lower()
 
         if clean_ext in SUPPORTED_FILETYPES:
             _log.info('Found file extension in supported filetypes')
-            return True
+            return MEDIA_TYPE
         else:
             _log.debug('Media present, extension not found in {0}'.format(
                     SUPPORTED_FILETYPES))
@@ -57,7 +59,7 @@ def sniff_handler(media_file, **kw):
         _log.warning('Need additional information (keyword argument \'media\')'
                      ' to be able to handle sniffing')
 
-    return False
+    return None
 
 
 def blender_render(config):