]> git.siccegge.de Git - forks/vmdebootstrap.git/commitdiff
Use with to deal with an open file.
authorLars Wirzenius <liw@liw.fi>
Wed, 29 Jun 2011 15:19:50 +0000 (16:19 +0100)
committerLars Wirzenius <liw@liw.fi>
Wed, 29 Jun 2011 15:19:50 +0000 (16:19 +0100)
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']: