[Pkg-bazaar-commits] ./bzr-gtk/unstable r434: Better errors, merge directive saving

Aaron Bentley aaron at aaronbentley.com
Fri Apr 10 07:44:55 UTC 2009


------------------------------------------------------------
revno: 434
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: gtk-applymerge
timestamp: Wed 2008-02-27 00:23:50 -0500
message:
  Better errors, merge directive saving
modified:
  __init__.py
  diff.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-02-23 07:26:04 +0000
+++ b/__init__.py	2008-02-27 05:23:50 +0000
@@ -685,19 +685,26 @@
     takes_args = ['path']
 
     def run(self, path):
-        from bzrlib.plugins.gtk.diff import DiffWindow, MergeDirectiveWindow
-        lines = open(path, 'rb').readlines()
         try:
-            directive = merge_directive.MergeDirective.from_lines(lines)
-        except errors.NotAMergeDirective:
-            window = DiffWindow()
-            window.set_diff_text(path, lines)
-        else:
-            window = MergeDirectiveWindow(directive)
-            window.set_diff_text(path, directive.patch.splitlines(True))
-        window.show()
-        gtk = self.open_display()
-        window.connect("destroy", gtk.main_quit)
+            from bzrlib.plugins.gtk.diff import (DiffWindow,
+                                                 MergeDirectiveWindow)
+            lines = open(path, 'rb').readlines()
+            lines = [l.replace('\r\n', '\n') for l in lines]
+            try:
+                directive = merge_directive.MergeDirective.from_lines(lines)
+            except errors.NotAMergeDirective:
+                window = DiffWindow()
+                window.set_diff_text(path, lines)
+            else:
+                window = MergeDirectiveWindow(directive, path)
+                window.set_diff_text(path, directive.patch.splitlines(True))
+            window.show()
+            gtk = self.open_display()
+            window.connect("destroy", gtk.main_quit)
+        except Exception, e:
+            from dialog import error_dialog
+            error_dialog('Error', str(e))
+            raise
         gtk.main()
 
 

=== modified file 'diff.py'
--- a/diff.py	2008-02-23 07:26:04 +0000
+++ b/diff.py	2008-02-27 05:23:50 +0000
@@ -30,7 +30,13 @@
 except ImportError:
     have_gconf = False
 
-from bzrlib import merge as _mod_merge, osutils, progress, workingtree
+from bzrlib import (
+    merge as _mod_merge,
+    osutils,
+    progress,
+    urlutils,
+    workingtree,
+)
 from bzrlib.diff import show_diff_trees, internal_diff
 from bzrlib.errors import NoSuchFile
 from bzrlib.patches import parse_patches
@@ -463,10 +469,11 @@
 
 class MergeDirectiveWindow(DiffWindow):
 
-    def __init__(self, directive, parent=None):
-        DiffWindow.__init__(self, parent)
+    def __init__(self, directive, path):
+        DiffWindow.__init__(self, None)
         self._merge_target = None
         self.directive = directive
+        self.path = path
 
     def _get_button_bar(self):
         """The button bar has only the Merge button"""
@@ -475,9 +482,15 @@
         merge_button.set_relief(gtk.RELIEF_NONE)
         merge_button.connect("clicked", self.perform_merge)
 
+        save_button = gtk.Button('Save')
+        save_button.show()
+        save_button.set_relief(gtk.RELIEF_NONE)
+        save_button.connect("clicked", self.perform_save)
+
         hbox = gtk.HButtonBox()
         hbox.set_layout(gtk.BUTTONBOX_START)
         hbox.pack_start(merge_button, expand=False, fill=True)
+        hbox.pack_start(save_button, expand=False, fill=True)
         hbox.show()
         return hbox
 
@@ -527,6 +540,33 @@
             d.destroy()
         return workingtree.WorkingTree.open(uri)
 
+    def perform_save(self, window):
+        d = gtk.FileChooserDialog('Save As', self,
+                                  gtk.FILE_CHOOSER_ACTION_SAVE,
+                                  buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
+                                           gtk.STOCK_CANCEL,
+                                           gtk.RESPONSE_CANCEL,))
+        d.set_current_name(osutils.basename(self.path))
+        try:
+            try:
+                result = d.run()
+                if result != gtk.RESPONSE_OK:
+                    raise SelectCancelled()
+                uri = d.get_uri()
+            finally:
+                d.destroy()
+        except SelectCancelled:
+            return
+        source = open(self.path, 'rb')
+        try:
+            target = open(urlutils.local_path_from_url(uri), 'wb')
+            try:
+                target.write(source.read())
+            finally:
+                target.close()
+        finally:
+            source.close()
+
 
 def _iter_changes_to_status(source, target):
     """Determine the differences between trees.



More information about the Pkg-bazaar-commits mailing list