Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. class FileStorageManager(StorageManager):
  2.     def __init__(self, config):
  3.         super(FileStorageManager, self).__init__(config)
  4.         self.path = config.path
  5.         self.data = {}
  6.  
  7.     def __get_name(self):
  8.         return "Plain File Storage Manager"
  9.  
  10.  
  11.     def __to_json(self):
  12.         return json.dumps(self.data, default = lambda o: o.__dict__,
  13.                                             sort_keys=True, indent=4)
  14.  
  15.     def __load_from_json(self, json_str):
  16.         self.data = json.loads(json_str, object_hook=lambda d: namedtuple('X',
  17.                                                         d.keys())(*d.values()))
  18.     def load(self):
  19.         file = open(self.path, "r")
  20.  
  21.         print("Reading %s from file %s" % (self.__get_name(), self.path))
  22.         self.__load_from_json(file.read())
  23.  
  24.         file.close()
  25.  
  26.     def save(self):
  27.         file = open(self.path, "w")
  28.  
  29.         print("Writing %s to file %s" % (self.__get_name(), str(self.path)))
  30.         file.write(self.__to_json())
  31.  
  32.         file.close()
  33.  
  34. class GoogleDriveConfig(FileStorageManager):
  35.     def __init__(self, config):
  36.         super(FileStorageManager, self).__init__(config)
  37.  
  38.     def __get_name(self):
  39.         return "Google Drive Configuration"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement