[py-svn] r57319 - py/branch/event/py/misc

hpk at codespeak.net hpk at codespeak.net
Sat Aug 16 17:08:26 CEST 2008


Author: hpk
Date: Sat Aug 16 17:08:24 2008
New Revision: 57319

Modified:
   py/branch/event/py/misc/_dist.py
Log:
merge 56743 and 56749 from trunk(ghum's fixes to PATH handling on windows) 


Modified: py/branch/event/py/misc/_dist.py
==============================================================================
--- py/branch/event/py/misc/_dist.py	(original)
+++ py/branch/event/py/misc/_dist.py	Sat Aug 16 17:08:24 2008
@@ -97,12 +97,48 @@
     
     # Add py/bin to PATH environment variable
     bindir = os.path.join(sysconfig.get_python_lib(), "py", "bin", "win32")
+    
+    # check for the user path
+    ureg = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
+    ukey = r"Environment"
+    
+    # not every user has his own path on windows
+    try:
+        upath = get_registry_value(ureg, ukey, "PATH")
+    except WindowsError:
+        upath=""
+    # if bindir allready in userpath -> do nothing
+    if bindir in upath: 
+        return
+    
     reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
     key = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
     path = get_registry_value(reg, key, "Path")
+    # if bindir allready in systempath -> do nothing
+    if bindir in path:
+        return 
     path += ";" + bindir
     print "Setting PATH to:", path
-    set_registry_value(reg, key, "Path", path)
+    
+    pathset=False
+    try:
+        set_registry_value(reg, key, "PATH", path)
+        pathset=True
+    except WindowsError:
+        print "cannot set systempath, falling back to userpath"
+        pass
+    
+    if not pathset:
+        try:
+            if len(upath)>0: #if no user path present
+                upath += ";" 
+            upath+=bindir
+            set_registry_value(ureg, ukey, "Path", upath)
+            pathset=True
+        except WindowsError:
+            print "cannot set userpath, please add %s to your path" % (bindir,)
+            return
+            
     #print "Current PATH is:", get_registry_value(reg, key, "Path")
 
     # Propagate changes throughout the system



More information about the pytest-commit mailing list