MediaManager: Use .foo instead of ['foo'].
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 8 Mar 2013 19:51:32 +0000 (20:51 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 17 Apr 2013 10:08:53 +0000 (12:08 +0200)
To make .media_fetch_order work, create a property.

mediagoblin/db/mixin.py
mediagoblin/media_types/__init__.py
mediagoblin/processing/task.py

index db08dfd2755d75771287dc129964d93c96e5c6ba..388bac8960d536c6965bd7fd83fde917abd00d30 100644 (file)
@@ -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:
index 745e05ef5a5590156c8996487e92a45b0331e0e7..81acaee86dda149dad55dc52e5060db552917e6e 100644 (file)
@@ -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(
index aec50aabdb11cfcc9460cd11709fe291ebfb95a0..9af192edb97f0f902dc15b253c1918dcae40cd40 100644 (file)
@@ -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 ;)