| 48 | self.bdata = {} |
| 49 | |
| 50 | def load(self): |
| 51 | data = self.bdata |
| 52 | if not os.path.exists(self.DPATH): |
| 53 | os.makedirs(self.DPATH) |
| 54 | self.fpath = os.path.join(self.DPATH, self.key + '.json') |
| 55 | |
| 56 | try: |
| 57 | with open(self.fpath, 'r') as _fh: |
| 58 | logging.debug("Loading data bag type %s", self.key) |
| 59 | data = json.load(_fh) |
| 60 | except (IOError, ValueError): |
| 61 | logging.debug("Caught load error, creating empty data bag type %s", self.key) |
| 62 | data.update({"id": self.key}) |
| 63 | finally: |
| 64 | self.dbag = data |
| 65 | |
| 66 | def save(self, dbag): |
| 67 | try: |