Esempio n. 1
0
def register_connected_ws(message, ws):
    try:
        if ws not in connected[message.config_name]:
            connected[message.config_name].add(ws)
        connected_message[ws] = message
    except KeyError:
        raise ProjectNoFoundException(config_name=message.config_name)
Esempio n. 2
0
 def read(self, config_name, default=None, check_exist=False):
     model = self.db_client[self._config_data_scope].find_one({'config_name': config_name})
     if not model:
         if check_exist:
             raise ProjectNoFoundException(config_name=config_name)
         else:
             return default
     return model['data']
Esempio n. 3
0
 def read(self, config_name, default=None, check_exist=False):
     if isinstance(default, dict):
         default = json.dumps(default).encode(self.__charset__)
     else:
         default = b'{}'
     data = self.redis_client.hget(self._config_data_scope, config_name)
     if data is None and check_exist:
         raise ProjectNoFoundException(config_name=config_name)
     return json.loads((data or default).decode(self.__charset__))
Esempio n. 4
0
 def read(self, config_name, default=None, check_exist=False):
     file_path = self.get_file_path(config_name)
     try:
         with io.open(file_path, encoding=self.__charset__) as open_file:
             source_data = json.load(open_file)
         logger.debug("Backend read json: {}".format(file_path))
     except IOError:
         logger.debug("Backend read json: {} (Ignored, file not Found)".format(file_path))
         if check_exist:
             raise ProjectNoFoundException(config_name=config_name)
         source_data = default or {}
     return source_data
Esempio n. 5
0
def get_config_store(config_name):
    try:
        return config_store_state[config_name]
    except KeyError:
        raise ProjectNoFoundException(config_name=config_name)