def load(self): filename = "./temp/rein_{}.txt".format(self.keyword) if os.path.isfile(filename): with locker.openl(filename) as fobj: self.db = pickle.load(fobj) else: self.db = ReinDatabase(self.keyword) self.bak = self.db.copy()
def save(self): filename = "./temp/rein_{}.txt".format(self.keyword) exists = True if not os.path.isfile(filename): # Create the file if it doesn't exist with open(filename, 'wb'): pass exists = False with locker.openl(filename) as fobj: db1 = self.db if exists: db2 = pickle.load(fobj) else: db2 = self.bak.copy() changes1 = db1 - self.bak changes2 = db2 - self.bak db_final = self.bak + changes1 + changes2 fobj.seek(0) fobj.truncate() pickle.dump(db_final, fobj) self.bak = db_final self.db = self.bak.copy()