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


Python Profile.info["state"]方法代码示例

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


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

示例1: setState

# 需要导入模块: from comar.network import Profile [as 别名]
# 或者: from comar.network.Profile import info["state"] [as 别名]
def setState(name, state):
    profile = Profile(name)
    ifname = profile.info["device"].split(":")[-1].split("_")[-1]
    iface = netutils.findInterface(profile.info["device"])
    if state == "unplugged" or not iface:
        # Reset Network Stack
        unregisterNameServers(ifname)
        if state == "down":
            # Save state to profile database
            profile.info["state"] = "down"
            profile.save(no_notify=True)
            # Notify clients
            notify("Network.Link", "stateChanged", (name, "down", ""))
        else:
            # Save state to profile database
            profile.info["state"] = "unplugged"
            profile.save(no_notify=True)
            # Notify clients
            notify("Network.Link", "stateChanged", (name, "unplugged", ""))
        # Run profile script (/etc/network/netlink.d/profilename.down)
        callScript(name, "down")
        return
    # Here we go...
    device_mode = profile.info.get("device_mode", "managed")
    if device_mode == "managed":
        if state == "up":
            # Stop other profiles on same device
            stopSameDevice(name)
            # Notify clients
            notify("Network.Link", "stateChanged", (name, "connecting", ""))
            # Save state to profile database
            profile.info["state"] = "connecting"
            profile.save(no_notify=True)
            # Wifi settings
            wifi = Wireless(iface)
            wifi.setSSID(profile.info["remote"])
            # Set encryption
            try:
                wifi.setEncryption(getAuthMethod(name), getAuthParameters(name))
            except Exception, e:
                # Stop ifplug deamon
                plugService(ifname, "down")
                # Save state to profile database
                profile.info["state"] = "inaccessible %s" % unicode(e)
                profile.save(no_notify=True)
                # Notify clients
                notify("Network.Link", "stateChanged", (name, "inaccessible", unicode(e)))
                fail(unicode(e))
            if profile.info.get("net_mode", "auto") == "auto":
                # Start DHCP client
                ret = iface.startAuto()
                if ret == 0 and iface.isUp():
                    if "net_address" in profile.info or "net_gateway" in profile.info:
                        net_address = profile.info.get("net_address", None)
                        net_mask = profile.info.get("net_mask", "255.255.255.0")
                        net_gateway = profile.info.get("net_gateway", None)
                        if net_address:
                            iface.setAddress(net_address, net_mask)
                            if not net_gateway:
                                gateways = iface.autoGateways()
                                if len(gateways):
                                    net_gateway = gateways[0]
                        if net_gateway:
                            route = netutils.Route()
                            route.setDefault(net_gateway)
                    elif iface.getAddress():
                        net_address = iface.getAddress()[0]
                    else:
                        # Bring device down
                        iface.down()
                        # Save state to profile database
                        profile.info["state"] = "inaccessible %s" % _(MSG_DHCP_FAILED)
                        profile.save(no_notify=True)
                        # Notify clients
                        notify("Network.Link", "stateChanged", (name, "inaccessible", _(MSG_DHCP_FAILED)))
                        return
                    # Set nameservers
                    registerNameServers(profile, iface)
                    # Save state to profile database
                    profile.info["state"] = "up " + net_address
                    profile.save(no_notify=True)
                    # Notify clients
                    notify("Network.Link", "stateChanged", (name, "up", net_address))
                    # Run profile script (/etc/network/netlink.d/profilename.up)
                    callScript(name, "up")
                    # Start ifplug daemon
                    plugService(ifname, "up", wireless=True)
                else:
                    # Bring device down
                    iface.down()
                    # Save state to profile database
                    profile.info["state"] = "inaccessible %s" % _(MSG_DHCP_FAILED)
                    profile.save(no_notify=True)
                    # Notify clients
                    notify("Network.Link", "stateChanged", (name, "inaccessible", _(MSG_DHCP_FAILED)))
            else:
                try:
                    net_address = profile.info["net_address"]
                    net_mask = profile.info["net_mask"]
                except KeyError:
#.........这里部分代码省略.........
开发者ID:blue-devil,项目名称:kuller,代码行数:103,代码来源:link.py


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