propertycacher: context manager for file open

Change-Id: Ib75f3f5ccbd35d7e70d9c171c0642077930c4741
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
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 @@
     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