uninstall.py

changeset 6509
884182bfd25c
parent 6500
0373580fc86c
child 6510
d8fd663f86ef
--- a/uninstall.py	Thu Sep 20 19:36:15 2018 +0200
+++ b/uninstall.py	Thu Sep 20 19:48:56 2018 +0200
@@ -64,7 +64,7 @@
             os.remove("eric6config.py")
         os.rename("eric6config.py.orig", "eric6config.py")
     
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         # different meaning of input between Py2 and Py3
         try:
             input("Press enter to continue...")
@@ -110,7 +110,7 @@
     @param wfile basename (without extension) of the wrapper script
     @return the names of the wrapper scripts
     """
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         wnames = (dname + "\\" + wfile + ".cmd",
                   dname + "\\" + wfile + ".bat")
     else:
@@ -128,6 +128,9 @@
     # Remove the menu entry for Linux systems
     if sys.platform.startswith("linux"):
         uninstallLinuxSpecifics()
+    # Remove the Desktop and Start Menu entries for Windows systems
+    elif sys.platform.startswith(("win", "cygwin")):
+        uninstallWindowsLinks()
     
     # Remove the wrapper scripts
     rem_wnames = [
@@ -212,6 +215,30 @@
         exit(7)
 
 
+def uninstallWindowsLinks():
+    """
+    Clean up the Desktop and Start Menu entries for Windows.
+    """
+    regPath = r"Software\Microsoft\Windows\CurrentVersion\Explorer" \
+              r"\User Shell Folders"
+    # 1. cleanup desktop links
+    regName = "Desktop"
+    desktopFolder = os.path.normpath(
+            os.path.expandvars(getWinregEntry(regName, regPath)))
+    for linkName in windowsDesktopNames():
+        linkPath = os.path.join(desktopFolder, linkName)
+        if os.path.exists(linkPath):
+            os.remove(linkPath)
+    
+    # 2. cleanup start menu entry
+    regName = "Programs"
+    programsFolder = os.path.normpath(
+        os.path.expandvars(getWinregEntry(regName, regPath)))
+    eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
+    if os.path.exists(eric6EntryPath):
+        shutil.rmtree(eric6EntryPath)
+
+
 def uninstallLinuxSpecifics():
     """
     Uninstall Linux specific files.
@@ -367,6 +394,56 @@
     return os.path.join(os.path.expanduser("~"), cdn)
 
 
+def getWinregEntry(name, path):
+    """
+    Function to get an entry from the Windows Registry.
+    
+    @param name variable name
+    @type str
+    @param path registry path of the variable
+    @type str
+    @return value of requested registry variable
+    @rtype any
+    """
+    # From http://stackoverflow.com/a/35286642
+    import winreg
+    try:
+        registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0,
+                                     winreg.KEY_READ)
+        value, _ = winreg.QueryValueEx(registryKey, name)
+        winreg.CloseKey(registryKey)
+        return value
+    except WindowsError:
+        return None
+
+
+def windowsDesktopNames():
+    """
+    Function to generate the link names for the Windows Desktop.
+    
+    @return list of desktop link names
+    @rtype list of str
+    """
+    majorVersion, minorVersion = sys.version_info[:2]
+    linkTemplates = [
+        "eric6 (Python {0}.{1}).lnk",
+        "eric6 Browser (Python {0}.{1}).lnk",
+    ]
+    
+    return [l.format(majorVersion, minorVersion) for l in linkTemplates]
+
+
+def windowsProgramsEntry():
+    """
+    Function to generate the name of the Start Menu top entry.
+    
+    @return name of the Start Menu top entry
+    @rtype str
+    """
+    majorVersion, minorVersion = sys.version_info[:2]
+    return "eric6 (Python {0}.{1})".format(majorVersion, minorVersion)
+
+
 def main(argv):
     """
     The main function of the script.

eric ide

mercurial