Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
Arquivo: disk.py Projeto: jhgg/disco
    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())
Exemplo n.º 4
0
    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 = {}
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
 def get(self, key):
     return Serializer.loads(self.format,
                             self.db.get(self.k(key)).decode('utf-8'))
Exemplo n.º 7
0
 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')))
Exemplo n.º 8
0
 def get(self, key):
     return Serializer.loads(self.format, self.conn.get(key))
Exemplo n.º 9
0
 def get_many(self, keys):
     for key, value in izip(keys, self.conn.mget(keys)):
         yield (key, Serializer.loads(self.format, value))