install.py

changeset 5214
0473e5256ca9
parent 5145
95947ce71171
child 5239
27f56dc07b5b
--- a/install.py	Sat Oct 08 17:01:03 2016 +0200
+++ b/install.py	Sat Oct 08 19:59:32 2016 +0200
@@ -30,6 +30,7 @@
 import distutils.sysconfig
 import codecs
 import subprocess
+import time
 
 # Define the globals.
 progName = None
@@ -306,6 +307,43 @@
     os.chmod(dst, 0o644)
 
 
+def copyAppStreamFile(src, dst, marker):
+    """
+    Modify an appstream file and write it to its destination.
+    
+    @param src source file name (string)
+    @param dst destination file name (string)
+    @param marker marker to be used (string)
+    """
+    if os.path.exists(os.path.join("eric", "UI", "Info.py")):
+        # Installing from archive
+        from eric.UI.Info import Version
+    elif os.path.exists(os.path.join("UI", "Info.py")):
+        # Installing from source tree
+        from UI.Info import Version
+    else:
+        Version = "Unknown"
+    
+    if sys.version_info[0] == 2:
+        f = codecs.open(src, "r", "utf-8")
+    else:
+        f = open(src, "r", encoding="utf-8")
+    text = f.read()
+    f.close()
+    
+    text = text.replace("@MARKER@", marker)\
+        .replace("@VERSION@", Version.split(None, 1)[0])\
+        .replace("@DATE@", time.strftime("%Y-%m-%d"))
+    
+    if sys.version_info[0] == 2:
+        f = codecs.open(dst, "w", "utf-8")
+    else:
+        f = open(dst, "w", encoding="utf-8")
+    f.write(text)
+    f.close()
+    os.chmod(dst, 0o644)
+
+
 def wrapperName(dname, wfile):
     """
     Create the platform specific name for the wrapper script.
@@ -827,7 +865,7 @@
                 os.path.join(distDir, "usr/share/metainfo"))
             if not os.path.exists(dst):
                 os.makedirs(dst)
-            copyDesktopFile(
+            copyAppStreamFile(
                 os.path.join(sourceDir, "eric6.appdata.xml"),
                 os.path.join(dst, "eric6" + marker + ".appdata.xml"),
                 marker)
@@ -840,12 +878,12 @@
                 "/usr/share/applications/eric6" + marker + ".desktop",
                 marker)
             if os.path.exists("/usr/share/metainfo"):
-                copyDesktopFile(
+                copyAppStreamFile(
                     os.path.join(sourceDir, "eric6.appdata.xml"),
                     "/usr/share/metainfo/eric6" + marker + ".appdata.xml",
                     marker)
             elif os.path.exists("/usr/share/appdata"):
-                copyDesktopFile(
+                copyAppStreamFile(
                     os.path.join(sourceDir, "eric6.appdata.xml"),
                     "/usr/share/appdata/eric6" + marker + ".appdata.xml",
                     marker)

eric ide

mercurial