]> granicus.if.org Git - python/commitdiff
Added win_add2path.py to Tools/scripts/
authorChristian Heimes <christian@cheimes.de>
Fri, 18 Jan 2008 11:58:50 +0000 (11:58 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 18 Jan 2008 11:58:50 +0000 (11:58 +0000)
Added builddoc.bat to Doc/

Doc/builddoc.bat [new file with mode: 0644]
Misc/NEWS
Tools/scripts/win_add2path.py [new file with mode: 0644]

diff --git a/Doc/builddoc.bat b/Doc/builddoc.bat
new file mode 100644 (file)
index 0000000..a26851f
--- /dev/null
@@ -0,0 +1,52 @@
+@echo off\r
+setlocal\r
+\r
+set SVNROOT=http://svn.python.org/projects\r
+if "%PYTHON%" EQU "" set PYTHON=python25\r
+\r
+if "%1" EQU "" goto help\r
+if "%1" EQU "html" goto build\r
+if "%1" EQU "htmlhelp" goto build\r
+if "%1" EQU "web" goto build\r
+if "%1" EQU "webrun" goto webrun\r
+if "%1" EQU "checkout" goto checkout\r
+if "%1" EQU "update" goto update\r
+\r
+:help\r
+echo HELP\r
+echo.\r
+echo builddoc checkout\r
+echo builddoc update\r
+echo builddoc html\r
+echo builddoc htmlhelp\r
+echo builddoc web\r
+echo builddoc webrun\r
+echo.\r
+goto end\r
+\r
+:checkout\r
+svn co %SVNROOT%/doctools/trunk/sphinx tools/sphinx\r
+svn co %SVNROOT%/external/docutils-0.4/docutils tools/docutils\r
+svn co %SVNROOT%/external/Pygments-0.9/pygments tools/pygments\r
+goto end\r
+\r
+:update\r
+svn update tools/sphinx\r
+svn update tools/docutils\r
+svn update tools/pygments\r
+goto end\r
+\r
+:build\r
+if not exist build mkdir build\r
+if not exist build\%1 mkdir build\%1\r
+if not exist build\doctrees mkdir build\doctrees\r
+cmd /C %PYTHON% tools\sphinx-build.py -b%1 -dbuild\doctrees . build\%1\r
+if "%1" EQU "htmlhelp" "%ProgramFiles%\HTML Help Workshop\hhc.exe" build\htmlhelp\pydoc.hhp\r
+goto end\r
+\r
+:webrun\r
+set PYTHONPATH=tools\r
+%PYTHON% -m sphinx.web build\web\r
+goto end\r
+\r
+:end\r
index 7f92aaf077ebb1794955b092f81494fcb7c01480..5060b681bd2efdb15e1eef06f48e8e57d2007fc0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1196,6 +1196,10 @@ Tests
 Tools
 -----
 
+- Tools/scripts/win_add2path.py was added. The simple script modifes the
+  PATH environment var of the HKCU tree and adds the python bin and script
+  directory.
+
 - Tools/18n/pygettext.py was added to the list of scripts installed by
   Tools/scripts/setup.py (tracker item 642309).
 
diff --git a/Tools/scripts/win_add2path.py b/Tools/scripts/win_add2path.py
new file mode 100644 (file)
index 0000000..876bfb2
--- /dev/null
@@ -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()