summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-01-18 11:58:50 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-01-18 11:58:50 (GMT)
commitbd865db90c00a1114defeb12149698cbf4e7313b (patch)
tree445a9c746624e88f63475e3d41ff10d65d76636f /Tools
parentb222bbc32105f7ca9a1c5c5ad37c07de3997b9c4 (diff)
downloadcpython-bd865db90c00a1114defeb12149698cbf4e7313b.zip
cpython-bd865db90c00a1114defeb12149698cbf4e7313b.tar.gz
cpython-bd865db90c00a1114defeb12149698cbf4e7313b.tar.bz2
Added win_add2path.py to Tools/scripts/
Added builddoc.bat to Doc/
Diffstat (limited to 'Tools')
-rw-r--r--Tools/scripts/win_add2path.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/Tools/scripts/win_add2path.py b/Tools/scripts/win_add2path.py
new file mode 100644
index 0000000..876bfb2
--- /dev/null
+++ b/Tools/scripts/win_add2path.py
@@ -0,0 +1,57 @@
+"""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()