aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/media_types
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2013-03-08 14:37:33 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2013-04-17 12:08:52 +0200
commit2077d6ed933773e0b44a7d1efa603453ea196fe3 (patch)
tree99d337413a6cc86822b9851ac2c7869d808bd670 /mediagoblin/media_types
parent827f91e603bf706e628e8d2d625d49d79c62e721 (diff)
downloadmediagoblin-2077d6ed933773e0b44a7d1efa603453ea196fe3.tar.lz
mediagoblin-2077d6ed933773e0b44a7d1efa603453ea196fe3.tar.xz
mediagoblin-2077d6ed933773e0b44a7d1efa603453ea196fe3.zip
First step towards a MediaManager class: Compat one.
To get us moving towards a MediaManager class, the first idea is to create a class that wraps our current dict based manager and makes all users happy.
Diffstat (limited to 'mediagoblin/media_types')
-rw-r--r--mediagoblin/media_types/__init__.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py
index 0abb38d3..745e05ef 100644
--- a/mediagoblin/media_types/__init__.py
+++ b/mediagoblin/media_types/__init__.py
@@ -20,6 +20,7 @@ import logging
import tempfile
from mediagoblin import mg_globals
+from mediagoblin.tools.common import import_component
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
_log = logging.getLogger(__name__)
@@ -31,6 +32,29 @@ class InvalidFileType(Exception):
pass
+class CompatMediaManager(object):
+ def __init__(self, mm_dict, entry=None):
+ self.mm_dict = mm_dict
+ self.entry = entry
+
+ def __call__(self, entry):
+ "So this object can look like a class too, somehow"
+ assert self.entry is None
+ return self.__class__(self.mm_dict, entry)
+
+ def __getitem__(self, i):
+ return self.mm_dict[i]
+
+ def __contains__(self, i):
+ return (i in self.mm_dict)
+
+ def get(self, *args, **kwargs):
+ return self.mm_dict.get(*args, **kwargs)
+
+ def __getattr__(self, i):
+ return self.mm_dict[i]
+
+
def sniff_media(media):
'''
Iterate through the enabled media types and find those suited
@@ -74,9 +98,12 @@ def get_media_managers():
Generator, yields all enabled media managers
'''
for media_type in get_media_types():
- __import__(media_type)
+ mm = import_component(media_type + ":MEDIA_MANAGER")
+
+ if isinstance(mm, dict):
+ mm = CompatMediaManager(mm)
- yield media_type, sys.modules[media_type].MEDIA_MANAGER
+ yield media_type, mm
def get_media_type_and_manager(filename):