web.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:restful_rfcat 作者: hufman 项目源码 文件源码
def index():
    if is_cli():
        bottle.response.content_type = 'text/plain'
        lines = []
        for klass in sorted(device_list.keys()):
            klass_devices = device_list[klass]
            for name in sorted(klass_devices.keys()):
                device = klass_devices[name]
                path = device._state_path()
                state = device.get_state()
                if state is None:
                    state = "Unknown"
                lines.append("%s - %s" % (path, state))
                for name,subdev in device.subdevices.items():
                    path = subdev._state_path()
                    state = subdev.get_state()
                    if state is None:
                        state = "Unknown"
                    lines.append("%s - %s" % (path, state))
        lines.append('')
        return '\n'.join(lines)
    else:
        page = markup.page()
        page.init(script=['app.js'], css=['style.css'])
        for klass in sorted(device_list.keys()):
            klass_devices = device_list[klass]
            page.h2(klass)
            for name in sorted(klass_devices.keys()):
                device = klass_devices[name]
                path = device._state_path()
                state = device.get_state()
                if state is None:
                    state = "Unknown"
                page.li.open()
                page.span("%s - " % (path,))
                page.span(state, id='%s-state'%(path,), class_='state')
                page.li.close()
                for name,subdev in device.subdevices.items():
                    path = subdev._state_path()
                    state = subdev.get_state()
                    if state is None:
                        state = "Unknown"
                    page.li.open()
                    page.span("%s - " % (path,))
                    page.span(state, id='%s-state'%(path,), class_='state')
                    page.li.close()
        page.br()
        page.a('Example configurations', href='examples')
        return str(page)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号