From bd865db90c00a1114defeb12149698cbf4e7313b Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 18 Jan 2008 11:58:50 +0000 Subject: Added win_add2path.py to Tools/scripts/ Added builddoc.bat to Doc/ --- Doc/builddoc.bat | 52 +++++++++++++++++++++++++++++++++++++++ Misc/NEWS | 4 +++ Tools/scripts/win_add2path.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 Doc/builddoc.bat create mode 100644 Tools/scripts/win_add2path.py diff --git a/Doc/builddoc.bat b/Doc/builddoc.bat new file mode 100644 index 0000000..a26851f --- /dev/null +++ b/Doc/builddoc.bat @@ -0,0 +1,52 @@ +@echo off +setlocal + +set SVNROOT=http://svn.python.org/projects +if "%PYTHON%" EQU "" set PYTHON=python25 + +if "%1" EQU "" goto help +if "%1" EQU "html" goto build +if "%1" EQU "htmlhelp" goto build +if "%1" EQU "web" goto build +if "%1" EQU "webrun" goto webrun +if "%1" EQU "checkout" goto checkout +if "%1" EQU "update" goto update + +:help +echo HELP +echo. +echo builddoc checkout +echo builddoc update +echo builddoc html +echo builddoc htmlhelp +echo builddoc web +echo builddoc webrun +echo. +goto end + +:checkout +svn co %SVNROOT%/doctools/trunk/sphinx tools/sphinx +svn co %SVNROOT%/external/docutils-0.4/docutils tools/docutils +svn co %SVNROOT%/external/Pygments-0.9/pygments tools/pygments +goto end + +:update +svn update tools/sphinx +svn update tools/docutils +svn update tools/pygments +goto end + +:build +if not exist build mkdir build +if not exist build\%1 mkdir build\%1 +if not exist build\doctrees mkdir build\doctrees +cmd /C %PYTHON% tools\sphinx-build.py -b%1 -dbuild\doctrees . build\%1 +if "%1" EQU "htmlhelp" "%ProgramFiles%\HTML Help Workshop\hhc.exe" build\htmlhelp\pydoc.hhp +goto end + +:webrun +set PYTHONPATH=tools +%PYTHON% -m sphinx.web build\web +goto end + +:end diff --git a/Misc/NEWS b/Misc/NEWS index 7f92aaf..5060b68 100644 --- 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 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 +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() -- cgit v0.12