Comment 2 for bug 384974

Revision history for this message
Stani (stani) wrote :

Very good bug report, thanks! Luckily it was only for metadata saving, not for regular actions.

$ bzr diff
=== modified file 'phatch/core/api.py'
--- phatch/core/api.py 2009-06-08 18:55:29 +0000
+++ phatch/core/api.py 2009-06-09 14:43:36 +0000
@@ -291,8 +291,14 @@
 def flush_metadata(photo,image_file,result):
     try:
         photo.flush_metadata()
+ result['skip'] = False
+ result['abort'] = False
+ #log non fatal errors/warnings
+ flush_log(photo, image_file)
+ return photo, result
     except Exception, details:
- folder, image = os.path.split(ensure_unicode(image_file))
+ photo.metadata = {}
+ folder, image = os.path.split(ensure_unicode(image_file))
         reason = exception_to_unicode(details)
         message = u'%s\n%s\n\n%s'%(
             _("Can not write metadata to image '%s' in folder:")%image,
@@ -301,7 +307,6 @@
         )
         return process_error(photo,message,image_file,action=None,
             result=result,ignore=True)
- flush_log(photo, image_file)

 def apply_action(action,photo,setting,cache,image_file,result):
@@ -321,8 +326,8 @@
             folder,
             reason,
         )
- ignore = True
- return process_error(photo,message,image_file,action,result,ignore)
+ return process_error(photo,message,image_file,action,
+ result,ignore=True)

 def apply_actions(actions,settings,paths=None,drop=False):
     """Do all the actions."""
@@ -407,7 +412,10 @@
         #do the actions
         for action_index, action in enumerate(actions):
             if action.flush_metadata_before:
- flush_metadata(photo,image_file,result)
+ photo, result = flush_metadata(photo,image_file,result)
+ if result['abort']: return
+ elif result['skip']:
+ break
             #update progress
             progress_result = {}
             send.progress_update_index(progress_result,image_index,action_index)
@@ -421,9 +429,9 @@
             if result['abort']: return
             elif result['skip']:
                 break
- flush_metadata(photo,image_file,result)
- flush_log(photo, image_file, action)
+ photo, result = flush_metadata(photo,image_file,result)
         del photo, progress_result, action_index, action
+ if result['abort']: return
     send.progress_close()
     #mention amount of photos and duration
     delta = time.time()-start

=== modified file 'phatch/core/lib/_pyexiv2.py'
--- phatch/core/lib/_pyexiv2.py 2009-06-09 13:56:09 +0000
+++ phatch/core/lib/_pyexiv2.py 2009-06-09 14:02:24 +0000
@@ -145,7 +145,7 @@
     if ext:
         format = ext.upper()
     if (format and not(format in WRITE_EXIF+WRITE_IPTC)):
- return 'pyexiv2: writing metadata to %s is not supported'%format
+ raise Exception('pyexiv2: writing metadata to %s is not supported'%format)
     image = pyexiv2.Image(path)
     image.readMetadata()
     warnings = []

=== modified file 'phatch/core/pil.py'
--- phatch/core/pil.py 2009-06-09 04:21:16 +0000
+++ phatch/core/pil.py 2009-06-09 13:58:48 +0000
@@ -434,7 +434,8 @@
         #throw an error if pyexiv2 is not installed
         if not exif:
             raise ImportError(NEEDS_PYEXIV2)
- self.log += exif.flush(self.info['path'],self.metadata)
+ self.log += exif.flush(self.info['path'],self.metadata,
+ self.info['Pil.Format'])
         #as metadata has changed, use new source
         self.metadata = {}

$ bzr commit -m "fixing error dialog buttons for metadata"
Committing to: /home/stani/sync/python/phatch/trunk/
modified phatch/core/api.py
modified phatch/core/pil.py
modified phatch/core/lib/_pyexiv2.py
Committed revision 709.