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


Python DbHelper.open_session方法代码示例

本文整理汇总了Python中domogik.common.database.DbHelper.open_session方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.open_session方法的具体用法?Python DbHelper.open_session怎么用?Python DbHelper.open_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在domogik.common.database.DbHelper的用法示例。


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

示例1: XplManager

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import open_session [as 别名]

#.........这里部分代码省略.........
                            if not failed:
                                # send out the msg
                                self.log.debug(u"sending xplmessage: {0}".format(msg))
                                self.myxpl.send(msg)
                                ### Wait for answer
                                stat_received = 0
                                if xplstat != None:
                                    # get xpl message from queue
                                    self.log.debug(u"Command : wait for answer...")
                                    sub = MQSyncSub( self.zmq, 'xplgw-command', ['device-stats'] )
                                    stat = sub.wait_for_event()
                                    if stat is not None:
                                        reply = json.loads(stat['content'])
                                        reply_msg = MQMessage()
                                        reply_msg.set_action('cmd.send.result')
                                        reply_msg.add_data('stat', reply)
                                        reply_msg.add_data('status', True)
                                        reply_msg.add_data('reason', None)
                                        self.log.debug(u"mq reply".format(reply_msg.get()))
                                        self.reply(reply_msg.get())
        if failed:
            self.log.error(failed)
            reply_msg = MQMessage()
            reply_msg.set_action('cmd.send.result')
            reply_msg.add_data('status', False)
            reply_msg.add_data('reason', failed)
            self.log.debug(u"mq reply".format(reply_msg.get()))
            self.reply(reply_msg.get())

    def load(self):
        """ (re)load all xml files to (re)create _Stats objects
        """
        self.log.info(u"Rest Stat Manager loading.... ")
        self._db.open_session()
        try:
            # not the first load : clean
            if self.stats != None:
                self.log.info(u"reloading")
                for stat in self.stats:
                    self.myxpl.del_listener(stat.get_listener())

            ### Load stats
            # key1, key2 = device_type_id, schema
            self.stats = []
            created_stats = []
            for stat in self._db.get_all_xpl_stat():
                # xpl-trig
                self.stats.append(self._Stat(self.myxpl, stat, "xpl-trig", \
                                self.log, self.pub, self.client_conversion_map))
                # xpl-stat
                self.stats.append(self._Stat(self.myxpl, stat, "xpl-stat", \
                                self.log, self.pub, self.client_conversion_map))
        except:
            self.log.error(u"%s" % traceback.format_exc())
        self._db.close_session()
        self.log.info(u"Loading finished")

    class _Stat:
        """ This class define a statistic parser and logger instance
        Each instance create a Listener and the associated callbacks
        """

        def __init__(self, xpl, stat, xpl_type, log, pub, conversions):
            """ Initialize a stat instance
            @param xpl : A xpl manager instance
            @param stat : A XplStat reference
开发者ID:anuraagkapoor,项目名称:domogik,代码行数:70,代码来源:xplgw.py

示例2: list

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import open_session [as 别名]
    for d in devs:
        d = list(d)
        if d[0] not in ret:
            ret[d[0]] = {}
            ret[d[0]]['name'] = d[1]
            ret[d[0]]['keys'] = []
            ret[d[0]]['keys'].append( d[2] )
        else:
            ret[d[0]]['keys'].append( d[2] )
    return ret


if __name__ == "__main__":
    # 0- connect to the DB
    db = DbHelper()
    db.open_session()

    # 1- list current devices  (odl ones)
    do = True
    old_devs = corellateOld(db.upgrade_list_old())
    while do:
        print old_devs
        # show dev menu
        i = 1
        for dev in old_devs:
            print("{0}. {1}".format(i, old_devs[dev]['name']))
            i = i + 1
        print("0. Exit")
        sel = i + 1
        while sel > i:
            try:
开发者ID:altenide,项目名称:domogik,代码行数:33,代码来源:statsUpgrade.py


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