Extended the uninstall script to remove the plug-ins directories, the data directory and the configuration directory.

Sun, 15 Nov 2015 13:31:39 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 15 Nov 2015 13:31:39 +0100
changeset 4561
5bc6ed226471
parent 4559
5af0cda900b3
child 4563
881340f4bd0c

Extended the uninstall script to remove the plug-ins directories, the data directory and the configuration directory.

install.py file | annotate | diff | comparison | revisions
uninstall.py file | annotate | diff | comparison | revisions
--- a/install.py	Sat Nov 14 14:38:17 2015 +0100
+++ b/install.py	Sun Nov 15 13:31:39 2015 +0100
@@ -9,8 +9,7 @@
 Installation script for the eric6 IDE and all eric6 related tools.
 """
 
-from __future__ import unicode_literals
-from __future__ import print_function
+from __future__ import unicode_literals, print_function
 try:
     import cStringIO as io
     import sip
--- a/uninstall.py	Sat Nov 14 14:38:17 2015 +0100
+++ b/uninstall.py	Sun Nov 15 13:31:39 2015 +0100
@@ -4,12 +4,13 @@
 # Copyright (c) 2002 - 2015 Detlev Offenbach <detlev@die-offenbachs.de>
 #
 # This is the uninstall script for eric6.
+#
 
 """
 Uninstallation script for the eric6 IDE and all eric6 related tools.
 """
 
-from __future__ import unicode_literals
+from __future__ import unicode_literals, print_function
 
 import sys
 import os
@@ -17,6 +18,10 @@
 import glob
 import distutils.sysconfig
 
+if sys.version_info[0] == 2:
+    import sip
+    sip.setapi('QString', 2)
+
 # get a local eric6config.py out of the way
 if os.path.exists("eric6config.py"):
     os.rename("eric6config.py", "eric6config.py.orig")
@@ -29,6 +34,8 @@
 includePythonVariant = False
 defaultMacAppBundleName = "eric6.app"
 defaultMacAppBundlePath = "/Applications"
+settingsNameOrganization = "Eric6"
+settingsNameGlobal = "eric6"
 
 # Define file name markers for Python variants
 PythonMarkers = {
@@ -193,8 +200,15 @@
                 if os.path.exists(bundlePath):
                     shutil.rmtree(bundlePath)
         
-        # TODO: ask to delete all plug-ins
-        # TODO: ask to delete configuration
+        # remove plug-in directories
+        removePluginDirectories()
+        
+        # remove the eric data directory
+        removeDataDirectory()
+        
+        # remove the eric configuration directory
+        removeConfigurationData()
+        
         print("\nUninstallation completed")
     except (IOError, OSError) as msg:
         sys.stderr.write(
@@ -202,6 +216,104 @@
         exit(7)
 
 
+def removePluginDirectories():
+    """
+    Remove the plug-in directories.
+    """
+    pathsToRemove = []
+    
+    globalPluginsDir = os.path.join(getConfig('mdir'), "eric6plugins")
+    if os.path.exists(globalPluginsDir):
+        pathsToRemove.append(globalPluginsDir)
+    
+    localPluginsDir = os.path.join(getConfigDir(), "eric6plugins")
+    if os.path.exists(localPluginsDir):
+        pathsToRemove.append(localPluginsDir)
+    
+    if pathsToRemove:
+        print("Found these plug-in directories")
+        for path in pathsToRemove:
+            print("  - {0}".format(path))
+        answer = "c"
+        while answer not in ["y", "Y", "n", "N", ""]:
+            if sys.version_info[0] == 2:
+                answer = raw_input(
+                    "Shall these directories be removed (y/N)? ")
+            else:
+                answer = input(
+                    "Shall these directories be removed (y/N)? ")
+        if answer in ["y", "Y"]:
+            for path in pathsToRemove:
+                shutil.rmtree(path)
+
+
+def removeDataDirectory():
+    """
+    Remove the eric data directory.
+    """
+    cfg = getConfigDir()
+    if os.path.exists(cfg):
+        print("Found the eric data directory")
+        print("  - {0}".format(cfg))
+        answer = "c"
+        while answer not in ["y", "Y", "n", "N", ""]:
+            if sys.version_info[0] == 2:
+                answer = raw_input(
+                    "Shall this directory be removed (y/N)? ")
+            else:
+                answer = input(
+                    "Shall this directory be removed (y/N)? ")
+        if answer in ["y", "Y"]:
+            shutil.rmtree(cfg)
+
+
+def removeConfigurationData():
+    """
+    Remove the eric configuration directory.
+    """
+    try:
+        from PyQt5.QtCore import QSettings
+    except ImportError:
+        try:
+            from PyQt4.QtCore import QSettings
+        except ImportError:
+            print("No PyQt variant installed. The configuration directory")
+            print("cannot be determined. You have to remove it manually.\n")
+            return
+    
+    settings = QSettings(QSettings.IniFormat, QSettings.UserScope,
+                         settingsNameOrganization, settingsNameGlobal)
+    settingsDir = os.path.dirname(settings.fileName())
+    if os.path.exists(settingsDir):
+        print("Found the eric configuration directory")
+        print("  - {0}".format(settingsDir))
+        answer = "c"
+        while answer not in ["y", "Y", "n", "N", ""]:
+            if sys.version_info[0] == 2:
+                answer = raw_input(
+                    "Shall this directory be removed (y/N)? ")
+            else:
+                answer = input(
+                    "Shall this directory be removed (y/N)? ")
+        if answer in ["y", "Y"]:
+            shutil.rmtree(settings)
+
+
+def getConfigDir():
+    """
+    Module function to get the name of the directory storing the config data.
+    
+    @return directory name of the config dir (string)
+    """
+    if sys.platform.startswith("win"):
+        cdn = "_eric6"
+        return os.path.join(os.path.expanduser("~"), cdn)
+    else:
+        cdn = ".eric6"
+        return os.path.join(
+            os.path.expanduser("~{0}".format(os.getlogin())), cdn)
+
+
 def main(argv):
     """
     The main function of the script.
@@ -248,7 +360,7 @@
         main(sys.argv)
     except SystemExit:
         raise
-    except:
+    except Exception:
         print("""An internal error occured.  Please report all the output of"""
               """ the program,\n"""
               """including the following traceback, to"""

eric ide

mercurial