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

index f0ba7867d6177dea621c1e90fa84a3d386f96dd6..c180507cadf18f5e72a34acfd781610a98b4a3e3 100644 (file)
 from mediagoblin.media_types import MediaManagerBase
 from mediagoblin.media_types.pdf.processing import process_pdf, \
     sniff_handler
+from mediagoblin.tools import pluginapi
+
+ACCEPTED_EXTENSIONS = ['pdf']
+MEDIA_TYPE = 'mediagoblin.media_types.pdf'
+
+
+def setup_plugin():
+    config = pluginapi.get_config(MEDIA_TYPE)
 
 
 class PDFMediaManager(MediaManagerBase):
     human_readable = "PDF"
     processor = staticmethod(process_pdf)
-    sniff_handler = staticmethod(sniff_handler)
     display_template = "mediagoblin/media_displays/pdf.html"
     default_thumb = "images/media_thumbs/pdf.jpg"
-    accepted_extensions = ["pdf"]
 
 
-MEDIA_MANAGER = PDFMediaManager
+def get_media_manager(media_type):
+    if media_type == MEDIA_TYPE:
+        return PDFMediaManager
+
+
+def get_media_type_and_manager(ext):
+    if ext in ACCEPTED_EXTENSIONS:
+        return MEDIA_TYPE, PDFMediaManager
+
+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 49742fd72256d7f4baf01717252d6434602e4ac8..a1eeb307e4af15fc5a3aa1883f0ea2b60fa26f11 100644 (file)
@@ -25,6 +25,8 @@ from mediagoblin.tools.translate import fake_ugettext_passthrough as _
 
 _log = logging.getLogger(__name__)
 
+MEDIA_TYPE = 'mediagoblin.media_types.pdf'
+
 # TODO - cache (memoize) util
 
 # This is a list created via uniconv --show and hand removing some types that
@@ -163,16 +165,17 @@ def check_prerequisites():
     return True
 
 def sniff_handler(media_file, **kw):
+    _log.info('Sniffing {0}'.format(MEDIA_TYPE))
     if not check_prerequisites():
-        return False
+        return None
     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 create_pdf_thumb(original, thumb_filename, width, height):
     # Note: pdftocairo adds '.png', remove it