ASCII media support - Fixes
authorJoar Wandborg <git@wandborg.com>
Sat, 4 Feb 2012 19:51:05 +0000 (20:51 +0100)
committerJoar Wandborg <git@wandborg.com>
Sat, 4 Feb 2012 19:51:05 +0000 (20:51 +0100)
- Added debug logging in
  - mediagoblin.processing
  - mediagoblin.media_types.ascii.processing
  - mediagoblin.media_types.ascii.asciitoimage

mediagoblin/media_types/ascii/asciitoimage.py
mediagoblin/media_types/ascii/processing.py
mediagoblin/processing.py

index 186d80660fd3146b6feff2a857ac4233cb968381..e1c4fb44c4a2e93b456de5735478f5e3aa076145 100644 (file)
@@ -59,15 +59,15 @@ class AsciiToImage(object):
         if kw.get('font_size'):
             self._font_size = kw.get('font_size')
 
-        _log.info('Setting font to {0}, size {1}'.format(
-                self._font,
-                self._font_size))
-
         self._if = ImageFont.truetype(
             self._font,
             self._font_size,
             encoding='unic')
 
+        _log.info('Font set to {0}, size {1}'.format(
+                self._font,
+                self._font_size))
+
         #      ,-,-^-'-^'^-^'^-'^-.
         #     ( I am a wall socket )Oo,  ___
         #      `-.,.-.,.-.-.,.-.--'     '   `
@@ -92,6 +92,7 @@ class AsciiToImage(object):
         - Character set detection and decoding,
           http://pypi.python.org/pypi/chardet
         '''
+        _log.debug('Drawing image')
         # Convert the input from str to unicode
         text = text.decode('utf-8')
 
@@ -128,7 +129,7 @@ class AsciiToImage(object):
                 px_pos = self._px_pos(char_pos)
 
                 _log.debug('Writing character "{0}" at {1} (px pos {2})'.format(
-                        char,
+                        char.encode('ascii', 'replace'),
                         char_pos,
                         px_pos))
 
index 96dfce807f8c138cfd1a28a8339160b0366ec6bf..837b98307ad9825a5d9f7952fe3b9825827b4dcc 100644 (file)
@@ -72,6 +72,7 @@ def process_ascii(entry):
             thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
             thumb.save(thumb_file)
 
+        _log.debug('Copying local file to public storage')
         mgg.public_store.copy_local_to_storage(
             tmp_thumb_filename, thumb_filepath)
 
index 4f1bf61b62602be425c9b172400f6c08d383e1fc..9e57380dec8bc4941cdbd932b7cc74b9fe7b161c 100644 (file)
@@ -14,6 +14,8 @@
 # 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 logging
+
 from celery.task import Task
 
 from mediagoblin.db.util import ObjectId
@@ -23,6 +25,7 @@ from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
 
 from mediagoblin.media_types import get_media_manager
 
+_log = logging.getLogger(__name__)
 
 THUMB_SIZE = 180, 180
 MEDIUM_SIZE = 640, 640
@@ -57,12 +60,19 @@ class ProcessMedia(Task):
         try:
             #__import__(entry.media_type)
             manager = get_media_manager(entry.media_type)
+            _log.debug('Processing {0}'.format(entry))
             manager['processor'](entry)
         except BaseProcessingFail, exc:
             mark_entry_failed(entry._id, exc)
             return
         except ImportError, exc:
-            mark_entry_failed(entry[u'_id'], exc)
+            _log.error(
+                'Entry {0} failed to process due to an import error: {1}'\
+                    .format(
+                    entry.title,
+                    exc))
+
+            mark_entry_failed(entry._id, exc)
 
         entry.state = u'processed'
         entry.save()