hopefully fewer leaks in files : always use a context manager to open files
[nodemanager.git] / plugins / vsys_privs.py
index dea3b44..bf3b1d1 100755 (executable)
@@ -1,6 +1,3 @@
-# $Id$
-# $URL$
-
 """
 vsys sub-configurator.  Maintains configuration parameters associated with vsys scripts.
 All slice attributes with the prefix vsys_ are written into configuration files on the
@@ -12,7 +9,7 @@ import os
 
 VSYS_PRIV_DIR = "/etc/planetlab/vsys-attributes"
 
-def start(options, conf):
+def start():
     logger.log("vsys_privs: plugin starting")
     if (not os.path.exists(VSYS_PRIV_DIR)):
         os.makedirs(VSYS_PRIV_DIR)
@@ -67,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