scripts/install.py

changeset 7785
9978016560ec
parent 7775
4a1db75550bd
child 7799
5aeb0122e063
--- a/scripts/install.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/scripts/install.py	Wed Oct 14 17:50:39 2020 +0200
@@ -235,9 +235,8 @@
     @param name the name of the file.
     @param text the contents to copy to the file.
     """
-    f = open(name, "w")
-    f.write(text)
-    f.close()
+    with open(name, "w") as f:
+        f.write(text)
 
 
 def copyDesktopFile(src, dst):
@@ -249,17 +248,15 @@
     """
     global cfg, platBinDir
     
-    f = open(src, "r", encoding="utf-8")
-    text = f.read()
-    f.close()
+    with open(src, "r", encoding="utf-8") as f:
+        text = f.read()
     
     text = text.replace("@BINDIR@", platBinDir)
     text = text.replace("@MARKER@", "")
     text = text.replace("@PY_MARKER@", "")
     
-    f = open(dst, "w", encoding="utf-8")
-    f.write(text)
-    f.close()
+    with open(dst, "w", encoding="utf-8") as f:
+        f.write(text)
     os.chmod(dst, 0o644)
 
 
@@ -279,9 +276,8 @@
     else:
         Version = "Unknown"
     
-    f = open(src, "r", encoding="utf-8")
-    text = f.read()
-    f.close()
+    with open(src, "r", encoding="utf-8") as f:
+        text = f.read()
     
     text = (
         text.replace("@MARKER@", "")
@@ -289,9 +285,8 @@
         .replace("@DATE@", time.strftime("%Y-%m-%d"))
     )
     
-    f = open(dst, "w", encoding="utf-8")
-    f.write(text)
-    f.close()
+    with open(dst, "w", encoding="utf-8") as f:
+        f.write(text)
     os.chmod(dst, 0o644)
 
 
@@ -424,16 +419,15 @@
     if not os.path.exists(fname):
         if not os.path.exists(pdir):
             os.mkdir(pdir, 0o755)
-        f = open(fname, "w")
-        f.write(
-            '''# -*- coding: utf-8 -*-
+        with open(fname, "w") as f:
+            f.write(
+                '''# -*- coding: utf-8 -*-
 
 """
 Package containing the global plugins.
 """
 '''
-        )
-        f.close()
+            )
         os.chmod(fname, 0o644)
 
 
@@ -1690,9 +1684,8 @@
         hgOut = hgOut.strip()
         if hgOut.endswith("+"):
             hgOut = hgOut[:-1]
-        f = open(fileName + ".orig", "r", encoding="utf-8")
-        text = f.read()
-        f.close()
+        with open(fileName + ".orig", "r", encoding="utf-8") as f:
+            text = f.read()
         text = (
             text.replace("@@REVISION@@", hgOut)
             .replace("@@VERSION@@", "rev_" + hgOut)

eric ide

mercurial