Porting video to GStreamer 1.0
[mediagoblin.git] / mediagoblin / processing / __init__.py
index bdbe0441bda352970bb748d180801fd68c9be8cc..b7e36027ef7ccf412cead1ffcf5bc877e3430eae 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/>.
 
-from collections import OrderedDict
+# Use an ordered dict if we can.  If not, we'll just use a normal dict
+# later.
+try:
+    from collections import OrderedDict
+except:
+    OrderedDict = None
+
 import logging
 import os
 
+import six
+
 from mediagoblin import mg_globals as mgg
 from mediagoblin.db.util import atomic_update
 from mediagoblin.db.models import MediaEntry
@@ -40,7 +48,7 @@ class ProgressCallback(object):
 def create_pub_filepath(entry, filename):
     return mgg.public_store.get_unique_filepath(
             ['media_entries',
-             unicode(entry.id),
+             six.text_type(entry.id),
              filename])
 
 
@@ -187,7 +195,10 @@ class ProcessingManager(object):
     """
     def __init__(self):
         # Dict of all MediaProcessors of this media type
-        self.processors = OrderedDict()
+        if OrderedDict is not None:
+            self.processors = OrderedDict()
+        else:
+            self.processors = {}
 
     def add_processor(self, processor):
         """
@@ -237,8 +248,6 @@ class ProcessingManager(object):
         try:
             processor = self.processors[key]
         except KeyError:
-            import pdb
-            pdb.set_trace()
             raise ProcessorDoesNotExist(
                 "'%s' processor does not exist for this media type" % key)
 
@@ -312,7 +321,7 @@ def mark_entry_failed(entry_id, exc):
         atomic_update(mgg.database.MediaEntry,
             {'id': entry_id},
             {u'state': u'failed',
-             u'fail_error': unicode(exc.exception_path),
+             u'fail_error': six.text_type(exc.exception_path),
              u'fail_metadata': exc.metadata})
     else:
         _log.warn("No idea what happened here, but it failed: %r", exc)
@@ -369,12 +378,11 @@ def store_public(entry, keyname, local_file, target_name=None,
                   entry.media_files[keyname], target_filepath)
         if delete_if_exists:
             mgg.public_store.delete_file(entry.media_files[keyname])
-
     try:
         mgg.public_store.copy_local_to_storage(local_file, target_filepath)
-    except:
+    except Exception as e:
+        _log.error(u'Exception happened: {0}'.format(e))
         raise PublicStoreFail(keyname=keyname)
-
     # raise an error if the file failed to copy
     if not mgg.public_store.file_exists(target_filepath):
         raise PublicStoreFail(keyname=keyname)
@@ -392,7 +400,7 @@ class BaseProcessingFail(Exception):
     subclass from.
 
     You shouldn't call this itself; instead you should subclass it
-    and provid the exception_path and general_message applicable to
+    and provide the exception_path and general_message applicable to
     this error.
     """
     general_message = u''