Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: Tools/scripts/win_add2path.py

Issue 23437: Make user scripts directory versioned on Windows
Patch Set: Created 5 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/sysconfig.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Add Python to the search path on Windows 1 """Add Python to the search path on Windows
2 2
3 This is a simple script to add Python to the Windows search path. It 3 This is a simple script to add Python to the Windows search path. It
4 modifies the current user (HKCU) tree of the registry. 4 modifies the current user (HKCU) tree of the registry.
5 5
6 Copyright (c) 2008 by Christian Heimes <christian@cheimes.de> 6 Copyright (c) 2008 by Christian Heimes <christian@cheimes.de>
7 Licensed to PSF under a Contributor Agreement. 7 Licensed to PSF under a Contributor Agreement.
8 """ 8 """
9 9
10 import sys 10 import sys
11 import site 11 import site
12 import os 12 import os
13 import winreg 13 import winreg
14 14
15 HKCU = winreg.HKEY_CURRENT_USER 15 HKCU = winreg.HKEY_CURRENT_USER
16 ENV = "Environment" 16 ENV = "Environment"
17 PATH = "PATH" 17 PATH = "PATH"
18 DEFAULT = "%PATH%" 18 DEFAULT = "%PATH%"
19 19
20 def modify(): 20 def modify():
21 pythonpath = os.path.dirname(os.path.normpath(sys.executable)) 21 pythonpath = os.path.dirname(os.path.normpath(sys.executable))
22 scripts = os.path.join(pythonpath, "Scripts") 22 scripts = os.path.join(pythonpath, "Scripts")
23 appdata = os.environ["APPDATA"] 23 appdata = os.environ["APPDATA"]
24 if hasattr(site, "USER_SITE"): 24 if hasattr(site, "USER_SITE"):
25 userpath = site.USER_SITE.replace(appdata, "%APPDATA%") 25 usersite = site.USER_SITE.replace(appdata, "%APPDATA%")
26 userpath = os.path.dirname(usersite)
26 userscripts = os.path.join(userpath, "Scripts") 27 userscripts = os.path.join(userpath, "Scripts")
27 else: 28 else:
28 userscripts = None 29 userscripts = None
29 30
30 with winreg.CreateKey(HKCU, ENV) as key: 31 with winreg.CreateKey(HKCU, ENV) as key:
31 try: 32 try:
32 envpath = winreg.QueryValueEx(key, PATH)[0] 33 envpath = winreg.QueryValueEx(key, PATH)[0]
33 except OSError: 34 except OSError:
34 envpath = DEFAULT 35 envpath = DEFAULT
35 36
(...skipping 12 matching lines...) Expand all
48 print("Path(s) added:") 49 print("Path(s) added:")
49 print('\n'.join(paths[1:])) 50 print('\n'.join(paths[1:]))
50 else: 51 else:
51 print("No path was added") 52 print("No path was added")
52 print("\nPATH is now:\n%s\n" % envpath) 53 print("\nPATH is now:\n%s\n" % envpath)
53 print("Expanded:") 54 print("Expanded:")
54 print(winreg.ExpandEnvironmentStrings(envpath)) 55 print(winreg.ExpandEnvironmentStrings(envpath))
55 56
56 if __name__ == '__main__': 57 if __name__ == '__main__':
57 main() 58 main()
OLDNEW
« no previous file with comments | « Lib/sysconfig.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+