mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 21:08:06 +01:00
Testing/Experimental:
- Replaced uses of /proc/net/wireless with /sys/class/net/<iface>.
This commit is contained in:
25
wicd.py
25
wicd.py
@@ -245,20 +245,19 @@ class TrayIcon:
|
||||
""" Determines what network activity state we are in. """
|
||||
transmitting = False
|
||||
receiving = False
|
||||
rcvbytes = None
|
||||
sndbytes = None
|
||||
|
||||
dev_file = open('/proc/net/dev','r')
|
||||
device_data = dev_file.read().split('\n')
|
||||
dev_file.close()
|
||||
|
||||
# Get the data for the wireless interface.
|
||||
for line in device_data:
|
||||
if daemon.GetWirelessInterface() in line:
|
||||
line = line.replace(':', ' ').split()
|
||||
rcvbytes = int(line[1])
|
||||
sndbytes = int(line[9])
|
||||
|
||||
dev_dir = '/sys/class/net/'
|
||||
wiface = daemon.GetWirelessInterface()
|
||||
for fldr in os.listdir(dev_dir):
|
||||
if fldr == wiface:
|
||||
dev_dir = dev_dir + fldr + "/statistics/"
|
||||
break
|
||||
try:
|
||||
rcvbytes = int(open(dev_dir + "rx_bytes", "r").read().strip())
|
||||
sndbytes = int(open(dev_dir + "tx_bytes", "r").read().strip())
|
||||
except IOError:
|
||||
sndbytes = None
|
||||
rcvbytes = None
|
||||
|
||||
if not rcvbytes or not sndbytes:
|
||||
return 'idle-'
|
||||
|
||||
22
wnettools.py
22
wnettools.py
@@ -133,26 +133,14 @@ def GetWirelessInterfaces():
|
||||
return iface
|
||||
|
||||
def _fast_get_wifi_interfaces():
|
||||
""" Tries to get a wireless interface by parsing /proc/net/wireless. """
|
||||
device = re.compile('[a-z]{3,4}[0-9]')
|
||||
""" Tries to get a wireless interface using /sys/class/net. """
|
||||
dev_dir = '/sys/class/net/'
|
||||
ifnames = []
|
||||
|
||||
try:
|
||||
f = open('/proc/net/wireless', 'r')
|
||||
except IOError:
|
||||
return None
|
||||
data = f.readlines()
|
||||
f.close()
|
||||
for line in data:
|
||||
try:
|
||||
ifnames.append(device.search(line).group())
|
||||
except AttributeError:
|
||||
pass
|
||||
ifnames = [iface for iface in os.listdir(dev_dir) if 'wireless' \
|
||||
in os.listdir(dev_dir + iface)]
|
||||
|
||||
if ifnames:
|
||||
return ifnames[0]
|
||||
else:
|
||||
return None
|
||||
return bool(ifnames) and ifnames[0] or None
|
||||
|
||||
def get_iw_ioctl_result(iface, call):
|
||||
""" Makes the given ioctl call and returns the results.
|
||||
|
||||
Reference in New Issue
Block a user