Improved logging
authorThierry Florac <thierry.florac@onf.fr>
Fri, 04 Dec 2015 16:36:30 +0100
changeset 23 d49c3f386782
parent 22 b5da674fd06c
child 24 0f4851b0aef3
Improved logging
src/pyams_media/process.py
--- a/src/pyams_media/process.py	Fri Dec 04 16:36:06 2015 +0100
+++ b/src/pyams_media/process.py	Fri Dec 04 16:36:30 2015 +0100
@@ -23,9 +23,10 @@
 from threading import Thread
 
 # import interfaces
-from pyams_media.interfaces import IMediaConverter, IMediaConversions
+from pyams_media.interfaces import IMediaConverter, IMediaConversions, MEDIA_CONVERSION_CMDLINE_KEY
 from pyams_utils.interfaces import PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME
 from transaction.interfaces import ITransactionManager
+from zope.annotation.interfaces import IAnnotations
 from zope.intid.interfaces import IIntIds
 
 # import packages
@@ -93,17 +94,21 @@
                 logger.debug("Starting conversion process for {0!r} to {1}".format(media, media_format))
                 manager = ITransactionManager(media)
                 for width, conversion in converter.convert(media):
-                    logger.debug("Finished FFmpeg conversion process to {0}, {1} bytes output".format(media_format,
-                                                                                                      len(conversion)))
+                    conversion_result = conversion.get('output', '')
+                    logger.debug("Finished FFmpeg conversion process to {0}, {1} bytes output"
+                                 .format(media_format, len(conversion_result)))
                     # add conversion in a transaction attempts loop
-                    if len(conversion) > 0:
+                    if len(conversion_result) > 0:
                         for attempt in manager.attempts():
                             with attempt as t:
-                                IMediaConversions(media).add_conversion(conversion, media_format, converter.format, width)
+                                converted = IMediaConversions(media).add_conversion(conversion_result, media_format,
+                                                                                    converter.format, width)
+                                IAnnotations(converted)[MEDIA_CONVERSION_CMDLINE_KEY] = conversion.get('cmdline')
                             if t.status == 'Committed':
                                 break
                     else:
                         logger.warning("Finished FFmpeg conversion process with **NO OUTPUT** !!!")
+                        logger.warning(conversion.get('errors'))
         finally:
             if manager is not None:
                 manager.abort()
@@ -133,7 +138,7 @@
 
     def test(self, settings):
         messages = ['Conversion process ready to handle requests.']
-        for command in ('ffmpeg', 'ffprobe'):
+        for command in ('avconv', 'avprobe'):
             whereis = shutil.which(command)
             if whereis is None:
                 messages.append("WARNING: missing required command '{0}'!".format(command))