eric6/PluginManager/PluginManager.py

changeset 7785
9978016560ec
parent 7400
e5d62581d002
child 7836
2f0d208b8137
diff -r 3257703e10c5 -r 9978016560ec eric6/PluginManager/PluginManager.py
--- a/eric6/PluginManager/PluginManager.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/eric6/PluginManager/PluginManager.py	Wed Oct 14 17:50:39 2020 +0200
@@ -206,8 +206,8 @@
             fname = os.path.join(path, "__init__.py")
             if not os.path.exists(fname):
                 try:
-                    f = open(fname, "w")
-                    f.close()
+                    with open(fname, "w"):
+                        pass
                 except IOError:
                     return (
                         False,
@@ -219,8 +219,8 @@
             if not os.path.exists(self.pluginDirs["user"]):
                 os.mkdir(self.pluginDirs["user"], 0o755)
             try:
-                f = open(fname, "w")
-                f.close()
+                with open(fname, "w"):
+                    pass
             except IOError:
                 del self.pluginDirs["user"]
         
@@ -231,13 +231,12 @@
             # create the global plugins directory
             os.mkdir(self.pluginDirs["global"], 0o755)
             fname = os.path.join(self.pluginDirs["global"], "__init__.py")
-            f = open(fname, "w", encoding="utf-8")
-            f.write('# -*- coding: utf-8 -*-' + "\n")
-            f.write("\n")
-            f.write('"""' + "\n")
-            f.write('Package containing the global plugins.' + "\n")
-            f.write('"""' + "\n")
-            f.close()
+            with open(fname, "w", encoding="utf-8") as f:
+                f.write('# -*- coding: utf-8 -*-' + "\n")
+                f.write("\n")
+                f.write('"""' + "\n")
+                f.write('Package containing the global plugins.' + "\n")
+                f.write('"""' + "\n")
         if not os.path.exists(self.pluginDirs["global"]):
             del self.pluginDirs["global"]
         

eric ide

mercurial