[PATCH v2 2/3] vc: Check for installed version control tools before use



Previously, meld blindly assumed that the proper version control software
was always installed.  This causes issues when the proper version control
software isn't installed.  For example, if 'bzr' is not installed,
running "meld ./" in a bzr repository would result in an error such as:

...
  File "/home/ptyser/meld_git/meld/meld/vc/_vc.py", line 194, in popen
    return subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE).stdout
  File "/usr/lib/python2.5/subprocess.py", line 594, in __init__
    errread, errwrite)
  File "/usr/lib/python2.5/subprocess.py", line 1147, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

This patch forces meld to check if the proper version control software is
installed before running any version control commands.

Signed-off-by: Peter Tyser <ptyser gmail com>
---
Changes since v1:
- Add a translation comment
- Attempt to fix error string concatenation to better support translation

 meld/vcview.py |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/meld/vcview.py b/meld/vcview.py
index 9f93a91..c8800b5 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -203,10 +203,11 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         # VC ComboBox
         self.combobox_vcs = gtk.ComboBox()
         self.combobox_vcs.lock = True
-        self.combobox_vcs.set_model(gtk.ListStore(str, object))
+        self.combobox_vcs.set_model(gtk.ListStore(str, object, bool))
         cell = gtk.CellRendererText()
         self.combobox_vcs.pack_start(cell, False)
         self.combobox_vcs.add_attribute(cell, 'text', 0)
+        self.combobox_vcs.add_attribute(cell, 'sensitive', 2)
         self.combobox_vcs.lock = False
         self.hbox2.pack_end(self.combobox_vcs, expand=False)
         self.combobox_vcs.show()
@@ -235,7 +236,21 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
             if (self.vc is not None and
                 self.vc.__class__ == avc.__class__):
                 default_active = idx
-            self.combobox_vcs.get_model().append([avc.NAME, avc])
+
+            # See if the necessary version control command exists.  If not,
+            # make the version control choice non-selectable.
+            err_str = ""
+            if vc._vc.call(["which", avc.CMD]):
+                # TRANSLATORS: this is an error message when a version control
+                # application isn't installed or can't be found
+                err_str = _("%s Not Installed" % avc.CMD)
+
+            if err_str:
+                self.combobox_vcs.get_model().append( \
+                        [_("%s (%s)") % (avc.NAME, err_str), avc, False])
+            else:
+                self.combobox_vcs.get_model().append([avc.NAME, avc, True])
+
         if gtk.pygtk_version >= (2, 12, 0):
             self.combobox_vcs.set_tooltip_text(tooltip_texts[len(vcs) == 1])
         self.combobox_vcs.set_sensitive(len(vcs) > 1)
-- 
1.7.1.13.gcfb88



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]