From e8676fa383975b37ac26e0908ec35da44afbc30a Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 8 Mar 2013 20:51:32 +0100 Subject: [PATCH] MediaManager: Use .foo instead of ['foo']. To make .media_fetch_order work, create a property. --- mediagoblin/db/mixin.py | 2 +- mediagoblin/media_types/__init__.py | 9 +++++---- mediagoblin/processing/task.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index db08dfd2..388bac89 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -149,7 +149,7 @@ class MediaEntryMixin(GenerateSlugMixin): or, if not found, None. """ - fetch_order = self.media_manager.get("media_fetch_order") + fetch_order = self.media_manager.media_fetch_order # No fetching order found? well, give up! if not fetch_order: diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py index 745e05ef..81acaee8 100644 --- a/mediagoblin/media_types/__init__.py +++ b/mediagoblin/media_types/__init__.py @@ -48,8 +48,9 @@ class CompatMediaManager(object): def __contains__(self, i): return (i in self.mm_dict) - def get(self, *args, **kwargs): - return self.mm_dict.get(*args, **kwargs) + @property + def media_fetch_order(self): + return self.mm_dict.get('media_fetch_order') def __getattr__(self, i): return self.mm_dict[i] @@ -74,7 +75,7 @@ def sniff_media(media): for media_type, manager in get_media_managers(): _log.info('Sniffing {0}'.format(media_type)) if 'sniff_handler' in manager and \ - manager['sniff_handler'](media_file, media=media): + manager.sniff_handler(media_file, media=media): _log.info('{0} accepts the file'.format(media_type)) return media_type, manager else: @@ -119,7 +120,7 @@ def get_media_type_and_manager(filename): for media_type, manager in get_media_managers(): # Omit the dot from the extension and match it against # the media manager - if ext[1:] in manager['accepted_extensions']: + if ext[1:] in manager.accepted_extensions: return media_type, manager else: _log.info('File {0} has no file extension, let\'s hope the sniffers get it.'.format( diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index aec50aab..9af192ed 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -89,7 +89,7 @@ class ProcessMedia(task.Task): with mgg.workbench_manager.create() as workbench: proc_state.set_workbench(workbench) # run the processing code - entry.media_manager['processor'](proc_state) + entry.media_manager.processor(proc_state) # We set the state to processed and save the entry here so there's # no need to save at the end of the processing stage, probably ;) -- 2.25.1