Staging
v0.5.1
https://github.com/python/cpython
Revision 2032722e514a20b5f5321f07427dc2cea6e0d634 authored by Antoine Pitrou on 24 May 2009, 20:39:11 UTC, committed by Antoine Pitrou on 24 May 2009, 20:39:11 UTC
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72898 | antoine.pitrou | 2009-05-24 22:23:57 +0200 (dim., 24 mai 2009) | 6 lines

  Issue #3585: Add pkg-config support.

  It creates a python-2.7.pc file and a python.pc symlink in the
  $(LIBDIR)/pkgconfig directory. Patch by Clinton Roy.
........
1 parent 70ccd16
Raw File
Tip revision: 2032722e514a20b5f5321f07427dc2cea6e0d634 authored by Antoine Pitrou on 24 May 2009, 20:39:11 UTC
Merged revisions 72898 via svnmerge from
Tip revision: 2032722
win_add2path.py
"""Add Python to the search path on Windows

This is a simple script to add Python to the Windows search path. It
modifies the current user (HKCU) tree of the registry.

Copyright (c) 2008 by Christian Heimes <christian@cheimes.de>
Licensed to PSF under a Contributor Agreement.
"""

import sys
import site
import os
import winreg

HKCU = winreg.HKEY_CURRENT_USER
ENV = "Environment"
PATH = "PATH"
DEFAULT = u"%PATH%"

def modify():
    pythonpath = os.path.dirname(os.path.normpath(sys.executable))
    scripts = os.path.join(pythonpath, "Scripts")
    appdata = os.environ["APPDATA"]
    if hasattr(site, "USER_SITE"):
        userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
        userscripts = os.path.join(userpath, "Scripts")
    else:
        userscripts = None

    with winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = winreg.QueryValueEx(key, PATH)[0]
        except WindowsError:
            envpath = DEFAULT

        paths = [envpath]
        for path in (pythonpath, scripts, userscripts):
            if path and path not in envpath and os.path.isdir(path):
                paths.append(path)

        envpath = os.pathsep.join(paths)
        winreg.SetValueEx(key, PATH, 0, winreg.REG_EXPAND_SZ, envpath)
        return paths, envpath

def main():
    paths, envpath = modify()
    if len(paths) > 1:
        print "Path(s) added:"
        print '\n'.join(paths[1:])
    else:
        print "No path was added"
    print "\nPATH is now:\n%s\n" % envpath
    print "Expanded:"
    print winreg.ExpandEnvironmentStrings(envpath)

if __name__ == '__main__':
    main()
back to top