MediaManager: Use .foo instead of ['foo'].

To make .media_fetch_order work, create a property.
This commit is contained in:
Elrond 2013-03-08 20:51:32 +01:00
parent 2077d6ed93
commit e8676fa383
3 changed files with 7 additions and 6 deletions

View File

@ -149,7 +149,7 @@ class MediaEntryMixin(GenerateSlugMixin):
or, if not found, None. 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! # No fetching order found? well, give up!
if not fetch_order: if not fetch_order:

View File

@ -48,8 +48,9 @@ class CompatMediaManager(object):
def __contains__(self, i): def __contains__(self, i):
return (i in self.mm_dict) return (i in self.mm_dict)
def get(self, *args, **kwargs): @property
return self.mm_dict.get(*args, **kwargs) def media_fetch_order(self):
return self.mm_dict.get('media_fetch_order')
def __getattr__(self, i): def __getattr__(self, i):
return self.mm_dict[i] return self.mm_dict[i]
@ -74,7 +75,7 @@ def sniff_media(media):
for media_type, manager in get_media_managers(): for media_type, manager in get_media_managers():
_log.info('Sniffing {0}'.format(media_type)) _log.info('Sniffing {0}'.format(media_type))
if 'sniff_handler' in manager and \ 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)) _log.info('{0} accepts the file'.format(media_type))
return media_type, manager return media_type, manager
else: else:
@ -119,7 +120,7 @@ def get_media_type_and_manager(filename):
for media_type, manager in get_media_managers(): for media_type, manager in get_media_managers():
# Omit the dot from the extension and match it against # Omit the dot from the extension and match it against
# the media manager # the media manager
if ext[1:] in manager['accepted_extensions']: if ext[1:] in manager.accepted_extensions:
return media_type, manager return media_type, manager
else: else:
_log.info('File {0} has no file extension, let\'s hope the sniffers get it.'.format( _log.info('File {0} has no file extension, let\'s hope the sniffers get it.'.format(

View File

@ -89,7 +89,7 @@ class ProcessMedia(task.Task):
with mgg.workbench_manager.create() as workbench: with mgg.workbench_manager.create() as workbench:
proc_state.set_workbench(workbench) proc_state.set_workbench(workbench)
# run the processing code # 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 # 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 ;) # no need to save at the end of the processing stage, probably ;)