@@ -54,7 +54,7 @@ def onerror(function, path, excinfo):
54
54
attempts to add write permission and then retries.
55
55
If the error is for another reason, it re-raises the error.
56
56
57
- Usage: `shutil.rmtree(path, onerror =onerror)"""
57
+ Usage: `shutil.rmtree(path, onexc =onerror)"""
58
58
if not os .access (path , os .W_OK ):
59
59
# Is the error an access error?
60
60
os .chmod (path , stat .S_IWUSR )
@@ -63,65 +63,6 @@ def onerror(function, path, excinfo):
63
63
raise
64
64
65
65
66
-
67
- # =============================================================================
68
- # Environment variables
69
- # =============================================================================
70
- def get_env (name , current = True ):
71
- """Return HKCU/HKLM environment variable name and value
72
-
73
- For example, get_user_env('PATH') may returns:
74
- ('Path', u'C:\\ Program Files\\ Intel\\ WiFi\\ bin\\ ')"""
75
- root = (
76
- winreg .HKEY_CURRENT_USER
77
- if current
78
- else winreg .HKEY_LOCAL_MACHINE
79
- )
80
- key = winreg .OpenKey (root , "Environment" )
81
- for index in range (0 , winreg .QueryInfoKey (key )[1 ]):
82
- try :
83
- value = winreg .EnumValue (key , index )
84
- if value [0 ].lower () == name .lower ():
85
- # Return both value[0] and value[1] because value[0] could be
86
- # different from name (lowercase/uppercase)
87
- return value [0 ], value [1 ]
88
- except :
89
- break
90
-
91
-
92
- def set_env (name , value , current = True ):
93
- """Set HKCU/HKLM environment variables"""
94
- root = (
95
- winreg .HKEY_CURRENT_USER
96
- if current
97
- else winreg .HKEY_LOCAL_MACHINE
98
- )
99
- key = winreg .OpenKey (root , "Environment" )
100
- try :
101
- _x , key_type = winreg .QueryValueEx (key , name )
102
- except WindowsError :
103
- key_type = winreg .REG_EXPAND_SZ
104
- key = winreg .OpenKey (
105
- root , "Environment" , 0 , winreg .KEY_SET_VALUE
106
- )
107
- winreg .SetValueEx (key , name , 0 , key_type , value )
108
- from win32gui import SendMessageTimeout
109
- from win32con import (
110
- HWND_BROADCAST ,
111
- WM_SETTINGCHANGE ,
112
- SMTO_ABORTIFHUNG ,
113
- )
114
-
115
- SendMessageTimeout (
116
- HWND_BROADCAST ,
117
- WM_SETTINGCHANGE ,
118
- 0 ,
119
- "Environment" ,
120
- SMTO_ABORTIFHUNG ,
121
- 5000 ,
122
- )
123
-
124
-
125
66
#==============================================================================
126
67
# https://stackoverflow.com/questions/580924/how-to-access-a-files-properties-on-windows
127
68
def getFileProperties (fname ):
@@ -210,7 +151,7 @@ def remove_winpython_start_menu_folder(current=True):
210
151
path = get_winpython_start_menu_folder (current = current )
211
152
if Path (path ).is_dir ():
212
153
try :
213
- shutil .rmtree (path , onerror = onerror )
154
+ shutil .rmtree (path , onexc = onerror )
214
155
except WindowsError :
215
156
print (
216
157
f"Directory { path } could not be removed" ,
@@ -222,7 +163,7 @@ def create_winpython_start_menu_folder(current=True):
222
163
path = get_winpython_start_menu_folder (current = current )
223
164
if Path (path ).is_dir ():
224
165
try :
225
- shutil .rmtree (path , onerror = onerror )
166
+ shutil .rmtree (path , onexc = onerror )
226
167
except WindowsError :
227
168
print (
228
169
f"Directory { path } could not be removed" ,
@@ -629,7 +570,7 @@ def _create_temp_dir():
629
570
"""Create a temporary directory and remove it at exit"""
630
571
tmpdir = tempfile .mkdtemp (prefix = 'wppm_' )
631
572
atexit .register (
632
- lambda path : shutil .rmtree (path , onerror = onerror ),
573
+ lambda path : shutil .rmtree (path , onexc = onerror ),
633
574
tmpdir ,
634
575
)
635
576
return tmpdir
@@ -744,7 +685,7 @@ def buildflit_wininst(
744
685
)
745
686
)
746
687
# remove tempo dir 'root' no more needed
747
- shutil .rmtree (root , onerror = onerror )
688
+ shutil .rmtree (root , onexc = onerror )
748
689
return dst_fname
749
690
750
691
0 commit comments