当前位置: 首页>>代码示例>>Python>>正文


Python message.MQMessage类代码示例

本文整理汇总了Python中domogik.mq.message.MQMessage的典型用法代码示例。如果您正苦于以下问题:Python MQMessage类的具体用法?Python MQMessage怎么用?Python MQMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MQMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _on_message

    def _on_message(self, msg):
        """Helper method called on message receive.

        msg is a list w/ the message parts
        """
        # 1st part is empty
        msg.pop(0)
        # 2nd part is protocol version
        # TODO: version check
        proto = msg.pop(0)
        # 3rd part is message type
        msg_type = msg.pop(0)
        # XXX: hardcoded message types!
        # any message resets the liveness counter
        self.need_handshake = False
        self.curr_liveness = self.HB_LIVENESS
        if msg_type == b'\x05': # disconnect
            self.curr_liveness = 0 # reconnect will be triggered by hb timer
        elif msg_type == b'\x02': # request
            # remaining parts are the user message
            envelope, msg = split_address(msg)
            envelope.append(b'')
            envelope = [ b'', self._proto_version, b'\x03'] + envelope # REPLY
            self.envelope = envelope
            mes = MQMessage()
            mes.set(msg)
            self.on_mdp_request(mes)
        else:
            # invalid message
            # ignored
            pass
        return
开发者ID:Basilic,项目名称:domogik,代码行数:32,代码来源:worker.py

示例2: check_config

def check_config(type, name, host, key, exp_value):
    cli = MQSyncReq(zmq.Context())
    msg = MQMessage()
    msg.set_action('config.get')
    msg.add_data('type', type)
    msg.add_data('host', host)
    msg.add_data('name', name)
    msg.add_data('key', key)
    result = cli.request('dbmgr', msg.get(), timeout=10)
    if result:
	data = result.get_data()
	if 'status' in data:
	    if not data['status']:
                print(result.get())
	        raise RuntimeError("DbMgr did not return status true on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
            else:
                if 'value' in data:
                    if data['value'] != exp_value:
       			print(result.get())
                        raise RuntimeError("The returned value is not the expected value for {0}-{1}.{2} : {3} = {4} but received {5}".format(type, name, host, key, exp_value, data['value']))
		    else:
                        return True
                else:
                    print(result.get())
	            raise RuntimeError("DbMgr did not return a value on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
        else:
	    print(result.get())
	    raise RuntimeError("DbMgr did not return a status on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
    else:
        raise RuntimeError("Error while setting configuration for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
开发者ID:Basilic,项目名称:domogik,代码行数:30,代码来源:helpers.py

示例3: client_devices_new

def client_devices_new(client_id):
    cli = MQSyncReq(app.zmq_context)
    msg = MQMessage()
    msg.set_action('client.detail.get')
    res = cli.request('manager', msg.get(), timeout=10)
    if res is not None:
        detaila = res.get_data()
        data = detaila[client_id]['data']
    else:
        data = {}
    if type(data["device_types"]) is not dict:
        dtypes = {}
    else:
        dtypes = list(data["device_types"].keys())
    products = {}
    if "products" in data:
        for prod in data["products"]:
            products[prod["name"]] = prod["type"]
 
    return render_template('client_device_new.html',
            device_types = dtypes,
            products = products,
            clientid = client_id,
            mactve="clients",
            active = 'devices'
            )
开发者ID:mehrdad-s,项目名称:domogik,代码行数:26,代码来源:clients.py

示例4: _mdp_reply_plugin_stop

    def _mdp_reply_plugin_stop(self, data):
        """ Stop the plugin
            @param data : MQ req message

            First, send the MQ Rep to 'ack' the request
            Then, change the plugin status to STATUS_STOP_REQUEST
            Then, quit the plugin by calling force_leave(). This should make the plugin send a STATUS_STOPPED if all is ok

            Notice that no check is done on the MQ req content : we need nothing in it as it is directly addressed to a plugin
        """
        # check if the message is for us
        content = data.get_data()
        if content['name'] != self._name or content['host'] != self.get_sanitized_hostname():
            return

        ### Send the ack over MQ Rep
        msg = MQMessage()
        msg.set_action('plugin.stop.result')
        status = True
        reason = ""
        msg.add_data('status', status)
        msg.add_data('reason', reason)
        msg.add_data('name', self._name)
        msg.add_data('host', self.get_sanitized_hostname())
        self.reply(msg.get())

        ### Change the plugin status
        self._set_status(STATUS_STOP_REQUEST)

        ### Try to stop the plugin
        # if it fails, the manager should try to kill the plugin
        self.force_leave()
开发者ID:ka2er,项目名称:domogik,代码行数:32,代码来源:plugin.py

示例5: client_devices_edit

def client_devices_edit(client_id, did):
    with app.db.session_scope():
        device = app.db.get_device_sql(did)
        MyForm = model_form(Device, \
                        base_class=Form, \
                        db_session=app.db.get_session(),
                        exclude=['params', 'commands', 'sensors', 'address', 'xpl_commands', 'xpl_stats', 'device_type_id', 'client_id', 'client_version'])
        form = MyForm(request.form, device)

        if request.method == 'POST' and form.validate():
            # save it
            app.db.update_device(did, \
                    d_name=request.form['name'], \
                    d_description=request.form['description'], \
                    d_reference=request.form['reference'])
            # message the suer
            flash(gettext("Device saved"), 'success')
            # reload stats
            req = MQSyncReq(app.zmq_context)
            msg = MQMessage()
            msg.set_action( 'reload' )
            resp = req.request('xplgw', msg.get(), 100)
            # redirect
            return redirect("/client/{0}/dmg_devices/known".format(client_id))
        else:
            return render_template('client_device_edit.html',
                form = form,
                clientid = client_id,
                mactive="clients",
                active = 'devices'
                )
开发者ID:geneReeves,项目名称:domogik,代码行数:31,代码来源:clients.py

示例6: reload_stats

 def reload_stats(self):
     self.log.debug(u"=============== reload stats")
     req = MQSyncReq(self.zmq)
     msg = MQMessage()
     msg.set_action( 'reload' )
     resp = req.request('xplgw', msg.get(), 100)
     self.log.debug(u"Reply from xplgw: {0}".format(resp))
     self.log.debug(u"=============== reload stats END")
开发者ID:Basilic,项目名称:domogik,代码行数:8,代码来源:rest.py

示例7: scenario_blocks_actions

def scenario_blocks_actions():
    """
        Blockly.Blocks['dom_action_log'] = {
          init: function() {
            this.setColour(160);
            this.appendDummyInput()
            .appendField('Log Message')
                .appendField(new Blockly.FieldTextInput("<message to log>"), "message");
            this.setPreviousStatement(true, "null");
            this.setNextStatement(true, "null");
            this.setTooltip('');
            this.setInputsInline(false);
            this.contextMenu = false;
          }
        };
    """
    js = ""
    cli = MQSyncReq(app.zmq_context)
    msg = MQMessage()
    msg.set_action('action.list')
    res = cli.request('scenario', msg.get(), timeout=10)
    if res is not None:
        res = res.get_data()
        if 'result' in res:
            res = json.loads(res['result'])
            for act, params in res.iteritems():
                print act
                print params
                p = []
                jso = ""
                for par, parv in params['parameters'].iteritems():
                    print par
                    print parv
                    papp = "this.appendDummyInput().appendField('{0}')".format(parv['description'])
                    if parv['type'] == 'string':
                        jso = '{0}, "{1}": "\'+ block.getFieldValue(\'{1}\') + \'" '.format(jso, par)
                        papp = "{0}.appendField(new Blockly.FieldTextInput('{1}'), '{2}');".format(papp, parv['default'],par)
                    elif parv['type'] == 'integer':
                        jso = '{0}, "{1}": \'+ block.getFieldValue(\'{1}\') + \' '.format(jso, par)
                        papp = "{0}.appendField(new Blockly.FieldTextInput('{1}'), '{2}');".format(papp, parv['default'],par)
                    else:
                        papp = "{0};".format(papp)
                    p.append(papp)
                add = """Blockly.Blocks['{0}'] = {{
                        init: function() {{
                            this.setHelpUrl('');
                            this.setColour(160);
                            this.appendDummyInput().appendField("{0}");
                            {1}
                            this.setPreviousStatement(true, "null");
                            this.setNextStatement(true, "null");
                            this.setTooltip('{2}');
                            this.setInputsInline(false);
                        }}
                    }};
                    """.format(act, '\n'.join(p), params['description'], jso)
                js = '{0}\n\r{1}'.format(js, add)
    return Response(js, content_type='text/javascript; charset=utf-8')
开发者ID:geneReeves,项目名称:domogik,代码行数:58,代码来源:scenario.py

示例8: client_devices_delete

def client_devices_delete(client_id, did):
    with app.db.session_scope():
        app.db.del_device(did)
    # reload stats
    req = MQSyncReq(app.zmq_context)
    msg = MQMessage()
    msg.set_action( 'reload' )
    resp = req.request('xplgw', msg.get(), 100)
    return redirect("/client/{0}/devices/known".format(client_id))
开发者ID:mehrdad-s,项目名称:domogik,代码行数:9,代码来源:clients.py

示例9: _load_client_to_xpl_target

 def _load_client_to_xpl_target(self):
     cli = MQSyncReq(self.zmq)
     msg = MQMessage()
     msg.set_action('client.list.get')
     response = cli.request('manager', msg.get(), timeout=10)
     if response:
         self._parse_xpl_target(response.get_data())
     else:
         self.log.error(u"Updating client list was not successfull, no response from manager")
开发者ID:Dsls,项目名称:domogik,代码行数:9,代码来源:xplgw.py

示例10: _load_conversions

 def _load_conversions(self):
     print "============================ conversion"
     cli = MQSyncReq(self.zmq)
     msg = MQMessage()
     msg.set_action('client.conversion.get')
     response = cli.request('manager', msg.get(), timeout=10)
     if response:
         self._parse_conversions(response.get_data())
     else:
         self.log.error(u"Updating client conversion list was not successfull, no response from manager")
开发者ID:Dsls,项目名称:domogik,代码行数:10,代码来源:xplgw.py

示例11: orphans_delete

def orphans_delete(did):
    with app.db.session_scope():
        app.db.del_device(did)
    # reload stats
    req = MQSyncReq(app.zmq_context)
    msg = MQMessage()
    msg.set_action( 'reload' )
    resp = req.request('xplgw', msg.get(), 100)
    flash(gettext("Device deleted"), "success")
    return redirect("/orphans")
开发者ID:Basilic,项目名称:domogik,代码行数:10,代码来源:orphans.py

示例12: __init__

    def __init__(self, server_interfaces, server_port):
        """ Initiate DbHelper, Logs and config
            Then, start HTTP server and give it initialized data
            @param server_interfaces :  interfaces of HTTP server
            @param server_port :  port of HTTP server
        """

        XplPlugin.__init__(self, name = 'admin', nohub = True)
        # logging initialization
        self.log.info(u"Admin Server initialisation...")
        self.log.debug(u"locale : %s %s" % locale.getdefaultlocale())

	try:
            try:
                cfg_rest = Loader('admin')
                config_rest = cfg_rest.load()
                conf_rest = dict(config_rest[1])
                self.interfaces = conf_rest['interfaces']
                self.port = conf_rest['port']
                # if rest_use_ssl = True, set here path for ssl certificate/key
                self.use_ssl = conf_rest['use_ssl']
                self.key_file = conf_rest['ssl_certificate']
                self.cert_file = conf_rest['ssl_key']
            except KeyError:
                # default parameters
                self.interfaces = server_interfaces
                self.port = server_port
		self.use_ssl = False
		self.key_file = ""
		self.cert_file = ""
                self.clean_json = False
            self.log.info(u"Configuration : interfaces:port = %s:%s" % (self.interfaces, self.port))
	    
	    # get all datatypes
            cli = MQSyncReq(self.zmq)
            msg = MQMessage()
            msg.set_action('datatype.get')
            res = cli.request('manager', msg.get(), timeout=10)
            if res is not None:
                self.datatypes = res.get_data()['datatypes']
            else:
                self.datatypes = {}

 	    # Launch server, stats
            self.log.info(u"Admin Initialisation OK")
            self.add_stop_cb(self.stop_http)
            self.server = None
	    self.start_http()
            # calls the tornado.ioloop.instance().start()
            
            ### Component is ready
            self.ready(0)
            IOLoop.instance().start()
        except :
            self.log.error(u"%s" % self.get_exception())
开发者ID:Dsls,项目名称:domogik,代码行数:55,代码来源:admin.py

示例13: set

    def set(self, plugin, key, value):
        """
        Send a xpl message to set value for a param

        @param technology : the technology of the item
        @param key : the key to set corresponding value,
        @param value : the value to set
        """
        msg = MQMessage()
        msg._action = "config.set"
        self.cli.request("dbmgr", msg.get(), timeout=QUERY_CONFIG_WAIT)
开发者ID:ripleyXLR8,项目名称:domogik,代码行数:11,代码来源:queryconfig.py

示例14: _load_client_to_xpl_target

 def _load_client_to_xpl_target(self):
     cli = MQSyncReq(self.zmq)
     msg = MQMessage()
     msg.set_action('client.list.get')
     response = cli.request('manager', msg.get(), timeout=10)
     if response:
         data = response.get_data()
         for cli in data:
             self.client_xpl_map[cli] = data[cli]['xpl_source']
     else:
         self.log.error(u"Updating client list was not successfull, no response from manager")
开发者ID:Basilic,项目名称:domogik,代码行数:11,代码来源:xplgw.py

示例15: on_mdp_request

    def on_mdp_request(self, msg):
	# XplPlugin handles MQ Req/rep also
        XplPlugin.on_mdp_request(self, msg)

        if msg.get_action() == "reload":
            self.load()
            msg = MQMessage()
            msg.set_action( 'reload.result' )
            self.reply(msg.get())
	elif msg.get_action() == "cmd.send":
            self._send_xpl_command(msg)
开发者ID:Dsls,项目名称:domogik,代码行数:11,代码来源:xplgw.py


注:本文中的domogik.mq.message.MQMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。