コード例 #1
0
ファイル: config.py プロジェクト: kuangch/web_frame_flask
def post_settings():

    try:
        old_cfg = SerializeUtils.get(MyConstant.sys_config_serialize_data_key)
        if old_cfg is None:
            old_cfg = {}

        param = request.form.get('sysconfig', '{}')

        try:
            new_cfg = json.loads(param)
        except:
            logging.getLogger(GlobalInfo.logger_main).error(
                traceback.format_exc())
            return json.dumps({'code': -1, 'msg': 'param error'})

        # merge config
        cfg = dict(old_cfg.items() + new_cfg.items())

        SerializeUtils.update(MyConstant.sys_config_serialize_data_key, cfg)
        return json.dumps({'code': 0, 'msg': 'sys config success'})

    except:
        logging.getLogger(GlobalInfo.logger_main).error(traceback.format_exc())
        return json.dumps({'code': -1, 'msg': 'submit wrong!'})
コード例 #2
0
    def update_portals(ips):
        smss = ZMQConns().get_all()
        sms_keys = ([])
        ip_keys = ([])

        if type(ips) == dict:
            ip_keys_store = {}
        elif type(ips) == list:
            ip_keys_store = []
        else:
            raise NameError('parameter of this method must be dict or list')

        try:
            ip_keys = set(ips)
        except:
            pass
        try:
            sms_keys = set(smss)
        except:
            pass

        new_ips = ip_keys - sms_keys
        old_ips = sms_keys - ip_keys
        intersection_ips = ip_keys & sms_keys

        for ip_key in ip_keys:
            if type(ips) == dict:
                ip_keys_store[ip_key] = ips[ip_key]
            else:
                ip_keys_store.append(ip_key)

        for ip in intersection_ips:
            logging.getLogger(GlobalInfo.logger_main).info(
                'portal of ip: ' + ip + ' msg passageway is already exits')

        for ip in old_ips:
            if ZMQConns().get(ip) is not None:
                ZMQConns().get(ip).run_flag = False
                ZMQConns().remove(ip)

        for ip in new_ips:
            PortalMsgManager.add_new_conn(ip)

        SerializeUtils.update(MyConstant.portal_ips_serialize_data_key,
                              ip_keys_store)
コード例 #3
0
 def init_portals():
     ips = SerializeUtils.get(MyConstant.portal_ips_serialize_data_key)
     if ips is None:
         logging.getLogger(
             GlobalInfo.logger_main).info('no ip to init zmq conn')
         return
     ips = set(ips)
     for ip in ips:
         PortalMsgManager.add_new_conn(ip)
コード例 #4
0
 def init_sys_conf():
     logger_main = logging.getLogger(GlobalInfo.logger_main)
     try:
         SerializeData()\
             .update(MyConstant.sys_config_serialize_data_key,
                     SerializeUtils.get(MyConstant.sys_config_serialize_data_key))
         return True
     except:
         logger_main.info('persistent data path not exit')
         return False
コード例 #5
0
ファイル: config.py プロジェクト: kuangch/web_frame_flask
def get_settings():

    try:
        cfg = SerializeUtils.get(MyConstant.sys_config_serialize_data_key)
        if cfg is None:
            cfg = {}
        return json.dumps({
            'code': 0,
            'msg': 'get sys config success',
            'data': cfg
        })
    except:
        logging.getLogger(GlobalInfo.logger_main).error(traceback.format_exc())
        return json.dumps({'code': -1, 'msg': 'get sys config wrong!'})