[py-svn] r12034 - py/dist/py/misc
ggheo at codespeak.net
ggheo at codespeak.net
Fri May 6 23:20:21 CEST 2005
Author: ggheo
Date: Fri May 6 23:20:21 2005
New Revision: 12034
Modified:
py/dist/py/misc/_dist.py
Log:
Added win32-specific functionality:
- add <python_install_dir>\Lib\site-packages\py\test\bin to Path registry value in Environment registry key
- propagate changes to current command prompt
Modified: py/dist/py/misc/_dist.py
==============================================================================
--- py/dist/py/misc/_dist.py (original)
+++ py/dist/py/misc/_dist.py Fri May 6 23:20:21 2005
@@ -1,8 +1,14 @@
import py
-import sys
+import sys, os
from distutils import sysconfig
from distutils import core
+winextensions = 1
+if sys.platform == 'win32':
+ try:
+ import _winreg, win32gui, win32con
+ except ImportError:
+ winextensions = 0
class Params:
""" a crazy hack to convince distutils to please
@@ -65,7 +71,7 @@
# scripts.remove('py/bin/py.test')
#
-# helpers:
+### helpers:
def checknonsvndir(p):
if p.basename != '.svn' and p.check(dir=1):
return True
@@ -85,6 +91,41 @@
print "data file ", x
print
+def addbindir2path():
+ if sys.platform != 'win32' or not winextensions:
+ return
+
+ # Add py/bin to PATH environment variable
+ bindir = os.path.join(sysconfig.get_python_lib(), "py", "bin")
+ reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
+ key = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
+ path = get_registry_value(reg, key, "Path")
+ path += ";" + bindir
+ print "Setting PATH to:", path
+ set_registry_value(reg, key, "Path", path)
+ #print "Current PATH is:", get_registry_value(reg, key, "Path")
+
+ # Propagate changes throughout the system
+ win32gui.SendMessageTimeout(win32con.HWND_BROADCAST,
+ win32con.WM_SETTINGCHANGE, 0, "Environment",
+ win32con.SMTO_ABORTIFHUNG, 5000)
+
+ # Propagate changes to current command prompt
+ os.system("set PATH=%s" % path)
+
+def get_registry_value(reg, key, value_name):
+ k = _winreg.OpenKey(reg, key)
+ value = _winreg.QueryValueEx(k, value_name)[0]
+ _winreg.CloseKey(k)
+ return value
+
+def set_registry_value(reg, key, value_name, value):
+ k = _winreg.OpenKey(reg, key, 0, _winreg.KEY_WRITE)
+ _winreg.SetValueEx(k, value_name, 0, _winreg.REG_SZ, value)
+ _winreg.CloseKey(k)
+
+### end helpers
+
def setup(pkg, **kw):
""" invoke distutils on a given package.
"""
@@ -106,6 +147,7 @@
#py.std.pprint.pprint(kw)
core.setup(**kw)
if 'install' in sys.argv[1:]:
+ addbindir2path()
x = params._rootdir.join('build')
if x.check():
print "removing", x
More information about the pytest-commit
mailing list