aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevan Franchini <twitch153@gentoo.org>2014-06-12 17:17:02 -0400
committerDevan Franchini <twitch153@gentoo.org>2014-06-14 20:36:41 -0400
commitb47238ef6ef407c7c07a94b885b7243a089c797f (patch)
tree7209618637f240494551b15bba63f8fcfd0037d6 /layman/dbbase.py
parentmercurial.py: Adds module branch support (diff)
downloadlayman-b47238ef6ef407c7c07a94b885b7243a089c797f.tar.gz
layman-b47238ef6ef407c7c07a94b885b7243a089c797f.tar.bz2
layman-b47238ef6ef407c7c07a94b885b7243a089c797f.zip
Implements the "with" syntax to open files
Diffstat (limited to 'layman/dbbase.py')
-rw-r--r--layman/dbbase.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/layman/dbbase.py b/layman/dbbase.py
index 92d5cf9..e17e8f3 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -131,8 +131,8 @@ class DbBase(object):
'''Read the overlay definition file.'''
try:
- df = fileopen(path, 'r')
- document = df.read()
+ with fileopen(path, 'r') as df:
+ document = df.read()
except Exception as error:
if not self.ignore_init_read_errors:
@@ -235,9 +235,9 @@ class DbBase(object):
indent(tree)
tree = ET.ElementTree(tree)
try:
- f = fileopen(path, 'w')
- tree.write(f, encoding=_UNICODE)
- f.close()
+ with fileopen(path, 'w') as f:
+ tree.write(f, encoding=_UNICODE)
+
except Exception as error:
raise Exception('Failed to write to local overlays file: '
+ path + '\nError was:\n' + str(error))