mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-10 14:09:22 +01:00
autotests: Replace strings with constants
This commit is contained in:
parent
10be3c27b9
commit
c2751ad6a2
@ -5,10 +5,20 @@ import dbus
|
|||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
IWD_SERVICE = 'net.connman.iwd'
|
||||||
|
|
||||||
|
IWD_AGENT_MANAGER_INTERFACE = 'net.connman.iwd.AgentManager'
|
||||||
|
IWD_DEVICE_INTERFACE = 'net.connman.iwd.Device'
|
||||||
|
IWD_NETWORK_INTERFACE = 'net.connman.iwd.Network'
|
||||||
|
IWD_AGENT_INTERFACE = 'net.connman.iwd.Agent'
|
||||||
|
IWD_WSC_INTERFACE = 'net.connman.iwd.WiFiSimpleConfiguration'
|
||||||
|
|
||||||
|
IWD_TOP_LEVEL_PATH = "/"
|
||||||
|
|
||||||
# get all the available networks
|
# get all the available networks
|
||||||
def getObjectList(bus):
|
def getObjectList(bus):
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"),
|
manager = dbus.Interface(bus.get_object(IWD_SERVICE, "/"),
|
||||||
"org.freedesktop.DBus.ObjectManager")
|
"org.freedesktop.DBus.ObjectManager")
|
||||||
return manager.GetManagedObjects()
|
return manager.GetManagedObjects()
|
||||||
|
|
||||||
@ -17,11 +27,11 @@ def getNetworkList(objects, bus):
|
|||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
networkList = []
|
networkList = []
|
||||||
for path in objects:
|
for path in objects:
|
||||||
if 'net.connman.iwd.Device' not in objects[path]:
|
if IWD_DEVICE_INTERFACE not in objects[path]:
|
||||||
continue
|
continue
|
||||||
for path2 in objects:
|
for path2 in objects:
|
||||||
if not path2.startswith(path) or \
|
if not path2.startswith(path) or \
|
||||||
'net.connman.iwd.Network' not in objects[path2]:
|
IWD_NETWORK_INTERFACE not in objects[path2]:
|
||||||
continue
|
continue
|
||||||
networkList.append(path2)
|
networkList.append(path2)
|
||||||
return networkList
|
return networkList
|
||||||
@ -29,8 +39,8 @@ def getNetworkList(objects, bus):
|
|||||||
def connect(networkToConnect, self, mainloop, bus):
|
def connect(networkToConnect, self, mainloop, bus):
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
logger.debug(" %s", networkToConnect)
|
logger.debug(" %s", networkToConnect)
|
||||||
network = dbus.Interface(bus.get_object("net.connman.iwd",networkToConnect),
|
network = dbus.Interface(bus.get_object(IWD_SERVICE, networkToConnect),
|
||||||
"net.connman.iwd.Network")
|
IWD_NETWORK_INTERFACE)
|
||||||
try:
|
try:
|
||||||
network.Connect()
|
network.Connect()
|
||||||
except:
|
except:
|
||||||
@ -45,8 +55,8 @@ def connect(networkToConnect, self, mainloop, bus):
|
|||||||
# try to disconnect from the device.
|
# try to disconnect from the device.
|
||||||
def disconnect(deviceToDisconnect, mainloop, bus):
|
def disconnect(deviceToDisconnect, mainloop, bus):
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
device = dbus.Interface(bus.get_object("net.connman.iwd",deviceToDisconnect),
|
device = dbus.Interface(bus.get_object(IWD_SERVICE, deviceToDisconnect),
|
||||||
"net.connman.iwd.Device")
|
IWD_DEVICE_INTERFACE)
|
||||||
try:
|
try:
|
||||||
device.Disconnect()
|
device.Disconnect()
|
||||||
except:
|
except:
|
||||||
@ -65,7 +75,7 @@ def getNetworkToConnectTo(objects):
|
|||||||
for path in objects:
|
for path in objects:
|
||||||
for path2 in objects:
|
for path2 in objects:
|
||||||
if not path2.startswith(path) or \
|
if not path2.startswith(path) or \
|
||||||
'net.connman.iwd.Network' not in objects[path2]:
|
IWD_NETWORK_INTERFACE not in objects[path2]:
|
||||||
continue
|
continue
|
||||||
return path2
|
return path2
|
||||||
return ""
|
return ""
|
||||||
@ -75,13 +85,13 @@ def getNetworkToConnectTo(objects):
|
|||||||
def getCurrentlyConnectedDevice():
|
def getCurrentlyConnectedDevice():
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"),
|
manager = dbus.Interface(bus.get_object(IWD_SERVICE, "/"),
|
||||||
"net.connman.iwd.Manager")
|
"net.connman.iwd.Manager")
|
||||||
objects = getObjectList(bus)
|
objects = getObjectList(bus)
|
||||||
for path in objects:
|
for path in objects:
|
||||||
if 'net.connman.iwd.Device' not in objects[path]:
|
if IWD_DEVICE_INTERFACE not in objects[path]:
|
||||||
continue
|
continue
|
||||||
device = objects[path]['net.connman.iwd.Device']
|
device = objects[path][IWD_DEVICE_INTERFACE]
|
||||||
for key in device.keys():
|
for key in device.keys():
|
||||||
if key in ["ConnectedNetwork"]:
|
if key in ["ConnectedNetwork"]:
|
||||||
return path
|
return path
|
||||||
@ -96,9 +106,9 @@ def getCurrentlyConnectedNetworkName():
|
|||||||
for path in deviceList:
|
for path in deviceList:
|
||||||
for path2 in deviceList:
|
for path2 in deviceList:
|
||||||
if not path2.startswith(path) or \
|
if not path2.startswith(path) or \
|
||||||
'net.connman.iwd.Network' not in deviceList[path2]:
|
IWD_NETWORK_INTERFACE not in deviceList[path2]:
|
||||||
continue
|
continue
|
||||||
network = deviceList[path2]['net.connman.iwd.Network']
|
network = deviceList[path2][IWD_NETWORK_INTERFACE]
|
||||||
for key in network.keys():
|
for key in network.keys():
|
||||||
name = ""
|
name = ""
|
||||||
if key in ["Connected"]:
|
if key in ["Connected"]:
|
||||||
@ -118,13 +128,13 @@ def getCurrentlyConnectedNetworkName():
|
|||||||
def getNetworkName(deviceList):
|
def getNetworkName(deviceList):
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
for path in deviceList:
|
for path in deviceList:
|
||||||
if 'net.connman.iwd.Device' not in deviceList[path]:
|
if IWD_DEVICE_INTERFACE not in deviceList[path]:
|
||||||
continue
|
continue
|
||||||
for path2 in deviceList:
|
for path2 in deviceList:
|
||||||
if not path2.startswith(path) or \
|
if not path2.startswith(path) or \
|
||||||
'net.connman.iwd.Network' not in deviceList[path2]:
|
IWD_NETWORK_INTERFACE not in deviceList[path2]:
|
||||||
continue
|
continue
|
||||||
network = deviceList[path2]['net.connman.iwd.Network']
|
network = deviceList[path2][IWD_NETWORK_INTERFACE]
|
||||||
for key in network.keys():
|
for key in network.keys():
|
||||||
if key in ["Name"]:
|
if key in ["Name"]:
|
||||||
return network[key]
|
return network[key]
|
||||||
|
Loading…
Reference in New Issue
Block a user