Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FileStorageManager(StorageManager):
- def __init__(self, config):
- super(FileStorageManager, self).__init__(config)
- self.path = config.path
- self.data = {}
- def __get_name(self):
- return "Plain File Storage Manager"
- def __to_json(self):
- return json.dumps(self.data, default = lambda o: o.__dict__,
- sort_keys=True, indent=4)
- def __load_from_json(self, json_str):
- self.data = json.loads(json_str, object_hook=lambda d: namedtuple('X',
- d.keys())(*d.values()))
- def load(self):
- file = open(self.path, "r")
- print("Reading %s from file %s" % (self.__get_name(), self.path))
- self.__load_from_json(file.read())
- file.close()
- def save(self):
- file = open(self.path, "w")
- print("Writing %s to file %s" % (self.__get_name(), str(self.path)))
- file.write(self.__to_json())
- file.close()
- class GoogleDriveConfig(FileStorageManager):
- def __init__(self, config):
- super(FileStorageManager, self).__init__(config)
- def __get_name(self):
- return "Google Drive Configuration"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement