Factored the get_orig_filename from processing state and put it to use.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 12 Aug 2013 13:57:56 +0000 (08:57 -0500)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:16 +0000 (15:30 -0700)
This commit sponsored by Vincent Demeester.  Thank you!

mediagoblin/media_types/image/processing.py
mediagoblin/processing/__init__.py

index b8ac1a601a32b0df1b34e0aebc230b8401a8511a..35069af44728d5ac41d6c501b50357269f85b802 100644 (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)
index 47f0b84e92abcc4e8d1d40383b5e8d62d0719259..9466aec6fb75cecfcab2a6bde039d19915e218c1 100644 (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