mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
python-3.6.zip added from Github
README.cosmo contains the necessary links.
This commit is contained in:
parent
75fc601ff5
commit
0c4c56ff39
4219 changed files with 1968626 additions and 0 deletions
58
third_party/python/Tools/scripts/win_add2path.py
vendored
Normal file
58
third_party/python/Tools/scripts/win_add2path.py
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
"""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 = "%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"):
|
||||
usersite = site.USER_SITE.replace(appdata, "%APPDATA%")
|
||||
userpath = os.path.dirname(usersite)
|
||||
userscripts = os.path.join(userpath, "Scripts")
|
||||
else:
|
||||
userscripts = None
|
||||
|
||||
with winreg.CreateKey(HKCU, ENV) as key:
|
||||
try:
|
||||
envpath = winreg.QueryValueEx(key, PATH)[0]
|
||||
except OSError:
|
||||
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()
|
Loading…
Add table
Add a link
Reference in a new issue