summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-07-28 13:52:29 -0400
committerPatrick Williams <patrick@stwcx.xyz>2016-08-10 17:09:50 +0000
commit0127d51c137dbe8063b81012763550faf5111d87 (patch)
tree9072ad87dc118baa462b853b87ab82f9f27731d0
parentd637227acb61b0446f4e73e321bbb3848967ec53 (diff)
downloadpyphosphor-0127d51c137dbe8063b81012763550faf5111d87.tar.gz
pyphosphor-0127d51c137dbe8063b81012763550faf5111d87.zip
propertycacher: context manager for file open
Change-Id: Ib75f3f5ccbd35d7e70d9c171c0642077930c4741 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--obmc/dbuslib/propertycacher.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/obmc/dbuslib/propertycacher.py b/obmc/dbuslib/propertycacher.py
index ce83195..7888b46 100644
--- a/obmc/dbuslib/propertycacher.py
+++ b/obmc/dbuslib/propertycacher.py
@@ -34,16 +34,14 @@ def save(obj_path, iface_name, properties):
try:
if not os.path.exists(parent):
os.makedirs(parent)
- output = open(filename, 'wb')
- try:
- ## use json module to convert dbus datatypes
- props = json.dumps(properties[iface_name])
- prop_obj = json.loads(props)
- cPickle.dump(prop_obj, output)
- except Exception as e:
- print "ERROR: "+str(e)
- finally:
- output.close()
+ with open(filename, 'wb') as output:
+ try:
+ ## use json module to convert dbus datatypes
+ props = json.dumps(properties[iface_name])
+ prop_obj = json.loads(props)
+ cPickle.dump(prop_obj, output)
+ except Exception as e:
+ print "ERROR: "+str(e)
except:
print "ERROR opening cache file: "+filename
OpenPOWER on IntegriCloud