hopefully fewer leaks in files : always use a context manager to open files
[nodemanager.git] / initscript.py
index 2d054fb..a25e06a 100644 (file)
@@ -29,6 +29,7 @@ class Initscript:
                     self.rerun_slice_vinit()
             else:
                 logger.log("Initscript: %s: Removed obsolete initscript %s" % (self.name, sliver_initscript))
+
     def install_and_enable_vinit(self):
         "prepare sliver rootfs init and systemd so the vinit service kicks in"
         # the fact that systemd attempts to run old-style services 
@@ -54,7 +55,8 @@ class Initscript:
         enable_link = "/vservers/%s/etc/rc.d/rc3.d/S99vinit" % self.name
         enable_target = "../init.d/vinit"
         # install in sliver
-        code = file(vinit_source).read()
+        with open(vinit_source) as f:
+            code = f.read()
         if tools.replace_file_with_string(vinit_script, code, chmod=0755):
             logger.log("Initscript: %s: installed generic vinit rc script" % self.name)
         # create symlink for runlevel 3
@@ -75,14 +77,14 @@ class Initscript:
         ########## initscripts : current status - march 2015
         ##########
         #
-        # the initscripts business worked smoothly up to f18 incusive
+        # the initscripts business worked smoothly up to f18 inclusive
         # with f20 and the apparition of machinectl, things started to
         # behave really weird
         #
         # so starting with f20, after having tried pretty hard to get this right,
         # but to no success obviously, and in order to stay on the safe side
         # of the force, I am turning off the initscript machinery completely
-        # that is to say: the vinit.service does not get installed at all installed
+        # that is to say: the vinit.service does not get installed at all
         # 
         if os.path.isfile('/usr/bin/machinectl'):
             logger.log("WARNING: initscripts are not supported anymore in nodes that have machinectl")
@@ -93,7 +95,8 @@ class Initscript:
         enable_link = "/vservers/%s/etc/systemd/system/multi-user.target.wants/vinit.service" % self.name
         enable_target = "/usr/lib/systemd/system/vinit.service"
         # install in sliver
-        code = file(vinit_source).read()
+        with open(vinit_source) as f:
+            code = f.read()
         if tools.replace_file_with_string(vinit_unit_file, code, chmod=0755):
             logger.log("Initscript: %s: installed vinit.service unit file" % self.name)
         # create symlink for enabling this unit