From: Christopher Allan Webber Date: Mon, 12 Aug 2013 13:57:56 +0000 (-0500) Subject: Factored the get_orig_filename from processing state and put it to use. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=eb372949a13c67962e7460e2411f389ff87d2661;p=mediagoblin.git Factored the get_orig_filename from processing state and put it to use. This commit sponsored by Vincent Demeester. Thank you! --- diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index b8ac1a60..35069af4 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -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) diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index 47f0b84e..9466aec6 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -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