84 """ |
85 """ |
85 Set the values of globals that need more than a simple assignment. |
86 Set the values of globals that need more than a simple assignment. |
86 """ |
87 """ |
87 global pyModDir |
88 global pyModDir |
88 |
89 |
89 pyModDir = sysconfig.get_path('platlib') |
90 pyModDir = sysconfig.get_path("platlib") |
90 |
91 |
91 |
92 |
92 def wrapperNames(dname, wfile): |
93 def wrapperNames(dname, wfile): |
93 """ |
94 """ |
94 Create the platform specific names for the wrapper script. |
95 Create the platform specific names for the wrapper script. |
95 |
96 |
96 @param dname name of the directory to place the wrapper into |
97 @param dname name of the directory to place the wrapper into |
97 @param wfile basename (without extension) of the wrapper script |
98 @param wfile basename (without extension) of the wrapper script |
98 @return the names of the wrapper scripts |
99 @return the names of the wrapper scripts |
99 """ |
100 """ |
100 wnames = ( |
101 wnames = ( |
101 (dname + "\\" + wfile + ".cmd", dname + "\\" + wfile + ".bat") |
102 (dname + "\\" + wfile + ".cmd", dname + "\\" + wfile + ".bat") |
102 if sys.platform.startswith(("win", "cygwin")) else |
103 if sys.platform.startswith(("win", "cygwin")) |
103 (dname + "/" + wfile, ) |
104 else (dname + "/" + wfile,) |
104 ) |
105 ) |
105 |
106 |
106 return wnames |
107 return wnames |
107 |
108 |
108 |
109 |
109 def uninstallEric(): |
110 def uninstallEric(): |
110 """ |
111 """ |
111 Uninstall the eric files. |
112 Uninstall the eric files. |
112 """ |
113 """ |
113 global pyModDir |
114 global pyModDir |
114 |
115 |
115 # Remove the menu entry for Linux systems |
116 # Remove the menu entry for Linux systems |
116 if sys.platform.startswith("linux"): |
117 if sys.platform.startswith("linux"): |
117 uninstallLinuxSpecifics() |
118 uninstallLinuxSpecifics() |
118 # Remove the Desktop and Start Menu entries for Windows systems |
119 # Remove the Desktop and Start Menu entries for Windows systems |
119 elif sys.platform.startswith(("win", "cygwin")): |
120 elif sys.platform.startswith(("win", "cygwin")): |
120 uninstallWindowsLinks() |
121 uninstallWindowsLinks() |
121 |
122 |
122 # Remove the wrapper scripts |
123 # Remove the wrapper scripts |
123 rem_wnames = [ |
124 rem_wnames = [ |
124 "eric7_api", "eric7_browser", "eric7_compare", "eric7_configure", |
125 "eric7_api", |
125 "eric7_diff", "eric7_doc", "eric7_editor", "eric7_hexeditor", |
126 "eric7_browser", |
126 "eric7_iconeditor", "eric7_plugininstall", "eric7_pluginrepository", |
127 "eric7_compare", |
127 "eric7_pluginuninstall", "eric7_qregularexpression", "eric7_re", |
128 "eric7_configure", |
128 "eric7_shell", "eric7_snap", "eric7_sqlbrowser", "eric7_testing", |
129 "eric7_diff", |
129 "eric7_tray", "eric7_trpreviewer", "eric7_uipreviewer", |
130 "eric7_doc", |
130 "eric7_virtualenv", "eric7", |
131 "eric7_editor", |
|
132 "eric7_hexeditor", |
|
133 "eric7_iconeditor", |
|
134 "eric7_plugininstall", |
|
135 "eric7_pluginrepository", |
|
136 "eric7_pluginuninstall", |
|
137 "eric7_qregularexpression", |
|
138 "eric7_re", |
|
139 "eric7_shell", |
|
140 "eric7_snap", |
|
141 "eric7_sqlbrowser", |
|
142 "eric7_testing", |
|
143 "eric7_tray", |
|
144 "eric7_trpreviewer", |
|
145 "eric7_uipreviewer", |
|
146 "eric7_virtualenv", |
|
147 "eric7", |
131 # obsolete scripts below |
148 # obsolete scripts below |
132 "eric7_unittest", |
149 "eric7_unittest", |
133 ] |
150 ] |
134 |
151 |
135 try: |
152 try: |
136 for rem_wname in rem_wnames: |
153 for rem_wname in rem_wnames: |
137 for rwname in wrapperNames(getConfig('bindir'), rem_wname): |
154 for rwname in wrapperNames(getConfig("bindir"), rem_wname): |
138 if os.path.exists(rwname): |
155 if os.path.exists(rwname): |
139 os.remove(rwname) |
156 os.remove(rwname) |
140 |
157 |
141 # Cleanup our config file(s) |
158 # Cleanup our config file(s) |
142 for name in ['eric7config.py', 'eric7config.pyc', 'eric7.pth']: |
159 for name in ["eric7config.py", "eric7config.pyc", "eric7.pth"]: |
143 e5cfile = os.path.join(pyModDir, name) |
160 e5cfile = os.path.join(pyModDir, name) |
144 if os.path.exists(e5cfile): |
161 if os.path.exists(e5cfile): |
145 os.remove(e5cfile) |
162 os.remove(e5cfile) |
146 e5cfile = os.path.join(pyModDir, "__pycache__", name) |
163 e5cfile = os.path.join(pyModDir, "__pycache__", name) |
147 path, ext = os.path.splitext(e5cfile) |
164 path, ext = os.path.splitext(e5cfile) |
148 for f in glob.glob("{0}.*{1}".format(path, ext)): |
165 for f in glob.glob("{0}.*{1}".format(path, ext)): |
149 os.remove(f) |
166 os.remove(f) |
150 |
167 |
151 # Cleanup the install directories |
168 # Cleanup the install directories |
152 for name in ['ericExamplesDir', 'ericDocDir', 'ericDTDDir', |
169 for name in [ |
153 'ericCSSDir', 'ericIconDir', 'ericPixDir', |
170 "ericExamplesDir", |
154 'ericTemplatesDir', 'ericCodeTemplatesDir', |
171 "ericDocDir", |
155 'ericOthersDir', 'ericStylesDir', 'ericThemesDir', |
172 "ericDTDDir", |
156 'ericDir']: |
173 "ericCSSDir", |
|
174 "ericIconDir", |
|
175 "ericPixDir", |
|
176 "ericTemplatesDir", |
|
177 "ericCodeTemplatesDir", |
|
178 "ericOthersDir", |
|
179 "ericStylesDir", |
|
180 "ericThemesDir", |
|
181 "ericDir", |
|
182 ]: |
157 with contextlib.suppress(AttributeError): |
183 with contextlib.suppress(AttributeError): |
158 dirpath = getConfig(name) |
184 dirpath = getConfig(name) |
159 if os.path.exists(dirpath): |
185 if os.path.exists(dirpath): |
160 shutil.rmtree(dirpath, True) |
186 shutil.rmtree(dirpath, True) |
161 |
187 |
162 # Cleanup translations |
188 # Cleanup translations |
163 for name in glob.glob( |
189 for name in glob.glob( |
164 os.path.join(getConfig('ericTranslationsDir'), 'eric7_*.qm')): |
190 os.path.join(getConfig("ericTranslationsDir"), "eric7_*.qm") |
|
191 ): |
165 if os.path.exists(name): |
192 if os.path.exists(name): |
166 os.remove(name) |
193 os.remove(name) |
167 |
194 |
168 # Cleanup API files |
195 # Cleanup API files |
169 apidir = getConfig('apidir') |
196 apidir = getConfig("apidir") |
170 if apidir: |
197 if apidir: |
171 for progLanguage in progLanguages: |
198 for progLanguage in progLanguages: |
172 for name in getConfig('apis'): |
199 for name in getConfig("apis"): |
173 apiname = os.path.join(apidir, progLanguage.lower(), name) |
200 apiname = os.path.join(apidir, progLanguage.lower(), name) |
174 if os.path.exists(apiname): |
201 if os.path.exists(apiname): |
175 os.remove(apiname) |
202 os.remove(apiname) |
176 for apiname in glob.glob( |
203 for apiname in glob.glob( |
177 os.path.join(apidir, progLanguage.lower(), "*.bas")): |
204 os.path.join(apidir, progLanguage.lower(), "*.bas") |
|
205 ): |
178 if os.path.basename(apiname) != "eric7.bas": |
206 if os.path.basename(apiname) != "eric7.bas": |
179 os.remove(apiname) |
207 os.remove(apiname) |
180 |
208 |
181 if sys.platform == "darwin": |
209 if sys.platform == "darwin": |
182 # delete the Mac app bundle |
210 # delete the Mac app bundle |
183 uninstallMacAppBundle() |
211 uninstallMacAppBundle() |
184 |
212 |
185 # remove plug-in directories |
213 # remove plug-in directories |
186 removePluginDirectories() |
214 removePluginDirectories() |
187 |
215 |
188 # remove the eric data directory |
216 # remove the eric data directory |
189 removeDataDirectory() |
217 removeDataDirectory() |
190 |
218 |
191 # remove the eric configuration directory |
219 # remove the eric configuration directory |
192 removeConfigurationData() |
220 removeConfigurationData() |
193 |
221 |
194 print("\nUninstallation completed") |
222 print("\nUninstallation completed") |
195 except OSError as msg: |
223 except OSError as msg: |
196 sys.stderr.write( |
224 sys.stderr.write("Error: {0}\nTry uninstall with admin rights.\n".format(msg)) |
197 'Error: {0}\nTry uninstall with admin rights.\n'.format(msg)) |
|
198 exit(7) |
225 exit(7) |
199 |
226 |
200 |
227 |
201 def uninstallWindowsLinks(): |
228 def uninstallWindowsLinks(): |
202 """ |
229 """ |
203 Clean up the Desktop and Start Menu entries for Windows. |
230 Clean up the Desktop and Start Menu entries for Windows. |
204 """ |
231 """ |
205 try: |
232 try: |
206 from pywintypes import com_error # __IGNORE_WARNING__ |
233 from pywintypes import com_error # __IGNORE_WARNING__ |
207 except ImportError: |
234 except ImportError: |
208 # links were not created by install.py |
235 # links were not created by install.py |
209 return |
236 return |
210 |
237 |
211 regPath = ( |
238 regPath = ( |
212 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + |
239 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" |
213 "\\User Shell Folders" |
240 + "\\User Shell Folders" |
214 ) |
241 ) |
215 |
242 |
216 # 1. cleanup desktop links |
243 # 1. cleanup desktop links |
217 regName = "Desktop" |
244 regName = "Desktop" |
218 desktopEntry = getWinregEntry(regName, regPath) |
245 desktopEntry = getWinregEntry(regName, regPath) |
219 if desktopEntry: |
246 if desktopEntry: |
220 desktopFolder = os.path.normpath(os.path.expandvars(desktopEntry)) |
247 desktopFolder = os.path.normpath(os.path.expandvars(desktopEntry)) |
285 macAppBundlePath = getConfig("macAppBundlePath") |
312 macAppBundlePath = getConfig("macAppBundlePath") |
286 macAppBundleName = getConfig("macAppBundleName") |
313 macAppBundleName = getConfig("macAppBundleName") |
287 except AttributeError: |
314 except AttributeError: |
288 macAppBundlePath = defaultMacAppBundlePath |
315 macAppBundlePath = defaultMacAppBundlePath |
289 macAppBundleName = defaultMacAppBundleName |
316 macAppBundleName = defaultMacAppBundleName |
290 for bundlePath in [os.path.join(defaultMacAppBundlePath, |
317 for bundlePath in [ |
291 macAppBundleName), |
318 os.path.join(defaultMacAppBundlePath, macAppBundleName), |
292 os.path.join(macAppBundlePath, |
319 os.path.join(macAppBundlePath, macAppBundleName), |
293 macAppBundleName), |
320 ]: |
294 ]: |
|
295 if os.path.exists(bundlePath): |
321 if os.path.exists(bundlePath): |
296 shutil.rmtree(bundlePath) |
322 shutil.rmtree(bundlePath) |
297 |
323 |
298 |
324 |
299 def removePluginDirectories(): |
325 def removePluginDirectories(): |
300 """ |
326 """ |
301 Remove the plug-in directories. |
327 Remove the plug-in directories. |
302 """ |
328 """ |
303 pathsToRemove = [] |
329 pathsToRemove = [] |
304 |
330 |
305 globalPluginsDir = os.path.join(getConfig('mdir'), "eric7plugins") |
331 globalPluginsDir = os.path.join(getConfig("mdir"), "eric7plugins") |
306 if os.path.exists(globalPluginsDir): |
332 if os.path.exists(globalPluginsDir): |
307 pathsToRemove.append(globalPluginsDir) |
333 pathsToRemove.append(globalPluginsDir) |
308 |
334 |
309 localPluginsDir = os.path.join(getConfigDir(), "eric7plugins") |
335 localPluginsDir = os.path.join(getConfigDir(), "eric7plugins") |
310 if os.path.exists(localPluginsDir): |
336 if os.path.exists(localPluginsDir): |
311 pathsToRemove.append(localPluginsDir) |
337 pathsToRemove.append(localPluginsDir) |
312 |
338 |
313 if pathsToRemove: |
339 if pathsToRemove: |
314 print("Found these plug-in directories") |
340 print("Found these plug-in directories") |
315 for path in pathsToRemove: |
341 for path in pathsToRemove: |
316 print(" - {0}".format(path)) |
342 print(" - {0}".format(path)) |
317 answer = "c" |
343 answer = "c" |
365 |
395 |
366 |
396 |
367 def getConfigDir(): |
397 def getConfigDir(): |
368 """ |
398 """ |
369 Module function to get the name of the directory storing the config data. |
399 Module function to get the name of the directory storing the config data. |
370 |
400 |
371 @return directory name of the config dir (string) |
401 @return directory name of the config dir (string) |
372 """ |
402 """ |
373 cdn = ".eric7" |
403 cdn = ".eric7" |
374 return os.path.join(os.path.expanduser("~"), cdn) |
404 return os.path.join(os.path.expanduser("~"), cdn) |
375 |
405 |
376 |
406 |
377 def getWinregEntry(name, path): |
407 def getWinregEntry(name, path): |
378 """ |
408 """ |
379 Function to get an entry from the Windows Registry. |
409 Function to get an entry from the Windows Registry. |
380 |
410 |
381 @param name variable name |
411 @param name variable name |
382 @type str |
412 @type str |
383 @param path registry path of the variable |
413 @param path registry path of the variable |
384 @type str |
414 @type str |
385 @return value of requested registry variable |
415 @return value of requested registry variable |
386 @rtype any |
416 @rtype any |
387 """ |
417 """ |
388 # From http://stackoverflow.com/a/35286642 |
418 # From http://stackoverflow.com/a/35286642 |
389 import winreg |
419 import winreg |
390 try: |
420 |
391 registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, |
421 try: |
392 winreg.KEY_READ) |
422 registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, winreg.KEY_READ) |
393 value, _ = winreg.QueryValueEx(registryKey, name) |
423 value, _ = winreg.QueryValueEx(registryKey, name) |
394 winreg.CloseKey(registryKey) |
424 winreg.CloseKey(registryKey) |
395 return value |
425 return value |
396 except WindowsError: |
426 except WindowsError: |
397 return None |
427 return None |
398 |
428 |
399 |
429 |
400 def windowsDesktopNames(): |
430 def windowsDesktopNames(): |
401 """ |
431 """ |
402 Function to generate the link names for the Windows Desktop. |
432 Function to generate the link names for the Windows Desktop. |
403 |
433 |
404 @return list of desktop link names |
434 @return list of desktop link names |
405 @rtype list of str |
435 @rtype list of str |
406 """ |
436 """ |
407 majorVersion, minorVersion = sys.version_info[:2] |
437 majorVersion, minorVersion = sys.version_info[:2] |
408 linkTemplates = [ |
438 linkTemplates = [ |
409 "eric7 (Python {0}.{1}).lnk", |
439 "eric7 (Python {0}.{1}).lnk", |
410 "eric7 Browser (Python {0}.{1}).lnk", |
440 "eric7 Browser (Python {0}.{1}).lnk", |
411 ] |
441 ] |
412 |
442 |
413 return [ll.format(majorVersion, minorVersion) for ll in linkTemplates] |
443 return [ll.format(majorVersion, minorVersion) for ll in linkTemplates] |
414 |
444 |
415 |
445 |
416 def windowsProgramsEntry(): |
446 def windowsProgramsEntry(): |
417 """ |
447 """ |
418 Function to generate the name of the Start Menu top entry. |
448 Function to generate the name of the Start Menu top entry. |
419 |
449 |
420 @return name of the Start Menu top entry |
450 @return name of the Start Menu top entry |
421 @rtype str |
451 @rtype str |
422 """ |
452 """ |
423 majorVersion, minorVersion = sys.version_info[:2] |
453 majorVersion, minorVersion = sys.version_info[:2] |
424 return "eric7 (Python {0}.{1})".format(majorVersion, minorVersion) |
454 return "eric7 (Python {0}.{1})".format(majorVersion, minorVersion) |