summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgenbackupdata13
1 files changed, 6 insertions, 7 deletions
diff --git a/genbackupdata b/genbackupdata
index 7ed1ee8..168961b 100755
--- a/genbackupdata
+++ b/genbackupdata
@@ -77,13 +77,12 @@ class GenbackupdataApp(cliapp.Application):
dirname = os.path.dirname(pathname)
if not os.path.exists(dirname):
os.makedirs(dirname)
- f = open(pathname, 'wb')
- while bytes >= chunk_size:
- self.write_bytes(f, chunk_size)
- bytes -= chunk_size
- if bytes > 0:
- self.write_bytes(f, bytes)
- f.close()
+ with open(pathname, 'wb') as f:
+ while bytes >= chunk_size:
+ self.write_bytes(f, chunk_size)
+ bytes -= chunk_size
+ if bytes > 0:
+ self.write_bytes(f, bytes)
def write_bytes(self, f, bytes):
chunk = self.gen.generate(bytes)