Commits

Anonymous committed 15fa273

move utility functions into new module

Comments (0)

Files changed (3)

tortoise/contextmenu.py

 import win32api
 import _winreg
 from mercurial import hg, ui, repo
-import re
 import gpopen
+from thgutil import *
 
 GUI_SHELL = 'guishell'
 
 S_OK = 0
 S_FALSE = 1
 
-_quotere = None
-def shellquote(s):
-    global _quotere
-    if _quotere is None:
-        _quotere = re.compile(r'(\\*)("|\\$)')
-    return '"%s"' % _quotere.sub(r'\1\1\\\2', s)
-    return "'%s'" % s.replace("'", "'\\''")
-
-def find_path(pgmname):
-    """ return first executable found in search path """
-    ospath = os.environ['PATH'].split(os.pathsep)
-    pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
-    pathext = pathext.lower().split(os.pathsep)
-
-    for path in ospath:
-        for ext in pathext:
-            ppath = os.path.join(path, pgmname + ext)
-            if os.path.exists(ppath):
-                return ppath
-
-    return None
-
-def find_root(path):
-    p = os.path.isdir(path) and path or os.path.dirname(path)
-    while not os.path.isdir(os.path.join(p, ".hg")):
-        oldp = p
-        p = os.path.dirname(p)
-        if p == oldp:
-            return None
-    return p
-
 def get_clone_repo_name(dir, repo_name):
     dest_clone = os.path.join(dir, repo_name)
     if os.path.exists(dest_clone):

tortoise/iconoverlay.py

 from win32com.shell import shell, shellcon
 import _winreg
 from mercurial import hg, repo, ui, cmdutil, util
+import thgutil
 
 UNCHANGED = "unchanged"
 ADDED = "added"
 
 CACHE_TIMEOUT = 1000
 
-def find_root(path):
-    p = os.path.isdir(path) and path or os.path.dirname(path)
-    while not os.path.isdir(os.path.join(p, ".hg")):
-        oldp = p
-        p = os.path.dirname(p)
-        if p == oldp:
-            return None
-    return p
-
 class IconOverlayExtension(object):
     """
     Class to implement icon overlays for source controlled files.
             return IconOverlayExtension.last_status
 
         # open repo
-        root = find_root(path)
+        root = thgutil.find_root(path)
         print "_get_state: root = ", root
         if root is None:
             print "_get_state: not in repo"

tortoise/thgutil.py

+"""
+util.py - TortoiseHg utility functions
+ Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
+
+This software may be used and distributed according to the terms
+of the GNU General Public License, incorporated herein by reference.
+
+"""
+
+import os.path, re
+
+_quotere = None
+def shellquote(s):
+    global _quotere
+    if _quotere is None:
+        _quotere = re.compile(r'(\\*)("|\\$)')
+    return '"%s"' % _quotere.sub(r'\1\1\\\2', s)
+    return "'%s'" % s.replace("'", "'\\''")
+
+def find_path(pgmname):
+    """ return first executable found in search path """
+    ospath = os.environ['PATH'].split(os.pathsep)
+    pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
+    pathext = pathext.lower().split(os.pathsep)
+
+    for path in ospath:
+        for ext in pathext:
+            ppath = os.path.join(path, pgmname + ext)
+            if os.path.exists(ppath):
+                return ppath
+
+    return None
+
+def find_root(path):
+    p = os.path.isdir(path) and path or os.path.dirname(path)
+    while not os.path.isdir(os.path.join(p, ".hg")):
+        oldp = p
+        p = os.path.dirname(p)
+        if p == oldp:
+            return None
+    return p