install.py

changeset 6500
0373580fc86c
parent 6495
6e73d31af3af
child 6509
884182bfd25c
--- a/install.py	Sat Sep 15 19:59:20 2018 +0200
+++ b/install.py	Sun Sep 16 18:15:43 2018 +0200
@@ -573,53 +573,7 @@
     
     # Remove the menu entry for Linux systems
     if sys.platform.startswith("linux"):
-        if os.getuid() == 0:
-            for name in ["/usr/share/pixmaps/eric.png",
-                         "/usr/share/pixmaps/ericWeb.png"]:
-                if os.path.exists(name):
-                    os.remove(name)
-            if includePythonVariant:
-                marker = PythonMarkers[sys.version_info.major]
-            else:
-                marker = ""
-            for name in [
-                "/usr/share/applications/eric6" + marker + ".desktop",
-                "/usr/share/appdata/eric6" + marker + ".appdata.xml",
-                "/usr/share/metainfo/eric6" + marker + ".appdata.xml",
-                "/usr/share/applications/eric6_webbrowser" + marker +
-                ".desktop",
-                "/usr/share/applications/eric6_browser" + marker +
-                ".desktop",
-                "/usr/share/pixmaps/eric" + marker + ".png",
-                "/usr/share/pixmaps/ericWeb" + marker + ".png",
-            ]:
-                if os.path.exists(name):
-                    os.remove(name)
-        elif os.getuid() >= 1000:
-            # it is assumed that user ids start at 1000
-            for name in ["~/.local/share/pixmaps/eric.png",
-                         "~/.local/share/pixmaps/ericWeb.png"]:
-                path = os.path.expanduser(name)
-                if os.path.exists(path):
-                    os.remove(path)
-            if includePythonVariant:
-                marker = PythonMarkers[sys.version_info.major]
-            else:
-                marker = ""
-            for name in [
-                "~/.local/share/applications/eric6" + marker + ".desktop",
-                "~/.local/share/appdata/eric6" + marker + ".appdata.xml",
-                "~/.local/share/metainfo/eric6" + marker + ".appdata.xml",
-                "~/.local/share/applications/eric6_webbrowser" + marker +
-                ".desktop",
-                "~/.local/share/applications/eric6_browser" + marker +
-                ".desktop",
-                "~/.local/share/pixmaps/eric" + marker + ".png",
-                "~/.local/share/pixmaps/ericWeb" + marker + ".png",
-            ]:
-                path = os.path.expanduser(name)
-                if os.path.exists(path):
-                    os.remove(path)
+        cleanUpLinuxSpecifics()
     
     # Remove the wrapper scripts
     rem_wnames = [
@@ -691,25 +645,92 @@
         
         if sys.platform == "darwin":
             # delete the Mac app bundle
-            try:
-                macAppBundlePath = getConfig("macAppBundlePath")
-                macAppBundleName = getConfig("macAppBundleName")
-            except AttributeError:
-                macAppBundlePath = defaultMacAppBundlePath
-                macAppBundleName = defaultMacAppBundleName
-            for bundlePath in [os.path.join(defaultMacAppBundlePath,
-                                            macAppBundleName),
-                               os.path.join(macAppBundlePath,
-                                            macAppBundleName),
-                               ]:
-                if os.path.exists(bundlePath):
-                    shutil.rmtree(bundlePath)
+            cleanUpMacAppBundle()
     except (IOError, OSError) as msg:
         sys.stderr.write(
             'Error: {0}\nTry install with admin rights.\n'.format(msg))
         exit(7)
 
 
+def cleanUpLinuxSpecifics():
+    """
+    Clean up Linux specific files.
+    """
+    if os.getuid() == 0:
+        for name in ["/usr/share/pixmaps/eric.png",
+                     "/usr/share/pixmaps/ericWeb.png"]:
+            if os.path.exists(name):
+                os.remove(name)
+        if includePythonVariant:
+            marker = PythonMarkers[sys.version_info.major]
+        else:
+            marker = ""
+        for name in [
+            "/usr/share/applications/eric6" + marker + ".desktop",
+            "/usr/share/appdata/eric6" + marker + ".appdata.xml",
+            "/usr/share/metainfo/eric6" + marker + ".appdata.xml",
+            "/usr/share/applications/eric6_webbrowser" + marker +
+            ".desktop",
+            "/usr/share/applications/eric6_browser" + marker +
+            ".desktop",
+            "/usr/share/pixmaps/eric" + marker + ".png",
+            "/usr/share/pixmaps/ericWeb" + marker + ".png",
+        ]:
+            if os.path.exists(name):
+                os.remove(name)
+    elif os.getuid() >= 1000:
+        # it is assumed that user ids start at 1000
+        for name in ["~/.local/share/pixmaps/eric.png",
+                     "~/.local/share/pixmaps/ericWeb.png"]:
+            path = os.path.expanduser(name)
+            if os.path.exists(path):
+                os.remove(path)
+        if includePythonVariant:
+            marker = PythonMarkers[sys.version_info.major]
+        else:
+            marker = ""
+        for name in [
+            "~/.local/share/applications/eric6" + marker + ".desktop",
+            "~/.local/share/appdata/eric6" + marker + ".appdata.xml",
+            "~/.local/share/metainfo/eric6" + marker + ".appdata.xml",
+            "~/.local/share/applications/eric6_webbrowser" + marker +
+            ".desktop",
+            "~/.local/share/applications/eric6_browser" + marker +
+            ".desktop",
+            "~/.local/share/pixmaps/eric" + marker + ".png",
+            "~/.local/share/pixmaps/ericWeb" + marker + ".png",
+        ]:
+            path = os.path.expanduser(name)
+            if os.path.exists(path):
+                os.remove(path)
+
+
+def cleanUpMacAppBundle():
+    """
+    Uninstall the macOS application bundle.
+    """
+    from eric6config import getConfig
+    try:
+        macAppBundlePath = getConfig("macAppBundlePath")
+        macAppBundleName = getConfig("macAppBundleName")
+    except AttributeError:
+        macAppBundlePath = defaultMacAppBundlePath
+        macAppBundleName = defaultMacAppBundleName
+    for bundlePath in [os.path.join(defaultMacAppBundlePath,
+                                    macAppBundleName),
+                       os.path.join(macAppBundlePath,
+                                    macAppBundleName),
+                       ]:
+        if os.path.exists(bundlePath):
+            shutil.rmtree(bundlePath)
+
+
+def cleanUpWindowsLinks():
+    """
+    Clean up the Desktop and Start Menu entries for Windows.
+    """
+
+
 def shutilCopy(src, dst, perm=0o644):
     """
     Wrapper function around shutil.copy() to ensure the permissions.
@@ -902,120 +923,13 @@
                             print("Could not install '{0}' (no permission)."
                                   .format(apiName))
     
-    # create menu entry for Linux systems
+    # Create menu entry for Linux systems
     if sys.platform.startswith("linux"):
-        if includePythonVariant:
-            marker = PythonMarkers[sys.version_info.major]
-        else:
-            marker = ""
+        createLinuxSpecifics()
     
-        if distDir:
-            dst = os.path.normpath(os.path.join(distDir, "usr/share/pixmaps"))
-            if not os.path.exists(dst):
-                os.makedirs(dst)
-            shutilCopy(
-                os.path.join(sourceDir, "icons", "default", "eric.png"),
-                os.path.join(dst, "eric" + marker + ".png"))
-            shutilCopy(
-                os.path.join(sourceDir, "icons", "default", "ericWeb48.png"),
-                os.path.join(dst, "ericWeb" + marker + ".png"))
-            dst = os.path.normpath(
-                os.path.join(distDir, "usr/share/applications"))
-            if not os.path.exists(dst):
-                os.makedirs(dst)
-            copyDesktopFile(os.path.join(sourceDir, "eric6.desktop"),
-                            os.path.join(dst, "eric6" + marker + ".desktop"),
-                            marker)
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6_webbrowser.desktop"),
-                os.path.join(dst, "eric6_webbrowser" + marker + ".desktop"),
-                marker)
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6_browser.desktop"),
-                os.path.join(dst, "eric6_browser" + marker + ".desktop"),
-                marker)
-            dst = os.path.normpath(
-                os.path.join(distDir, "usr/share/metainfo"))
-            if not os.path.exists(dst):
-                os.makedirs(dst)
-            copyAppStreamFile(
-                os.path.join(sourceDir, "eric6.appdata.xml"),
-                os.path.join(dst, "eric6" + marker + ".appdata.xml"),
-                marker)
-        elif os.getuid() == 0:
-            shutilCopy(os.path.join(
-                sourceDir, "icons", "default", "eric.png"),
-                "/usr/share/pixmaps/eric" + marker + ".png")
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6.desktop"),
-                "/usr/share/applications/eric6" + marker + ".desktop",
-                marker)
-            if os.path.exists("/usr/share/metainfo"):
-                copyAppStreamFile(
-                    os.path.join(sourceDir, "eric6.appdata.xml"),
-                    "/usr/share/metainfo/eric6" + marker + ".appdata.xml",
-                    marker)
-            elif os.path.exists("/usr/share/appdata"):
-                copyAppStreamFile(
-                    os.path.join(sourceDir, "eric6.appdata.xml"),
-                    "/usr/share/appdata/eric6" + marker + ".appdata.xml",
-                    marker)
-            shutilCopy(os.path.join(
-                sourceDir, "icons", "default", "ericWeb48.png"),
-                "/usr/share/pixmaps/ericWeb" + marker + ".png")
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6_webbrowser.desktop"),
-                "/usr/share/applications/eric6_webbrowser" + marker +
-                ".desktop",
-                marker)
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6_browser.desktop"),
-                "/usr/share/applications/eric6_browser" + marker +
-                ".desktop",
-                marker)
-        elif os.getuid() >= 1000:
-            # it is assumed, that user ids start at 1000
-            localPath = os.path.join(os.path.expanduser("~"),
-                                     ".local", "share")
-            # create directories first
-            for directory in [os.path.join(localPath, name)
-                              for name in ("pixmaps", "applications",
-                                           "metainfo", "appdata")]:
-                if not os.path.isdir(directory):
-                    os.makedirs(directory)
-            # now copy the files
-            shutilCopy(
-                os.path.join(sourceDir, "icons", "default", "eric.png"),
-                os.path.join(localPath, "pixmaps", "eric" + marker + ".png"))
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6.desktop"),
-                os.path.join(localPath, "applications",
-                             "eric6" + marker + ".desktop"),
-                marker)
-            copyAppStreamFile(
-                os.path.join(sourceDir, "eric6.appdata.xml"),
-                os.path.join(localPath, "metainfo",
-                             "eric6" + marker + ".appdata.xml"),
-                marker)
-            copyAppStreamFile(
-                os.path.join(sourceDir, "eric6.appdata.xml"),
-                os.path.join(localPath, "appdata",
-                             "eric6" + marker + ".appdata.xml"),
-                marker)
-            shutilCopy(
-                os.path.join(sourceDir, "icons", "default", "ericWeb48.png"),
-                os.path.join(localPath, "pixmaps",
-                             "ericWeb" + marker + ".png"))
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6_webbrowser.desktop"),
-                os.path.join(localPath, "applications",
-                             "eric6_webbrowser" + marker + ".desktop"),
-                marker)
-            copyDesktopFile(
-                os.path.join(sourceDir, "eric6_browser.desktop"),
-                os.path.join(localPath, "applications",
-                             "eric6_browser" + marker + ".desktop"),
-                marker)
+    # Create Desktop and Start Menu entries for Windows systems
+    if sys.platform.startswith("win"):
+        createWindowsLinks()
     
     # Create a Mac application bundle
     if sys.platform == "darwin":
@@ -1024,12 +938,147 @@
     return 0
 
 
+def createLinuxSpecifics():
+    """
+    Install Linux specific files.
+    """
+    global distDir, sourceDir, includePythonVariant
+    
+    if includePythonVariant:
+        marker = PythonMarkers[sys.version_info.major]
+    else:
+        marker = ""
+
+    if distDir:
+        dst = os.path.normpath(os.path.join(distDir, "usr/share/pixmaps"))
+        if not os.path.exists(dst):
+            os.makedirs(dst)
+        shutilCopy(
+            os.path.join(sourceDir, "icons", "default", "eric.png"),
+            os.path.join(dst, "eric" + marker + ".png"))
+        shutilCopy(
+            os.path.join(sourceDir, "icons", "default", "ericWeb48.png"),
+            os.path.join(dst, "ericWeb" + marker + ".png"))
+        dst = os.path.normpath(
+            os.path.join(distDir, "usr/share/applications"))
+        if not os.path.exists(dst):
+            os.makedirs(dst)
+        copyDesktopFile(os.path.join(sourceDir, "eric6.desktop"),
+                        os.path.join(dst, "eric6" + marker + ".desktop"),
+                        marker)
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6_webbrowser.desktop"),
+            os.path.join(dst, "eric6_webbrowser" + marker + ".desktop"),
+            marker)
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6_browser.desktop"),
+            os.path.join(dst, "eric6_browser" + marker + ".desktop"),
+            marker)
+        dst = os.path.normpath(
+            os.path.join(distDir, "usr/share/metainfo"))
+        if not os.path.exists(dst):
+            os.makedirs(dst)
+        copyAppStreamFile(
+            os.path.join(sourceDir, "eric6.appdata.xml"),
+            os.path.join(dst, "eric6" + marker + ".appdata.xml"),
+            marker)
+    elif os.getuid() == 0:
+        shutilCopy(os.path.join(
+            sourceDir, "icons", "default", "eric.png"),
+            "/usr/share/pixmaps/eric" + marker + ".png")
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6.desktop"),
+            "/usr/share/applications/eric6" + marker + ".desktop",
+            marker)
+        if os.path.exists("/usr/share/metainfo"):
+            copyAppStreamFile(
+                os.path.join(sourceDir, "eric6.appdata.xml"),
+                "/usr/share/metainfo/eric6" + marker + ".appdata.xml",
+                marker)
+        elif os.path.exists("/usr/share/appdata"):
+            copyAppStreamFile(
+                os.path.join(sourceDir, "eric6.appdata.xml"),
+                "/usr/share/appdata/eric6" + marker + ".appdata.xml",
+                marker)
+        shutilCopy(os.path.join(
+            sourceDir, "icons", "default", "ericWeb48.png"),
+            "/usr/share/pixmaps/ericWeb" + marker + ".png")
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6_webbrowser.desktop"),
+            "/usr/share/applications/eric6_webbrowser" + marker +
+            ".desktop",
+            marker)
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6_browser.desktop"),
+            "/usr/share/applications/eric6_browser" + marker +
+            ".desktop",
+            marker)
+    elif os.getuid() >= 1000:
+        # it is assumed, that user ids start at 1000
+        localPath = os.path.join(os.path.expanduser("~"),
+                                 ".local", "share")
+        # create directories first
+        for directory in [os.path.join(localPath, name)
+                          for name in ("pixmaps", "applications",
+                                       "metainfo", "appdata")]:
+            if not os.path.isdir(directory):
+                os.makedirs(directory)
+        # now copy the files
+        shutilCopy(
+            os.path.join(sourceDir, "icons", "default", "eric.png"),
+            os.path.join(localPath, "pixmaps", "eric" + marker + ".png"))
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6.desktop"),
+            os.path.join(localPath, "applications",
+                         "eric6" + marker + ".desktop"),
+            marker)
+        copyAppStreamFile(
+            os.path.join(sourceDir, "eric6.appdata.xml"),
+            os.path.join(localPath, "metainfo",
+                         "eric6" + marker + ".appdata.xml"),
+            marker)
+        copyAppStreamFile(
+            os.path.join(sourceDir, "eric6.appdata.xml"),
+            os.path.join(localPath, "appdata",
+                         "eric6" + marker + ".appdata.xml"),
+            marker)
+        shutilCopy(
+            os.path.join(sourceDir, "icons", "default", "ericWeb48.png"),
+            os.path.join(localPath, "pixmaps",
+                         "ericWeb" + marker + ".png"))
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6_webbrowser.desktop"),
+            os.path.join(localPath, "applications",
+                         "eric6_webbrowser" + marker + ".desktop"),
+            marker)
+        copyDesktopFile(
+            os.path.join(sourceDir, "eric6_browser.desktop"),
+            os.path.join(localPath, "applications",
+                         "eric6_browser" + marker + ".desktop"),
+            marker)
+
+
+def createWindowsLinks():
+    """
+    Create Desktop and Start Menu links.
+    """
+    try:
+        from win32com.client import Dispatch
+    except ImportError:
+        print(
+            "\nThe Python package 'pywin32' is not installed. Desktop and"
+            " Start Menu entries will not be created."
+        )
+        return
+
+
 def createMacAppBundle(pydir):
     """
     Create a Mac application bundle.
 
     @param pydir the name of the directory where the Python script will
-        eventually be installed (string)
+        eventually be installed
+    @type str
     """
     global cfg, sourceDir, macAppBundleName, macPythonExe, macAppBundlePath, \
         pyqtVariant

eric ide

mercurial