very rough working version of image reprocessing
authorRodney Ewing <ewing.rj@gmail.com>
Fri, 2 Aug 2013 20:18:35 +0000 (13:18 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:14 +0000 (15:30 -0700)
mediagoblin/media_types/image/__init__.py
mediagoblin/media_types/image/processing.py
mediagoblin/processing/__init__.py

index 3a05671894bd7e3ca39da0ca0d98fdd681251da9..1aff21d4ebceecb77a49ea19d156206e5fb69cba 100644 (file)
@@ -86,7 +86,8 @@ def _parser(args):
         '--resize')
     parser.add_argument(
         '--size',
-        nargs=2)
+        nargs=2,
+        type=int)
     parser.add_argument(
         '--initial_processing',
         action='store_true')
@@ -103,14 +104,14 @@ def _check_eligible(entry_args, reprocess_args):
     if entry_args.state == 'failed':
         if reprocess_args.resize:
             raise Exception(_('You can not run --resize on media that has not'
-                              'been processed.'))
+                              ' been processed.'))
         if reprocess_args.size:
             _log.warn('With --initial_processing, the --size flag will be'
                       ' ignored.')
 
     if entry_args.state == 'processing':
         raise Exception(_('We currently do not support reprocessing on media'
-                          'that is in the "processing" state.'))
+                          ' that is in the "processing" state.'))
 
 
 def media_reprocess(args):
@@ -133,15 +134,15 @@ def media_reprocess(args):
                 # For now we can only reprocess with the original file
                 if not entry.media_files.get('original'):
                     raise Exception(_('The original file for this media entry'
-                                      'does not exist.'))
+                                      ' does not exist.'))
 
                 reprocess_info = {'resize': reprocess_args.resize}
 
-                if reprocess_args.size and len(reprocess_args.size) == 2:
+                if reprocess_args.size:
                     reprocess_info['max_width'] = reprocess_args.size[0]
                     reprocess_info['max_height'] = reprocess_args.size[1]
 
-                run_process_media(entry, reprocess_info)
+                run_process_media(entry, reprocess_info=reprocess_info)
 
         else:
             raise Exception(_('The --resize flag must set either "thumb"'
index 4f619f47f4611e16e6e5c8ba206884dbc64393d3..18b8bd4e9c7f9ef376e6e9f75b519f2e265a903c 100644 (file)
@@ -73,10 +73,8 @@ def resize_image(proc_state, resized, keyname, target_name, new_size,
     proc_state.store_public(keyname, tmp_resized_filename, target_name)
 
 
-def resize_tool(proc_state, force, keyname, target_name,
+def resize_tool(proc_state, force, keyname, filename, target_name,
                 conversions_subdir, exif_tags, new_size=None):
-    # filename -- the filename of the original image being resized
-    filename = proc_state.get_queued_filename()
     if not new_size:
         max_width = mgg.global_config['media:' + keyname]['max_width']
         max_height = mgg.global_config['media:' + keyname]['max_height']
@@ -90,8 +88,8 @@ def resize_tool(proc_state, force, keyname, target_name,
     except IOError:
         raise BadMediaFail()
     if force \
-        or im.size[0] > max_width \
-        or im.size[1] > max_height \
+        or im.size[0] > new_size[0]\
+        or im.size[1] > new_size[1]\
         or exif_image_needs_rotation(exif_tags):
         resize_image(
             proc_state, im, unicode(keyname), target_name,
@@ -129,8 +127,7 @@ def process_image(proc_state, reprocess_info=None):
     """
     entry = proc_state.entry
     workbench = proc_state.workbench
-    import ipdb
-    ipdb.set_trace()
+
     # Conversions subdirectory to avoid collisions
     conversions_subdir = os.path.join(
         workbench.dir, 'conversions')
@@ -148,12 +145,12 @@ def process_image(proc_state, reprocess_info=None):
         gps_data = get_gps_data(exif_tags)
 
         # Always create a small thumbnail
-        resize_tool(proc_state, True, 'thumb',
+        resize_tool(proc_state, True, 'thumb', queued_filename,
                     name_builder.fill('{basename}.thumbnail{ext}'),
                     conversions_subdir, exif_tags)
 
         # Possibly create a medium
-        resize_tool(proc_state, False, 'medium',
+        resize_tool(proc_state, False, 'medium', queued_filename,
                     name_builder.fill('{basename}.medium{ext}'),
                     conversions_subdir, exif_tags)
 
@@ -183,19 +180,16 @@ def _reprocess_image(proc_state, reprocess_info, conversions_subdir):
 
     if reprocess_info.get('max_width'):
         max_width = reprocess_info['max_width']
+        max_height = reprocess_info['max_height']
     else:
         max_width = mgg.global_config \
             ['media:' + reprocess_info['resize']]['max_width']
-
-    if reprocess_info.get('max_height'):
-        max_height = reprocess_info['max_height']
-    else:
         max_height = mgg.global_config \
             ['media:' + reprocess_info['resize']]['max_height']
 
     new_size = (max_width, max_height)
 
-    resize_tool(proc_state, False, reprocess_info['resize'],
+    resize_tool(proc_state, False, reprocess_info['resize'], reprocess_filename,
                 name_builder.fill('{basename}.thumbnail{ext}'),
                 conversions_subdir, exif_tags, new_size)
 
index bbe9f364999b22b038b1165a39a65b7d297ac6d6..13c677ebfaf4498fcdac9f10b3a89d110fd9d8c9 100644 (file)
@@ -138,10 +138,10 @@ class ProcessingState(object):
         if self.reprocess_filename is not None:
             return self.reprocess_filename
 
-        reprocess_filepath = self.entry.media_files['original'][2]
-        reprocess_filename = self.workbench.local_file(
+        reprocess_filepath = self.entry.media_files['original']
+        reprocess_filename = self.workbench.localized_file(
             mgg.public_store, reprocess_filepath,
-            'original')
+            'source')
         self.reprocess_filename = reprocess_filename
         return reprocess_filename