Switching the hook 'get_media_manager' to a more "directed" tuple-hook
authorChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 12 Jul 2013 22:04:08 +0000 (17:04 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 12 Jul 2013 22:04:08 +0000 (17:04 -0500)
By switching this to a tuple that includes the media type in the key
itself, this requires iteration and execution of functions that
"check" that they are the right type.

This commit sponsored by Greg Grossmeier.  Thanks buddy! :)

mediagoblin/db/mixin.py
mediagoblin/media_types/__init__.py
mediagoblin/media_types/ascii/__init__.py
mediagoblin/media_types/audio/__init__.py
mediagoblin/media_types/image/__init__.py
mediagoblin/media_types/pdf/__init__.py
mediagoblin/media_types/stl/__init__.py
mediagoblin/media_types/video/__init__.py

index ee8525c280796ad6f89b9839f680bf10338bf052..57b27d83a976dc5afa2ea76ea42ae2847478b704 100644 (file)
@@ -203,7 +203,7 @@ class MediaEntryMixin(GenerateSlugMixin):
 
         Raises FileTypeNotSupported in case no such manager is enabled
         """
-        manager = hook_handle('get_media_manager', self.media_type)
+        manager = hook_handle(('media_manager', self.media_type))
         if manager:
             return manager(self)
 
index 395ba17aa1c44077588d077f18b9d2e0b9f14cc8..134157dcb0ca7054fdf5043bef82548137ef7373 100644 (file)
@@ -69,7 +69,7 @@ def sniff_media(media):
         media_type = hook_handle('sniff_handler', media_file, media=media)
         if media_type:
             _log.info('{0} accepts the file'.format(media_type))
-            return media_type, hook_handle('get_media_managers', media_type)
+            return media_type, hook_handle(('media_manager', media_type))
         else:
             _log.debug('{0} did not accept the file'.format(media_type))
 
index bcba237c0f12af8ce4d4826f031bc271df4267c1..4baf8dd383b6b2fc1587d901b16772de87f50874 100644 (file)
@@ -34,11 +34,6 @@ class ASCIIMediaManager(MediaManagerBase):
     default_thumb = "images/media_thumbs/ascii.jpg"
 
 
-def get_media_manager(media_type):
-    if media_type == MEDIA_TYPE:
-        return ASCIIMediaManager
-
-
 def get_media_type_and_manager(ext):
     if ext in ACCEPTED_EXTENSIONS:
         return MEDIA_TYPE, ASCIIMediaManager
@@ -47,6 +42,6 @@ def get_media_type_and_manager(ext):
 hooks = {
     'setup': setup_plugin,
     'get_media_type_and_manager': get_media_type_and_manager,
+    ('media_manager', MEDIA_TYPE): lambda: ASCIIMediaManager,
     'sniff_handler': sniff_handler,
-    'get_media_manager': get_media_manager,
 }
index dfe686606db19a9af9b147ef8ae417cc4be5d49e..90f842baa8e73d5d2475ee126f6afe46d856c976 100644 (file)
@@ -33,11 +33,6 @@ class AudioMediaManager(MediaManagerBase):
     display_template = "mediagoblin/media_displays/audio.html"
 
 
-def get_media_manager(media_type):
-    if media_type == MEDIA_TYPE:
-        return AudioMediaManager
-
-
 def get_media_type_and_manager(ext):
     if ext in ACCEPTED_EXTENSIONS:
         return MEDIA_TYPE, AudioMediaManager
@@ -46,5 +41,5 @@ hooks = {
     'setup': setup_plugin,
     'get_media_type_and_manager': get_media_type_and_manager,
     'sniff_handler': sniff_handler,
-    'get_media_manager': get_media_manager,
+    ('media_manager', MEDIA_TYPE): lambda: AudioMediaManager,
 }
index 4b991588c5897da11fb9dbf913080c34f4d27cfb..1bb9c6f3edb9a1ffae69beb98266c339abb65af8 100644 (file)
@@ -59,11 +59,6 @@ class ImageMediaManager(MediaManagerBase):
             return None
 
 
-def get_media_manager(media_type):
-    if media_type == MEDIA_TYPE:
-        return ImageMediaManager
-
-
 def get_media_type_and_manager(ext):
     if ext in ACCEPTED_EXTENSIONS:
         return MEDIA_TYPE, ImageMediaManager
@@ -73,5 +68,5 @@ hooks = {
     'setup': setup_plugin,
     'get_media_type_and_manager': get_media_type_and_manager,
     'sniff_handler': sniff_handler,
-    'get_media_manager': get_media_manager,
+    ('media_manager', MEDIA_TYPE): lambda: ImageMediaManager,
 }
index c180507cadf18f5e72a34acfd781610a98b4a3e3..67509ddc5196835c1f111c05dfc9e396f84aced9 100644 (file)
@@ -34,18 +34,14 @@ class PDFMediaManager(MediaManagerBase):
     default_thumb = "images/media_thumbs/pdf.jpg"
 
 
-def get_media_manager(media_type):
-    if media_type == MEDIA_TYPE:
-        return PDFMediaManager
-
-
 def get_media_type_and_manager(ext):
     if ext in ACCEPTED_EXTENSIONS:
         return MEDIA_TYPE, PDFMediaManager
 
+
 hooks = {
     'setup': setup_plugin,
     'get_media_type_and_manager': get_media_type_and_manager,
     'sniff_handler': sniff_handler,
-    'get_media_manager': get_media_manager,
+    ('media_manager', MEDIA_TYPE): lambda: PDFMediaManager,
 }
index 192b576174f4a68519c993f4616288e4498039ed..1d2a8478c9b4633e992278b573132773fe8c0cfa 100644 (file)
@@ -34,11 +34,6 @@ class STLMediaManager(MediaManagerBase):
     default_thumb = "images/media_thumbs/video.jpg"
 
 
-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
@@ -47,5 +42,5 @@ hooks = {
     'setup': setup_plugin,
     'get_media_type_and_manager': get_media_type_and_manager,
     'sniff_handler': sniff_handler,
-    'get_media_manager': get_media_manager,
+    ('media_manager', MEDIA_TYPE): lambda: STLMediaManager,
 }
index aa4cdb938dd9ea3ba46e2155de46cc5584d1037a..e8a4308bc7386b943f12ff51bc84a2eee4d3d473 100644 (file)
@@ -39,11 +39,6 @@ class VideoMediaManager(MediaManagerBase):
     default_webm_type = 'video/webm; codecs="vp8, vorbis"'
 
 
-def get_media_manager(media_type):
-    if media_type == MEDIA_TYPE:
-        return VideoMediaManager
-
-
 def get_media_type_and_manager(ext):
     if ext in ACCEPTED_EXTENSIONS:
         return MEDIA_TYPE, VideoMediaManager
@@ -52,5 +47,5 @@ hooks = {
     'setup': setup_plugin,
     'get_media_type_and_manager': get_media_type_and_manager,
     'sniff_handler': sniff_handler,
-    'get_media_manager': get_media_manager,
+    ('media_manager', MEDIA_TYPE): lambda: VideoMediaManager,
 }