From 6403bc928bbdd916248775580d1bfa90c511f2dc Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 12 Jul 2013 17:04:08 -0500 Subject: [PATCH] Switching the hook 'get_media_manager' to a more "directed" tuple-hook 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 | 2 +- mediagoblin/media_types/__init__.py | 2 +- mediagoblin/media_types/ascii/__init__.py | 7 +------ mediagoblin/media_types/audio/__init__.py | 7 +------ mediagoblin/media_types/image/__init__.py | 7 +------ mediagoblin/media_types/pdf/__init__.py | 8 ++------ mediagoblin/media_types/stl/__init__.py | 7 +------ mediagoblin/media_types/video/__init__.py | 7 +------ 8 files changed, 9 insertions(+), 38 deletions(-) diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index ee8525c2..57b27d83 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -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) diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py index 395ba17a..134157dc 100644 --- a/mediagoblin/media_types/__init__.py +++ b/mediagoblin/media_types/__init__.py @@ -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)) diff --git a/mediagoblin/media_types/ascii/__init__.py b/mediagoblin/media_types/ascii/__init__.py index bcba237c..4baf8dd3 100644 --- a/mediagoblin/media_types/ascii/__init__.py +++ b/mediagoblin/media_types/ascii/__init__.py @@ -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, } diff --git a/mediagoblin/media_types/audio/__init__.py b/mediagoblin/media_types/audio/__init__.py index dfe68660..90f842ba 100644 --- a/mediagoblin/media_types/audio/__init__.py +++ b/mediagoblin/media_types/audio/__init__.py @@ -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, } diff --git a/mediagoblin/media_types/image/__init__.py b/mediagoblin/media_types/image/__init__.py index 4b991588..1bb9c6f3 100644 --- a/mediagoblin/media_types/image/__init__.py +++ b/mediagoblin/media_types/image/__init__.py @@ -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, } diff --git a/mediagoblin/media_types/pdf/__init__.py b/mediagoblin/media_types/pdf/__init__.py index c180507c..67509ddc 100644 --- a/mediagoblin/media_types/pdf/__init__.py +++ b/mediagoblin/media_types/pdf/__init__.py @@ -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, } diff --git a/mediagoblin/media_types/stl/__init__.py b/mediagoblin/media_types/stl/__init__.py index 192b5761..1d2a8478 100644 --- a/mediagoblin/media_types/stl/__init__.py +++ b/mediagoblin/media_types/stl/__init__.py @@ -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, } diff --git a/mediagoblin/media_types/video/__init__.py b/mediagoblin/media_types/video/__init__.py index aa4cdb93..e8a4308b 100644 --- a/mediagoblin/media_types/video/__init__.py +++ b/mediagoblin/media_types/video/__init__.py @@ -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, } -- 2.25.1