[meld] Move installation check into VC modules



commit ac78779f81eab71f75176dbb2697ee655c071f69
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Aug 18 07:20:58 2013 +1000

    Move installation check into VC modules

 meld/vc/_vc.py |    8 ++++++++
 meld/vc/git.py |    9 +++++++++
 meld/vcview.py |   11 +----------
 3 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 46b8cf4..34b5223 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -264,6 +264,14 @@ class Vc(object):
             return None
         return vc_files[0]
 
+    @classmethod
+    def is_installed(cls):
+        try:
+            popen([cls.CMD])
+            return True
+        except:
+            return False
+
 
 class CachedVc(Vc):
 
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 7bb6ed6..59e245f 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -69,6 +69,15 @@ class Vc(_vc.CachedVc):
         self._tree_cache = {}
         self._tree_meta_cache = {}
 
+    @classmethod
+    def is_installed(cls):
+        try:
+            proc = _vc.popen([cls.CMD, '--version'])
+            assert proc.read().startswith('git version')
+            return True
+        except:
+            return False
+
     def check_repo_root(self, location):
         # Check exists instead of isdir, since .git might be a git-file
         if not os.path.exists(os.path.join(location, self.VC_DIR)):
diff --git a/meld/vcview.py b/meld/vcview.py
index 3c5ea90..4573e44 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -328,16 +328,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
             # tool and display a basic error message in the drop-down menu.
             err_str = ""
 
-            def vc_installed(cmd):
-                if not cmd:
-                    return True
-                try:
-                    return not vc._vc.call(["which", cmd])
-                except OSError:
-                    if os.name == 'nt':
-                        return not vc._vc.call(["where", cmd])
-
-            if not vc_installed(avc.CMD):
+            if not avc.is_installed():
                 # 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)


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