94cdb4d4 | # Copyright (C) 2015 vmware inc. # # Author: Sharath George <sharathg@vmware.com> import json import collections class JsonWrapper(object): |
87815216 | def __init__(self, filename): |
94cdb4d4 | self.filename = filename |
87815216 | self.data = None |
94cdb4d4 | def read(self): |
87815216 | try: with open(self.filename) as json_data: self.data = json.load(json_data, object_pairs_hook=collections.OrderedDict) except Exception as _: raise Exception("Unable to read {}".format(self.filename)) |
94cdb4d4 | return self.data |
87815216 | def write(self, data): |
94cdb4d4 | self.data = data |
87815216 | try: with open(self.filename, 'w') as outfile: json.dump(data, outfile) except Exception as _: raise Exception("Unable to write {}".format(self.filename)) |