Factored the get_orig_filename from processing state and put it to use.

This commit sponsored by Vincent Demeester.  Thank you!
This commit is contained in:
Christopher Allan Webber 2013-08-12 08:57:56 -05:00 committed by Rodney Ewing
parent 22479c39a0
commit eb372949a1
2 changed files with 44 additions and 2 deletions

View File

@ -27,7 +27,7 @@ from mediagoblin.db.models import MediaEntry
from mediagoblin.processing import (
BadMediaFail, FilenameBuilder,
MediaProcessor, ProcessingManager,
request_from_args)
request_from_args, get_orig_filename)
from mediagoblin.submit.lib import run_process_media
from mediagoblin.tools.exif import exif_fix_image_orientation, \
extract_exif, clean_exif, get_gps_data, get_useful, \
@ -325,8 +325,15 @@ class CommonImageProcessor(MediaProcessor):
help=(
"Height of the resized image (if not using defaults)"))
def setup_workbench_subdirs(self):
# Conversions subdirectory to avoid collisions
self.conversions_subdir = os.path.join(
self.workbench.dir, 'convirsions')
def fetch_original(self):
pass
self.orig_filename = get_orig_filename(
self.entry, self.workbench)
self.name_builder = FilenameBuilder(self.orig_filename)
def generate_medium_if_applicable(self, size=None):
pass
@ -374,6 +381,7 @@ class InitialProcessor(CommonImageProcessor):
def process(self, size=None, thumb_size=None):
self.setup_workbench_subdirs()
self.fetch_original()
self.generate_medium_if_applicable(size=size)
self.generate_thumb(size=thumb_size)

View File

@ -372,6 +372,40 @@ def mark_entry_failed(entry_id, exc):
u'fail_metadata': {}})
###############################################################################
# refactoring procstate stuff here
def get_orig_filename(entry, workbench):
"""
Get the a filename for the original, on local storage
If the media entry has a queued_media_file, use that, otherwise
use the original.
In the future, this will return the highest quality file available
if neither the original or queued file are available by checking
some ordered list of preferred keys.
"""
if entry.queued_media_file:
orig_filepath = entry.queued_media_file
storage = mgg.queue_store
else:
orig_filepath = entry.media_files['original']
storage = mgg.public_store
orig_filename = workbench.localized_file(
storage, orig_filepath,
'source')
return orig_filename
# end refactoring
###############################################################################
class BaseProcessingFail(Exception):
"""
Base exception that all other processing failure messages should