eric6/eric6_post_install.py

branch
setup.py
changeset 6951
ef3e87580dc9
parent 6950
62e39a353cd9
child 7192
a22eee00b052
--- a/eric6/eric6_post_install.py	Tue Apr 16 19:43:53 2019 +0200
+++ b/eric6/eric6_post_install.py	Wed Apr 17 19:44:50 2019 +0200
@@ -4,6 +4,10 @@
 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
 #
 
+"""
+Module implemenzing the post install logic for 'pip install'.
+"""
+
 from __future__ import unicode_literals
 
 import sys
@@ -15,6 +19,7 @@
 ## Post installation hooks for Windows below
 ######################################################################
 
+
 def createWindowsLinks():
     """
     Create Desktop and Start Menu links.
@@ -144,17 +149,25 @@
 ## Post installation hooks for Linux below
 ######################################################################
 
+
 def copyLinuxMetaData():
     """
     Function to copy the meta data files.
     """
-    # TODO: .desktop files need patching of the exec line
-    srcDir = os.path.join(os.path.dirname(sysconfig.get_path("scripts")),
-                          "share")
+    scriptsDir = sysconfig.get_path("scripts")
+    srcDir = os.path.join(os.path.dirname(scriptsDir), "share")
     dstDir = os.path.join(os.path.expanduser("~"), ".local", "share")
-    for metaDir in ["applications", "icons", "appdata", "metainfo"]:
+    
+    for metaDir in ["icons", "appdata", "metainfo"]:
         copyMetaFilesTree(os.path.join(srcDir, metaDir),
                           os.path.join(dstDir, metaDir))
+    
+    for desktop in ["eric6.desktop", "eric6_browser.desktop"]:
+        copyDesktopFile(
+            os.path.join(srcDir, "applications", desktop),
+            os.path.join(dstDir, "applications", desktop),
+            scriptsDir
+        )
 
 
 def copyMetaFilesTree(src, dst):
@@ -181,13 +194,34 @@
         if os.path.isdir(srcname):
             copyMetaFilesTree(srcname, dstname)
 
+
+def copyDesktopFile(src, dst, scriptsdir):
+    """
+    Modify a desktop file and write it to its destination.
+    
+    @param src source file name (string)
+    @param dst destination file name (string)
+    @param scriptsdir directory containing the scripts (string)
+    """
+    f = open(src, "r", encoding="utf-8")
+    text = f.read()
+    f.close()
+    
+    text = text.replace("@BINDIR@", scriptsdir)
+    
+    f = open(dst, "w", encoding="utf-8")
+    f.write(text)
+    f.close()
+    os.chmod(dst, 0o644)
+
 ######################################################################
 ## Main script below
 ######################################################################
 
+
 def main():
     """
-    Main script
+    Main script orchestrating the platform dependent post installation tasks.
     """
     if sys.platform.startswith(("win", "cygwin")):
         createWindowsLinks()

eric ide

mercurial