]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
Use with to deal with an open file.
[forks/vmdebootstrap.git] / vmdebootstrap
index 67e5a409a87334f20be73884209e5a7e9de304e2..f85958701455513defd868c26ed93f71a80a193a 100755 (executable)
@@ -172,9 +172,8 @@ class VmDebootstrap(cliapp.Application):
 
     def set_hostname(self, rootdir):
         hostname = self.settings['hostname']
-        f = open(os.path.join(rootdir, 'etc', 'hostname'), 'w')
-        f.write(hostname)
-        f.close()
+        with open(os.path.join(rootdir, 'etc', 'hostname'), 'w') as f:
+            f.write(hostname)
 
     def set_root_password(self, rootdir):
         if self.settings['root-password']: