88# be tested in an installation.
99
1010import os
11- import re
1211import sys
13- from os .path import exists , isfile , join
14-
15- try :
16- import winreg
17- except ImportError :
18- import _winreg as winreg
12+ from os .path import exists , join
1913
2014ROOT_PREFIX = sys .prefix
2115
@@ -57,96 +51,6 @@ def err(x):
5751 OutputDebugString ('_nsis.py: Error: ' + x )
5852
5953
60- class NSISReg :
61- def __init__ (self , reg_path ):
62- self .reg_path = reg_path
63- if exists (join (ROOT_PREFIX , '.nonadmin' )):
64- self .main_key = winreg .HKEY_CURRENT_USER
65- else :
66- self .main_key = winreg .HKEY_LOCAL_MACHINE
67-
68- def set (self , name , value ):
69- try :
70- winreg .CreateKey (self .main_key , self .reg_path )
71- registry_key = winreg .OpenKey (self .main_key , self .reg_path , 0 ,
72- winreg .KEY_WRITE )
73- winreg .SetValueEx (registry_key , name , 0 , winreg .REG_SZ , value )
74- winreg .CloseKey (registry_key )
75- return True
76- except WindowsError :
77- return False
78-
79- def get (self , name ):
80- try :
81- registry_key = winreg .OpenKey (self .main_key , self .reg_path , 0 ,
82- winreg .KEY_READ )
83- value , regtype = winreg .QueryValueEx (registry_key , name )
84- winreg .CloseKey (registry_key )
85- return value
86- except WindowsError :
87- return None
88-
89-
90- def mk_dirs ():
91- envs_dir = join (ROOT_PREFIX , 'envs' )
92- if not exists (envs_dir ):
93- os .mkdir (envs_dir )
94-
95-
96- def run_post_install ():
97- """
98- call the post install script, if the file exists
99- """
100- path = join (ROOT_PREFIX , 'pkgs' , 'post_install.bat' )
101- if not isfile (path ):
102- return
103- env = os .environ .copy ()
104- env .setdefault ('PREFIX' , str (ROOT_PREFIX ))
105- cmd_exe = os .path .join (os .environ ['SystemRoot' ], 'System32' , 'cmd.exe' )
106- if not os .path .isfile (cmd_exe ):
107- cmd_exe = os .path .join (os .environ ['windir' ], 'System32' , 'cmd.exe' )
108- if not os .path .isfile (cmd_exe ):
109- err ("Error: running %s failed. cmd.exe could not be found. "
110- "Looked in SystemRoot and windir env vars.\n " % path )
111- if os .environ .get ("NSIS_SCRIPTS_RAISE_ERRORS" ):
112- sys .exit (1 )
113- args = [cmd_exe , '/d' , '/c' , path ]
114- import subprocess
115- try :
116- subprocess .check_call (args , env = env )
117- except subprocess .CalledProcessError :
118- err ("Error: running %s failed\n " % path )
119- if os .environ .get ("NSIS_SCRIPTS_RAISE_ERRORS" ):
120- sys .exit (1 )
121-
122-
123- def run_pre_uninstall ():
124- """
125- call the pre uninstall script, if the file exists
126- """
127- path = join (ROOT_PREFIX , 'pre_uninstall.bat' )
128- if not isfile (path ):
129- return
130- env = os .environ .copy ()
131- env .setdefault ('PREFIX' , str (ROOT_PREFIX ))
132- cmd_exe = os .path .join (os .environ ['SystemRoot' ], 'System32' , 'cmd.exe' )
133- if not os .path .isfile (cmd_exe ):
134- cmd_exe = os .path .join (os .environ ['windir' ], 'System32' , 'cmd.exe' )
135- if not os .path .isfile (cmd_exe ):
136- err ("Error: running %s failed. cmd.exe could not be found. "
137- "Looked in SystemRoot and windir env vars.\n " % path )
138- if os .environ .get ("NSIS_SCRIPTS_RAISE_ERRORS" ):
139- sys .exit (1 )
140- args = [cmd_exe , '/d' , '/c' , path ]
141- import subprocess
142- try :
143- subprocess .check_call (args , env = env )
144- except subprocess .CalledProcessError :
145- err ("Error: running %s failed\n " % path )
146- if os .environ .get ("NSIS_SCRIPTS_RAISE_ERRORS" ):
147- sys .exit (1 )
148-
149-
15054allusers = (not exists (join (ROOT_PREFIX , '.nonadmin' )))
15155# out('allusers is %s\n' % allusers)
15256
@@ -217,29 +121,9 @@ def add_condabin_to_path():
217121 broadcast_environment_settings_change ()
218122
219123
220- def rm_regkeys ():
221- cmdproc_reg_entry = NSISReg (r'Software\Microsoft\Command Processor' )
222- cmdproc_autorun_val = cmdproc_reg_entry .get ('AutoRun' )
223- conda_hook_regex_pat = r'((\s+&\s+)?(if +exist)?(\s*?\"[^\"]*?conda[-_]hook\.bat\"))'
224- if join (ROOT_PREFIX , 'condabin' ) in (cmdproc_autorun_val or '' ):
225- cmdproc_autorun_newval = re .sub (conda_hook_regex_pat , '' ,
226- cmdproc_autorun_val )
227- try :
228- cmdproc_reg_entry .set ('AutoRun' , cmdproc_autorun_newval )
229- except Exception :
230- # Hey, at least we made an attempt to cleanup
231- pass
232-
233-
234124def main ():
235125 cmd = sys .argv [1 ].strip ()
236- if cmd == 'post_install' :
237- run_post_install ()
238- elif cmd == 'rmreg' :
239- rm_regkeys ()
240- elif cmd == 'mkdirs' :
241- mk_dirs ()
242- elif cmd == 'addpath' :
126+ if cmd == 'addpath' :
243127 # These checks are probably overkill, but could be useful
244128 # if I forget to update something that uses this code.
245129 if len (sys .argv ) > 2 :
@@ -257,8 +141,6 @@ def main():
257141 add_condabin_to_path ()
258142 elif cmd == 'rmpath' :
259143 remove_from_path ()
260- elif cmd == 'pre_uninstall' :
261- run_pre_uninstall ()
262144 else :
263145 sys .exit ("ERROR: did not expect %r" % cmd )
264146
0 commit comments