Commits

TK Soh  committed b2410fa

help Popen() find hg.bat in PATH

  • Participants
  • Parent commits 4ad42d8

Comments (0)

Files changed (1)

File tortoise/contextmenu.py

             # string into the correct encoding depending on the flags.
             return self._handlers[cmd][0]
         return S_FALSE
+
+    def _find_path(self, pgmname):
+        ospath = os.environ['PATH']
+        plist = []
+        for path in ospath.split(';'):
+            for ext in ['exe', 'bat', 'cmd']:
+                ppath = os.path.join(path, "%s.%s" % (pgmname, ext))
+                #print "checking path: %s" % ppath
+                if os.path.exists(ppath):
+                    plist.append(ppath)
+
+        if plist:
+            #print "path found: %s" % ", ".join(plist)
+            return plist[0]
+        else:
+            return None
+
         
     def _checkout(self, parent_window):
         import checkout
         else:
             dir = os.path.dirname(path)
         os.chdir(dir)
-
-        subprocess.Popen(['hg', 'qct'])
-        print "popened 'hg qct'"
+        
+        hgpath = self._find_path('hg')
+        if hgpath:
+            subprocess.Popen(['hg', 'qct'])
+            print "popened 'hg qct'"
 
     def _diff(self, parent_window):
         import os, subprocess
             dir = path
         else:
             dir = os.path.dirname(path)
+
         print "chdir to %s" % dir
         os.chdir(dir)
         print "cwd = %s" % os.getcwd()
-        subprocess.Popen(['hg', 'extdiff'])
-        print "popened 'hg extdiff'"
+        
+        hgpath = self._find_path('hg')
+        if hgpath:
+            subprocess.Popen([hgpath, 'extdiff', '.'])
+            print "popened 'hg extdiff'"
 
     def _view(self, parent_window):
         import os, subprocess
             dir = os.path.dirname(path)
         os.chdir(dir)
         
-        subprocess.Popen(['hg', 'view'])
-        print "popened 'hg view'"
+        hgpath = self._find_path('hg')
+        if hgpath:
+            subprocess.Popen([hgpath, 'view'])
+            print "popened 'hg view'"