converted ascii media_type to plugin
authorRodney Ewing <ewing.rj@gmail.com>
Tue, 2 Jul 2013 15:09:37 +0000 (08:09 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Tue, 2 Jul 2013 16:00:50 +0000 (09:00 -0700)
mediagoblin/media_types/ascii/__init__.py
mediagoblin/media_types/ascii/processing.py

index 0931e83a0f9755d20d451ef329261da623dfb739..bcba237c0f12af8ce4d4826f031bc271df4267c1 100644 (file)
 from mediagoblin.media_types import MediaManagerBase
 from mediagoblin.media_types.ascii.processing import process_ascii, \
     sniff_handler
+from mediagoblin.tools import pluginapi
+
+ACCEPTED_EXTENSIONS = ["txt", "asc", "nfo"]
+MEDIA_TYPE = 'mediagoblin.media_types.ascii'
+
+
+def setup_plugin():
+    config = pluginapi.get_config(MEDIA_TYPE)
 
 
 class ASCIIMediaManager(MediaManagerBase):
     human_readable = "ASCII"
     processor = staticmethod(process_ascii)
-    sniff_handler = staticmethod(sniff_handler)
     display_template = "mediagoblin/media_displays/ascii.html"
     default_thumb = "images/media_thumbs/ascii.jpg"
-    accepted_extensions = ["txt", "asc", "nfo"]
-    
 
-MEDIA_MANAGER = ASCIIMediaManager
+
+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
+
+
+hooks = {
+    'setup': setup_plugin,
+    'get_media_type_and_manager': get_media_type_and_manager,
+    'sniff_handler': sniff_handler,
+    'get_media_manager': get_media_manager,
+}
index 2f6079be444a2f7ee54144da3cc1863aae34f5ab..aca784e8c6c375ba30391122eb91a1bf1d41a33d 100644 (file)
@@ -28,17 +28,19 @@ from mediagoblin.media_types.ascii import asciitoimage
 _log = logging.getLogger(__name__)
 
 SUPPORTED_EXTENSIONS = ['txt', 'asc', 'nfo']
+MEDIA_TYPE = 'mediagoblin.media_types.ascii'
 
 
 def sniff_handler(media_file, **kw):
+    _log.info('Sniffing {0}'.format(MEDIA_TYPE))
     if kw.get('media') is not None:
         name, ext = os.path.splitext(kw['media'].filename)
         clean_ext = ext[1:].lower()
 
         if clean_ext in SUPPORTED_EXTENSIONS:
-            return True
+            return MEDIA_TYPE
 
-    return False
+    return None
 
 
 def process_ascii(proc_state):