[serverconfig] fix ResourceWarning: unclosed file bootstrap_cubes
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 19 Oct 2015 17:53:51 +0200
changeset 10818 8cdf9965b2b8
parent 10817 7b154e0fa194
child 10819 5b5864483c4d
[serverconfig] fix ResourceWarning: unclosed file bootstrap_cubes
server/serverconfig.py
--- a/server/serverconfig.py	Mon Oct 19 14:29:53 2015 +0200
+++ b/server/serverconfig.py	Mon Oct 19 17:53:51 2015 +0200
@@ -236,15 +236,16 @@
 
     def bootstrap_cubes(self):
         from logilab.common.textutils import splitstrip
-        for line in open(join(self.apphome, 'bootstrap_cubes')):
-            line = line.strip()
-            if not line or line.startswith('#'):
-                continue
-            self.init_cubes(self.expand_cubes(splitstrip(line)))
-            break
-        else:
-            # no cubes
-            self.init_cubes(())
+        with open(join(self.apphome, 'bootstrap_cubes')) as f:
+            for line in f:
+                line = line.strip()
+                if not line or line.startswith('#'):
+                    continue
+                self.init_cubes(self.expand_cubes(splitstrip(line)))
+                break
+            else:
+                # no cubes
+                self.init_cubes(())
 
     def write_bootstrap_cubes_file(self, cubes):
         stream = open(join(self.apphome, 'bootstrap_cubes'), 'w')