Merge remote branch 'remotes/elrond/idea/simple_proc_media_clean'
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 12 Jun 2011 22:42:26 +0000 (17:42 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 12 Jun 2011 22:42:26 +0000 (17:42 -0500)
Conflicts:
mediagoblin/process_media/__init__.py

1  2 
mediagoblin/process_media/__init__.py

index f0a6e511124904cf7c45ea52f897128317b8f70a,097b4375e2075dba7ec683682831b45ef2f4dd26..a2d843e9fb0d59308823f5df95f1a02eb8a94883
@@@ -24,11 -24,16 +24,18 @@@ from mediagoblin import mg_globals as m
  THUMB_SIZE = 200, 200
  
  
 -    return public_store.get_unique_filepath(
+ def create_pub_filepath(entry, filename):
++    return mgg.public_store.get_unique_filepath(
+             ['media_entries',
+              unicode(entry['_id']),
+              filename])
  @task
  def process_media_initial(media_id):
 -    entry = database.MediaEntry.one(
 +    workbench = mgg.workbench_manager.create_workbench()
 +
 +    entry = mgg.database.MediaEntry.one(
          {'_id': ObjectId(media_id)})
  
      queued_filepath = entry['queued_media_file']
      with queued_file:
          thumb = Image.open(queued_file)
          thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
 +        # ensure color mode is compatible with jpg
 +        if thumb.mode != "RGB":
 +            thumb = thumb.convert("RGB")
  
-         thumb_filepath = mgg.public_store.get_unique_filepath(
-             ['media_entries',
-              unicode(entry['_id']),
-              'thumbnail.jpg'])
+         thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
  
 -        with public_store.get_file(thumb_filepath, 'w') as thumb_file:
 +        thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
 +        with thumb_file:
              thumb.save(thumb_file, "JPEG")
  
      # we have to re-read because unlike PIL, not everything reads
      # things in string representation :)
 -    queued_file = queue_store.get_file(queued_filepath, 'rb')
 +    queued_file = file(queued_filename, 'rb')
  
      with queued_file:
-         main_filepath = mgg.public_store.get_unique_filepath(
-             ['media_entries',
-              unicode(entry['_id']),
-              queued_filepath[-1]])
+         main_filepath = create_pub_filepath(entry, queued_filepath[-1])
          
 -        with public_store.get_file(main_filepath, 'wb') as main_file:
 +        with mgg.public_store.get_file(main_filepath, 'wb') as main_file:
              main_file.write(queued_file.read())
  
 -    queue_store.delete_file(queued_filepath)
 +    mgg.queue_store.delete_file(queued_filepath)
+     entry['queued_media_file'] = []
      media_files_dict = entry.setdefault('media_files', {})
      media_files_dict['thumb'] = thumb_filepath
      media_files_dict['main'] = main_filepath