Bug 681 - Comments from reviewing the new video merge
authorJoar Wandborg <git@wandborg.com>
Tue, 6 Dec 2011 22:05:47 +0000 (23:05 +0100)
committerJoar Wandborg <git@wandborg.com>
Tue, 6 Dec 2011 22:05:47 +0000 (23:05 +0100)
in mediagoblin.media_types and submodules

- Moved VideoThumbnailer.errors initialization to VideoThumbnailer.__init__
- Cleaned up the image.processing imports
- Removed default ``None`` from get_media_manager(_media_type)

in mediagoblin.views
- Removed media_types import
- Removed sys import, and passing of sys to root.html template

mediagoblin/media_types/__init__.py
mediagoblin/media_types/image/processing.py
mediagoblin/media_types/video/transcoders.py
mediagoblin/views.py

index 61786562f7a0043e7983cd309812dcbcafe9665a..4fa56bc39ffad233d9b538df8d7a893182cef2b4 100644 (file)
@@ -30,7 +30,7 @@ class InvalidFileType(Exception):
 
 def get_media_types():
     """
-    Generator that returns the available media types
+    Generator, yields the available media types
     """
     for media_type in mg_globals.app_config['media_types']:
         yield media_type
@@ -38,7 +38,7 @@ def get_media_types():
 
 def get_media_managers():
     '''
-    Generator that returns all available media managers
+    Generator, yields all enabled media managers
     '''
     for media_type in get_media_types():
         __import__(media_type)
@@ -46,20 +46,35 @@ def get_media_managers():
         yield media_type, sys.modules[media_type].MEDIA_MANAGER
 
 
-def get_media_manager(_media_type = None):
+def get_media_manager(_media_type):
+    '''
+    Get the MEDIA_MANAGER based on a media type string
+
+    Example::
+        get_media_type('mediagoblin.media_types.image')
+    '''
+    if not _media_type:
+        return False
+
     for media_type, manager in get_media_managers():
         if media_type in _media_type:
             return manager
 
 
 def get_media_type_and_manager(filename):
+    '''
+    Get the media type and manager based on a filename
+    '''
     for media_type, manager in get_media_managers():
         if filename.find('.') > 0:
+            # Get the file extension
             ext = os.path.splitext(filename)[1].lower()
         else:
             raise InvalidFileType(
                 _('Could not find any file extension in "{filename}"').format(
                     filename=filename))
 
+        # Omit the dot from the extension and match it against
+        # the media manager
         if ext[1:] in manager['accepted_extensions']:
             return media_type, manager
index 5b8259fc65a3c7fc7ae480eedba069c830fbb56e..e493eb2bdc560de93b1d44ecf6b5052263d13c7f 100644 (file)
 import Image
 import os
 
-from celery.task import Task
-from celery import registry
-
-from mediagoblin.db.util import ObjectId
 from mediagoblin import mg_globals as mgg
 
-from mediagoblin.processing import BaseProcessingFail, \
-    mark_entry_failed, BadMediaFail, create_pub_filepath, THUMB_SIZE, \
-    MEDIUM_SIZE
+from mediagoblin.processing import BadMediaFail, \
+    create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE
 
 ################################
 # Media processing initial steps
index d7ed14cad25633971d867e2d6a3a318234a9087f..7071b88753fe24bb67642a28488a2397208d1b4a 100644 (file)
@@ -74,14 +74,14 @@ class VideoThumbnailer:
 
     buffer_probes = {}
 
-    errors = []
-
     def __init__(self, source_path, dest_path):
         '''
         Set up playbin pipeline in order to get video properties.
 
         Initializes and runs the gobject.MainLoop()
         '''
+        self.errors = []
+
         self.source_path = source_path
         self.dest_path = dest_path
 
index cd6aba9b8fdc6a6608ee51ef63376193b96ffab8..1e1db6c3ee9322fca9febd0bb3a2ce942d5ee6d7 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import sys
-
 from mediagoblin import mg_globals
 from mediagoblin.tools.pagination import Pagination
 from mediagoblin.tools.response import render_to_response
 from mediagoblin.db.util import DESCENDING
 from mediagoblin.decorators import uses_pagination
-from mediagoblin import media_types
 
 
 
@@ -36,8 +33,7 @@ def root_view(request, page):
         request, 'mediagoblin/root.html',
         {'media_entries': media_entries,
          'allow_registration': mg_globals.app_config["allow_registration"],
-         'pagination': pagination,
-         'sys': sys})
+         'pagination': pagination})
 
 
 def simple_template_render(request):