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


Python Util.gap_for_timestring方法代码示例

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


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

示例1: callback

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import gap_for_timestring [as 别名]
    def callback(self, cmd, action, target, msg):
        if msg is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None

        if msg.endswith(u'点') or \
           msg.endswith(u'分'):
            t = Util.gap_for_timestring(msg)
        elif msg.endswith(u"秒"):
            t = int(Util.cn2dig(msg[:-1]))
        elif msg.endswith(u"分钟"):
            t = int(Util.cn2dig(msg[:-2]))*60
        elif msg.endswith(u"小时"):
            t = int(Util.cn2dig(msg[:-2]))*60*60
        else:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False
        if t is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None
        DEBUG("thread wait for %d sec" % (t, ))
        self._home.publish_msg(cmd, action + target + msg)

        threading.current_thread().waitUtil(t)
        if threading.current_thread().stopped():
            return False
        self._home.setResume(True)
        count = 7
        Sound.play( Res.get_res_path("sound/com_bell") , True, count)
        self._home.setResume(False)
        return True
开发者ID:euwen,项目名称:LEHome,代码行数:33,代码来源:tools.py

示例2: callback

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import gap_for_timestring [as 别名]
    def callback(self, cmd, delay_time, action, target, msg):
        if delay_time is None or len(delay_time) == 0:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None

        t = None
        if delay_time.endswith(u"秒") or delay_time.endswith(u"秒钟"):
            t = int(Util.cn2dig(delay_time[:-1]))
        elif delay_time.endswith(u"分钟"):
            t = int(Util.cn2dig(delay_time[:-2])) * 60
        elif delay_time.endswith(u"小时"):
            t = int(Util.cn2dig(delay_time[:-2])) * 60 * 60
        else:
            t = Util.gap_for_timestring(delay_time)
        if t is None:
            WARN("error delay_time format")
            self._home.publish_msg(cmd, u"时间格式错误:" + delay_time)
            return False, None
        info = delay_time + u"执行: %s%s%s" % (Util.xunicode(action), Util.xunicode(target), Util.xunicode(msg))
        # self._home.publish_msg(cmd, info)  # noise
        DEBUG("delay wait for %d sec" % (t,))

        threading.current_thread().waitUtil(t)
        if threading.current_thread().stopped():
            return False
        return True
开发者ID:houzhenggang,项目名称:LEHome,代码行数:28,代码来源:delay.py

示例3: callback

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import gap_for_timestring [as 别名]
    def callback(self, cmd, action, target, msg, pre_value, stack):
        if pre_value != "while" or msg is None:
            WARN("every callback must in a 'while'")
            return False, pre_value

        var_name = "first_every_invoke" + str(stack.cur_layer())
        first_every_invoke = stack.get_value(var_name)
        if first_every_invoke is None:
            first_every_invoke = True
            stack.set_var(var_name, False)
            self._home.publish_msg(cmd, u"循环建立:" + cmd)

        # INFO("every_callback invoke:%s" % (msg, ))
        if msg.endswith(u"天"):
            if msg.startswith(u"天"):
                t = 24*60*60
            else:
                t = int(Util.cn2dig(msg[:-1]))*24*60*60
        elif msg.endswith(u"小时"):
            if msg.startswith(u"小时"):
                t = 60*60
            else:
                t = int(Util.cn2dig(msg[:-2]))*60*60
        elif msg.endswith(u"分钟"):
            if msg.startswith(u"分钟"):
                t = 60
            else:
                t = int(Util.cn2dig(msg[:-2]))*60
        elif msg.endswith(u"秒") or msg.endswith(u"秒钟"):
            if msg.startswith(u"秒"):
                t = 1
            else:
                t = int(Util.cn2dig(msg[:-1]))
        elif (msg.startswith(u'天') or \
                msg.startswith(u'工作日')) and \
                (msg.endswith(u'点') or \
                   msg.endswith(u'点钟') or \
                   msg.endswith(u'分')):
            # import pdb; pdb.set_trace()
            check_weekday = False
            if msg.startswith(u'工作日'):
                check_weekday = True
                msg = msg[3:]
            else:
                msg = msg[1:]

            period = msg.split(u'到')
            if len(period) == 2:
                t = Util.wait_for_period(period)
                if t > 0:
                    DEBUG("period wait for %d sec" % (t, ))
                    threading.current_thread().waitUtil(t)
                if check_weekday is True:
                    workday = Util.is_workday_today()
                    while workday != 0:
                        t = 24*60*60
                        INFO("weekday task, wait for %d sec" % (t, ))
                        threading.current_thread().waitUtil(t)
                        if threading.current_thread().stopped():
                            return False, False
                        workday = Util.is_workday_today()
                if threading.current_thread().stopped():
                    return False, False
                return True, True
            else:
                t = Util.gap_for_timestring(msg)
            if t > 0:
                INFO("gap wait for %d sec" % (t, ))
                threading.current_thread().waitUtil(t)
                if check_weekday is True:
                    workday = Util.is_workday_today()
                    while workday != 0:
                        t = 24*60*60
                        INFO("weekday task, wait for %d sec" % (t, ))
                        threading.current_thread().waitUtil(t)
                        if threading.current_thread().stopped():
                            return False, False
                        workday = Util.is_workday_today()
                if threading.current_thread().stopped():
                    return False, False
            return True, True
        else:
            self._home.publish_msg(cmd, u"时间格式有误")
            return False, False

        if first_every_invoke is False:
            threading.current_thread().waitUtil(t)
            if threading.current_thread().stopped():
                return False, False
            return True, True
        else:
            INFO("new loop for %d sec, invoke now" % (t, ))
            if threading.current_thread().stopped():
                return False, False
            return True, True
开发者ID:kkme,项目名称:LEHome,代码行数:97,代码来源:action.py


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