def get_many(self, keys): keys = list(keys) if not len(keys): raise StopIteration for key, value in izip(keys, self.conn.mget(keys)): yield (key, Serializer.loads(self.format, value))
def load_plugin_config(self, cls): name = cls.__name__.lower() if name.endswith('plugin'): name = name[:-6] path = os.path.join(self.config.plugin_config_dir, name) + '.' + self.config.plugin_config_format data = {} if self.config.shared_config: data.update(self.config.shared_config) if name in self.config.plugin_config: data.update(self.config.plugin_config[name]) if os.path.exists(path): with open(path, 'r') as f: data.update( Serializer.loads(self.config.plugin_config_format, f.read())) if hasattr(cls, 'config_cls'): inst = cls.config_cls() if data: inst.update(data) return inst return data
def load(self): if not os.path.exists(self.path): return if self.config.get('autosave', True): self.autosave_task = gevent.spawn( self.autosave_loop, self.config.get('autosave_interval', 120)) with open(self.path, 'r') as f: self.data = Serializer.loads(self.format, f.read())
def __init__(self, ctx, config): self._ctx = ctx self._path = config.path self._serializer = config.serializer self._fsync = config.fsync self._data = {} if os.path.exists(self._path): with open(self._path, 'r') as f: self._data = Serializer.loads(self._serializer, f.read()) if not self._data: self._data = {}
def load_plugin_config(self, cls): name = cls.__name__.lower() if name.endswith('plugin'): name = name[:-6] path = os.path.join(self.config.plugin_config_dir, name) + '.' + self.config.plugin_config_format if not os.path.exists(path): if hasattr(cls, 'config_cls'): return cls.config_cls() return with open(path, 'r') as f: data = Serializer.loads(self.config.plugin_config_format, f.read()) if hasattr(cls, 'config_cls'): inst = cls.config_cls() inst.update(data) return inst return data
def set(self, key, value): self.db.put(self.k(key), Serializer.dumps(self.format, value))
def get(self, key): return Serializer.loads(self.format, self.db.get(self.k(key)).decode('utf-8'))
def get_many(self, keys): for key, value in izip(keys, self.db.multi_get(list(map(self.k, keys)))): yield (key, Serializer.loads(self.format, value.decode('utf-8')))
def set(self, key, value): self.conn.set(key, Serializer.dumps(self.format, value))
def get(self, key): return Serializer.loads(self.format, self.conn.get(key))
def save(self): if not self._path: return with open(self._path, 'w') as f: f.write(Serializer.dumps(self._serializer, self._data))
def get_many(self, keys): for key, value in izip(keys, self.conn.mget(keys)): yield (key, Serializer.loads(self.format, value))
def save(self): with open(self.path, 'w') as f: f.write(Serializer.dumps(self.format, self.data))