hopefully fewer leaks in files : always use a context manager to open files
[nodemanager.git] / plugins / vsys_privs.py
index 01ab283..bf3b1d1 100755 (executable)
@@ -64,11 +64,12 @@ def read_privs():
                 pass
 
             for tagname in tagnames:
-                tagfile = os.path.join(slicedir,tagname)
-                values_n = file(tagfile).readlines()
-                values = map(lambda s:s.rstrip(),values_n)
-                slice = os.path.basename(slicedir)
-                cur_privs[slice][tagname]=values
+                tagfilename = os.path.join(slicedir,tagname)
+                with open(tagfilename) as tagfile:
+                    values_n = tagfile.readlines()
+                    values = [ v.rstrip() for v in values_n ]
+                    slice = os.path.basename(slicedir)
+                    cur_privs[slice][tagname] = values
 
     return cur_privs