Merge remote-tracking branch 'refs/remotes/spaetz/561_use_workbench_not_tempfiles'

This commit is contained in:
Christopher Allan Webber 2013-01-16 11:23:38 -06:00
commit 3c5f583707
2 changed files with 10 additions and 8 deletions

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging import logging
import tempfile from tempfile import NamedTemporaryFile
import os import os
from mediagoblin import mg_globals as mgg from mediagoblin import mg_globals as mgg
@ -73,7 +73,7 @@ def process_audio(entry):
transcoder = AudioTranscoder() transcoder = AudioTranscoder()
with tempfile.NamedTemporaryFile() as webm_audio_tmp: with NamedTemporaryFile(dir=workbench.dir) as webm_audio_tmp:
progress_callback = ProgressCallback(entry) progress_callback = ProgressCallback(entry)
transcoder.transcode( transcoder.transcode(
@ -99,7 +99,7 @@ def process_audio(entry):
original=os.path.splitext( original=os.path.splitext(
queued_filepath[-1])[0])) queued_filepath[-1])[0]))
with tempfile.NamedTemporaryFile(suffix='.ogg') as wav_tmp: with NamedTemporaryFile(dir=workbench.dir, suffix='.ogg') as wav_tmp:
_log.info('Creating OGG source for spectrogram') _log.info('Creating OGG source for spectrogram')
transcoder.transcode( transcoder.transcode(
queued_filename, queued_filename,
@ -109,7 +109,7 @@ def process_audio(entry):
thumbnailer = AudioThumbnailer() thumbnailer = AudioThumbnailer()
with tempfile.NamedTemporaryFile(suffix='.jpg') as spectrogram_tmp: with NamedTemporaryFile(dir=workbench.dir, suffix='.jpg') as spectrogram_tmp:
thumbnailer.spectrogram( thumbnailer.spectrogram(
wav_tmp.name, wav_tmp.name,
spectrogram_tmp.name, spectrogram_tmp.name,
@ -122,7 +122,7 @@ def process_audio(entry):
entry.media_files['spectrogram'] = spectrogram_filepath entry.media_files['spectrogram'] = spectrogram_filepath
with tempfile.NamedTemporaryFile(suffix='.jpg') as thumb_tmp: with NamedTemporaryFile(dir=workbench.dir, suffix='.jpg') as thumb_tmp:
thumbnailer.thumbnail_spectrogram( thumbnailer.thumbnail_spectrogram(
spectrogram_tmp.name, spectrogram_tmp.name,
thumb_tmp.name, thumb_tmp.name,

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import tempfile from tempfile import NamedTemporaryFile
import logging import logging
from mediagoblin import mg_globals as mgg from mediagoblin import mg_globals as mgg
@ -74,7 +74,7 @@ def process_video(entry):
entry, name_builder.fill('{basename}.thumbnail.jpg')) entry, name_builder.fill('{basename}.thumbnail.jpg'))
# Create a temporary file for the video destination # Create a temporary file for the video destination
tmp_dst = tempfile.NamedTemporaryFile() tmp_dst = NamedTemporaryFile(dir=workbench.dir)
with tmp_dst: with tmp_dst:
# Transcode queued file to a VP8/vorbis file that fits in a 640x640 square # Transcode queued file to a VP8/vorbis file that fits in a 640x640 square
@ -88,6 +88,7 @@ def process_video(entry):
# Push transcoded video to public storage # Push transcoded video to public storage
_log.debug('Saving medium...') _log.debug('Saving medium...')
# TODO (#419, we read everything in RAM here!)
mgg.public_store.get_file(medium_filepath, 'wb').write( mgg.public_store.get_file(medium_filepath, 'wb').write(
tmp_dst.read()) tmp_dst.read())
_log.debug('Saved medium') _log.debug('Saved medium')
@ -100,7 +101,7 @@ def process_video(entry):
height=transcoder.dst_data.videoheight) height=transcoder.dst_data.videoheight)
# Create a temporary file for the video thumbnail # Create a temporary file for the video thumbnail
tmp_thumb = tempfile.NamedTemporaryFile(suffix='.jpg') tmp_thumb = NamedTemporaryFile(dir=workbench.dir, suffix='.jpg')
with tmp_thumb: with tmp_thumb:
# Create a thumbnail.jpg that fits in a 180x180 square # Create a thumbnail.jpg that fits in a 180x180 square
@ -129,6 +130,7 @@ def process_video(entry):
with mgg.public_store.get_file(original_filepath, 'wb') as \ with mgg.public_store.get_file(original_filepath, 'wb') as \
original_file: original_file:
_log.debug('Saving original...') _log.debug('Saving original...')
# TODO (#419, we read everything in RAM here!)
original_file.write(queued_file.read()) original_file.write(queued_file.read())
_log.debug('Saved original') _log.debug('Saved original')