booh-classifier: on failure to cp/mv, propose to continue or to continue to all these...
authorGuillaume Cottenceau <gcottenc@gmail.com>
Wed, 5 Jan 2011 21:44:05 +0000 (22:44 +0100)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Wed, 5 Jan 2011 21:44:05 +0000 (22:44 +0100)
bin/booh-classifier

index b047b79..350eee8 100644 (file)
@@ -893,10 +893,14 @@ def show_popup(parent, msg, *options)
     end
     if options[:okcancel]
         cancel = dialog.add_button(Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL)
+        dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
+    elsif options[:yestoall]
+        cancel = dialog.add_button(Gtk::Stock::NO, Gtk::Dialog::RESPONSE_NO)
         if ! options[:bottomwidget]
             cancel.grab_focus
         end
-        dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
+        dialog.add_button(Gtk::Stock::YES, Gtk::Dialog::RESPONSE_YES)
+        dialog.add_button(utf8(_("Yes to all")), Gtk::Dialog::RESPONSE_ACCEPT)
     else
         ok = dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK).grab_focus
         if ! options[:bottomwidget]
@@ -939,6 +943,8 @@ def show_popup(parent, msg, *options)
             dialog.destroy
             if options[:okcancel]
                 return response == Gtk::Dialog::RESPONSE_OK
+            elsif options[:yestoall]
+                return response == Gtk::Dialog::RESPONSE_YES ? 'yes' : response == Gtk::Dialog::RESPONSE_ACCEPT ? 'yestoall' : 'no'
             end
         }
     else
@@ -1630,16 +1636,36 @@ def execute
                     begin
                         moved = 0
                         copied = 0
+                        ignored_errors = []
                         stuff.keys.each { |key|
                             if key.is_a?(Label) && stuff[key][:combo] && stuff[key][:combo].active <= 1
                                 destination = stuff[key][:pathlabel].text
                                 label2entries[key].each { |entry|
                                     if stuff[key][:combo].active == 0
-                                        system("cp -dp '#{entry.path}' '#{destination}'") or raise "failed to copy '#{entry.path}'"
-                                        copied += 1
+                                        result = `cp -dp '#{entry.path}' '#{destination}' 2>&1`
                                     elsif stuff[key][:combo].active == 1
-                                        system("mv '#{entry.path}' '#{destination}'") or raise "failed to move '#{entry.path}'"
-                                        moved += 1
+                                        result = `mv '#{entry.path}' '#{destination}' 2>&1`
+                                    end
+                                    if $?.exitstatus > 0
+                                        simplified_error = result.sub(/#{Regexp.quote(destination + '/' + File.basename(entry.path))}/, '').  #'
+                                                                  sub(/#{Regexp.quote(entry.path)}/, '').
+                                                                  sub(/#{Regexp.quote(File.basename(entry.path))}/, '')
+                                        if ! ignored_errors.include?(simplified_error)
+                                            response = show_popup($main_window,
+                                                                  utf8(_("Failure:\n\n%s\nDo you wish to continue?" % result)),
+                                                                  { :yestoall => true })
+                                            if response == 'no'
+                                                raise "failure on '#{entry.path}'"
+                                            elsif response == 'yestoall'
+                                                ignored_errors << simplified_error
+                                            end
+                                        end
+                                    else
+                                        if stuff[key][:combo].active == 0
+                                            copied += 1
+                                        else
+                                            moved += 1
+                                        end
                                     end
                                 }
                             end
@@ -1654,8 +1680,7 @@ def execute
                             }
                         end
                     rescue
-                        msg 1, "woops: #{$!}"
-                        show_popup(dialog, utf8(_("Unexpected error: '%s'.") % $!))
+                        msg 1, "woops: #{$!}\n" + $@.join("\n")
                     end
                     show_popup(dialog, utf8(_("Successfully moved %d files, copied %d file, and removed %d files.") % [ moved, copied, removed ]))
                     dialog.destroy