install.py

changeset 6214
89a53d80e729
parent 6213
d7695d0aa4e7
child 6216
2a0eeba143e7
--- a/install.py	Wed Apr 04 17:21:51 2018 +0200
+++ b/install.py	Wed Apr 04 19:48:25 2018 +0200
@@ -243,11 +243,16 @@
         if not os.path.exists(platBinDir):
             platBinDir = platBinDirOld
     else:
-        # TODO: install scripts into {venv}/bin for virtual environments
-        # 1.) assume it is venv if os.path.dirname(sys.executable) is not in
-        # (/opt/local/bin, /usr/local/bin, /usr/bin) and
-        # 2.) directory is writable by user
-        platBinDir = "/usr/local/bin"
+        pyBinDir = os.path.normpath(os.path.dirname(sys.executable))
+        if os.access(pyBinDir, os.W_OK):
+            # install the eric scripts along the python executable
+            platBinDir = pyBinDir
+        else:
+            # install them in the user's bin directory
+            platBinDir = os.path.expanduser("~/bin")
+        if platBinDir != "/usr/local/bin" and \
+           os.access("/usr/local/bin", os.W_OK):
+            platBinDirOld = "/usr/local/bin"
 
     modDir = distutils.sysconfig.get_python_lib(True)
     pyModDir = modDir
@@ -256,7 +261,11 @@
     if os.path.exists(os.path.join(pyqtDataDir, "qsci")):
         # it's the installer
         qtDataDir = pyqtDataDir
+    elif os.path.exists(os.path.join(pyqtDataDir, "Qt", "qsci")):
+        # it's the wheel
+        qtDataDir = os.path.join(pyqtDataDir, "Qt")
     else:
+        # determine dynamically
         try:
             if pyqtVariant == "PyQt4":
                 from PyQt4.QtCore import QLibraryInfo
@@ -551,25 +560,54 @@
     global pyModDir, progLanguages
     
     # Remove the menu entry for Linux systems
-    if sys.platform.startswith("linux") and 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",
-                     ]:
-            if os.path.exists(name):
-                os.remove(name)
+    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)
     
     # Remove the wrapper scripts
     rem_wnames = [
@@ -602,9 +640,9 @@
         
         # Cleanup our config file(s)
         for name in ['eric6config.py', 'eric6config.pyc', 'eric6.pth']:
-            e5cfile = os.path.join(pyModDir, name)
-            if os.path.exists(e5cfile):
-                os.remove(e5cfile)
+            e6cfile = os.path.join(pyModDir, name)
+            if os.path.exists(e6cfile):
+                os.remove(e6cfile)
             e5cfile = os.path.join(pyModDir, "__pycache__", name)
             path, ext = os.path.splitext(e5cfile)
             for f in glob.glob("{0}.*{1}".format(path, ext)):
@@ -814,6 +852,8 @@
     if installApis:
         for progLanguage in progLanguages:
             apidir = os.path.join(cfg['apidir'], progLanguage.lower())
+            print("Installing {0} API files to '{1}'.".format(
+                progLanguage, apidir))
             if not os.path.exists(apidir):
                 os.makedirs(apidir)
             for apiName in glob.glob(os.path.join(sourceDir, "APIs",
@@ -821,13 +861,15 @@
                 try:
                     shutilCopy(apiName, apidir)
                 except EnvironmentError:
-                    print("Could not install '{0}'.".format(apiName))
+                    print("Could not install '{0}' (no permission)."
+                          .format(apiName))
             for apiName in glob.glob(os.path.join(sourceDir, "APIs",
                                                   progLanguage, "*.bas")):
                 try:
                     shutilCopy(apiName, apidir)
                 except EnvironmentError:
-                    print("Could not install '{0}'.".format(apiName))
+                    print("Could not install '{0}' (no permission)."
+                          .format(apiName))
             if progLanguage == "Python":
                 # copy Python3 API files to the same destination
                 for apiName in glob.glob(os.path.join(sourceDir, "APIs",
@@ -835,7 +877,8 @@
                     try:
                         shutilCopy(apiName, apidir)
                     except EnvironmentError:
-                        print("Could not install '{0}'.".format(apiName))
+                        print("Could not install '{0}' (no permission)."
+                              .format(apiName))
                 for apiName in glob.glob(os.path.join(sourceDir, "APIs",
                                                       "Python3", "*.bas")):
                     if os.path.exists(os.path.join(
@@ -844,7 +887,8 @@
                         try:
                             shutilCopy(apiName, apidir)
                         except EnvironmentError:
-                            print("Could not install '{0}'.".format(apiName))
+                            print("Could not install '{0}' (no permission)."
+                                  .format(apiName))
     
     # create menu entry for Linux systems
     if sys.platform.startswith("linux"):
@@ -917,6 +961,48 @@
                 "/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")
+            # 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 a Mac application bundle
     if sys.platform == "darwin":

eric ide

mercurial