1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 12:28:08 +01:00

Merge r311 of mainline 1.6

This commit is contained in:
Andrew Psaltis
2009-02-28 08:48:21 -05:00
9 changed files with 94 additions and 92 deletions

View File

@@ -23,3 +23,4 @@ scripts/wicd-client
scripts/wicd-curses scripts/wicd-curses
translations/* translations/*
wicd/wpath.py wicd/wpath.py
*tags

View File

@@ -5,6 +5,7 @@
# This is defined in /usr/lib/python2.5/site-packages/wicd/wpath.py # This is defined in /usr/lib/python2.5/site-packages/wicd/wpath.py
PIDFILE="%PIDFILE%" PIDFILE="%PIDFILE%"
DAEMON="%SBIN%wicd"
# Define start and stop functions # Define start and stop functions
@@ -15,7 +16,7 @@ wicd_start() {
echo "$PIDFILE and try again..." echo "$PIDFILE and try again..."
exit 1 exit 1
else else
echo "Starting wicd daemon..." echo "Starting wicd daemon: $DAEMON"
wicd 2>/dev/null 1>&2 wicd 2>/dev/null 1>&2
fi fi
} }

View File

@@ -28,7 +28,7 @@ import subprocess
VERSION_NUM = '1.6.0a1' VERSION_NUM = '1.6.0a1'
# REVISION_NUM is automatically updated # REVISION_NUM is automatically updated
REVISION_NUM = 'unknown' REVISION_NUM = 'unknown'
CURSES_REVNO = 'r278' CURSES_REVNO = 'r279'
try: try:
if not os.path.exists('vcsinfo.py'): if not os.path.exists('vcsinfo.py'):

View File

@@ -33,8 +33,7 @@ from wicd import misc
from wicd import wnettools from wicd import wnettools
from wicd import wpath from wicd import wpath
from wicd.wnettools import * from wicd.wnettools import *
from wicd.wnettools import strength_pattern, altstrength_pattern, wep_pattern, \ from wicd.wnettools import wep_pattern, signaldbm_pattern
signaldbm_pattern
import iwscan import iwscan
import wpactrl import wpactrl
@@ -311,17 +310,10 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
# Link Quality # Link Quality
ap['qual_found'] = True ap['qual_found'] = True
try: ap['quality'] = self._get_link_quality(cell['stats'])
[(strength, max_strength)] = strength_pattern.findall(cell["stats"]) if ap['quality'] is None:
if max_strength: ap['qual_found'] = False
ap["quality"] = 100 * int(strength) // int(max_strength) ap['quality'] = -1
else:
ap["quality"] = int(strength)
except ValueError:
ap['quality'] = misc.RunRegex(altstrength_pattern,cell["stats"])
if not ap['quality']:
ap['qual_found'] = False
ap['quality'] = -1
# Signal Strength (only used if user doesn't want link # Signal Strength (only used if user doesn't want link
# quality displayed or it isn't found) # quality displayed or it isn't found)
@@ -338,7 +330,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
socket_loc = os.path.join(ctrl_iface, self.iface) socket_loc = os.path.join(ctrl_iface, self.iface)
if os.path.exists(socket_loc): if os.path.exists(socket_loc):
try: try:
return wpactrl.WPACtrl(socket) return wpactrl.WPACtrl(socket_loc)
except wpactrl.error, e: except wpactrl.error, e:
print "Couldn't open ctrl_interface: %s" % e print "Couldn't open ctrl_interface: %s" % e
return None return None
@@ -498,10 +490,12 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS) buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS)
strength = ord(buff[2]) strength = ord(buff[2])
max_strength = self._get_max_strength() max_strength = self._get_max_strength()
if strength and max_strength: if strength not in ['', None] and max_strength:
return 100 * int(strength) // int(max_strength) return 100 * int(strength) // int(max_strength)
elif strength not in ['', None]:
return strength return int(strength)
else:
return None
def _get_max_strength(self): def _get_max_strength(self):
""" Gets the maximum possible strength from the wireless driver. """ """ Gets the maximum possible strength from the wireless driver. """

View File

@@ -26,6 +26,7 @@ import gobject
from threading import Thread from threading import Thread
from subprocess import Popen, STDOUT, PIPE, call from subprocess import Popen, STDOUT, PIPE, call
from commands import getoutput from commands import getoutput
from itertools import repeat, chain, izip
# wicd imports # wicd imports
import wpath import wpath
@@ -243,9 +244,11 @@ def ParseEncryption(network):
# Write the data to the files then chmod them so they can't be read # Write the data to the files then chmod them so they can't be read
# by normal users. # by normal users.
f = open(wpath.networks + network["bssid"].replace(":", "").lower(), "w") file_loc = os.path.join(wpath.networks,
os.chmod(wpath.networks + network["bssid"].replace(":", "").lower(), 0600) network['bssid'].replace(":", "").lower())
os.chown(wpath.networks + network["bssid"].replace(":", "").lower(), 0, 0) f = open(file_loc, "w")
os.chmod(file_loc, 0600)
os.chown(file_loc, 0, 0)
# We could do this above, but we'd like to read protect # We could do this above, but we'd like to read protect
# them before we write, so that it can't be read. # them before we write, so that it can't be read.
f.write(config_file) f.write(config_file)
@@ -690,4 +693,31 @@ def timeout_add(time, func, milli=False):
else: else:
if not milli: time = time * 1000 if not milli: time = time * 1000
return gobject.timeout_add(time, func) return gobject.timeout_add(time, func)
def izip_longest(*args, **kwds):
""" Implement the itertools.izip_longest method.
We implement the method here because its new in Python 2.6.
"""
# izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
fillvalue = kwds.get('fillvalue')
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
yield counter() # yields the fillvalue, or raises IndexError
fillers = repeat(fillvalue)
iters = [chain(it, sentinel(), fillers) for it in args]
try:
for tup in izip(*iters):
yield tup
except IndexError:
pass
def grouper(n, iterable, fillvalue=None):
""" Iterate over several elements at once
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
"""
args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)

View File

@@ -396,7 +396,7 @@ class ConnectThread(threading.Thread):
print 'Setting the broadcast address...' + self.network['broadcast'] print 'Setting the broadcast address...' + self.network['broadcast']
iface.SetAddress(broadcast=self.network['broadcast']) iface.SetAddress(broadcast=self.network['broadcast'])
@abortable @abortable
def set_ip_address(self, iface): def set_ip_address(self, iface):
""" Set the IP address for the given interface. """ Set the IP address for the given interface.
@@ -420,7 +420,7 @@ class ConnectThread(threading.Thread):
self.abort_connection(dhcp_status) self.abort_connection(dhcp_status)
return return
@abortable @abortable
def set_dns_addresses(self): def set_dns_addresses(self):
""" Set the DNS address(es). """ Set the DNS address(es).
@@ -443,7 +443,7 @@ class ConnectThread(threading.Thread):
self.network.get('dns_domain'), self.network.get('dns_domain'),
self.network.get('search_domain')) self.network.get('search_domain'))
@abortable @abortable
def release_dhcp_clients(self, iface): def release_dhcp_clients(self, iface):
""" Release all running dhcp clients. """ """ Release all running dhcp clients. """
print "Releasing DHCP leases..." print "Releasing DHCP leases..."
@@ -474,7 +474,7 @@ class ConnectThread(threading.Thread):
finally: finally:
self.lock.release() self.lock.release()
@abortable @abortable
def put_iface_up(self, iface): def put_iface_up(self, iface):
""" Bring up given interface. """ """ Bring up given interface. """
print 'Putting interface up...' print 'Putting interface up...'
@@ -819,7 +819,7 @@ class WirelessConnectThread(ConnectThread):
print 'Stopping wpa_supplicant' print 'Stopping wpa_supplicant'
wiface.StopWPA() wiface.StopWPA()
@abortable @abortable
def generate_psk_and_authenticate(self, wiface): def generate_psk_and_authenticate(self, wiface):
""" Generates a PSK and authenticates if necessary. """ Generates a PSK and authenticates if necessary.

View File

@@ -109,12 +109,12 @@ class TrayIcon(object):
Base Class for implementing a tray icon to display network status. Base Class for implementing a tray icon to display network status.
""" """
def __init__(self, use_tray, animate): def __init__(self, animate):
if USE_EGG: if USE_EGG:
self.tr = self.EggTrayIconGUI(use_tray) self.tr = self.EggTrayIconGUI()
else: else:
self.tr = self.StatusTrayIconGUI(use_tray) self.tr = self.StatusTrayIconGUI()
self.icon_info = self.TrayConnectionInfo(self.tr, use_tray, animate) self.icon_info = self.TrayConnectionInfo(self.tr, animate)
def is_embedded(self): def is_embedded(self):
if USE_EGG: if USE_EGG:
@@ -125,7 +125,7 @@ class TrayIcon(object):
class TrayConnectionInfo(object): class TrayConnectionInfo(object):
""" Class for updating the tray icon status. """ """ Class for updating the tray icon status. """
def __init__(self, tr, use_tray=True, animate=True): def __init__(self, tr, animate=True):
""" Initialize variables needed for the icon status methods. """ """ Initialize variables needed for the icon status methods. """
self.last_strength = -2 self.last_strength = -2
self.still_wired = False self.still_wired = False
@@ -133,7 +133,6 @@ class TrayIcon(object):
self.tried_reconnect = False self.tried_reconnect = False
self.connection_lost_counter = 0 self.connection_lost_counter = 0
self.tr = tr self.tr = tr
self.use_tray = use_tray
self.last_sndbytes = -1 self.last_sndbytes = -1
self.last_rcvbytes = -1 self.last_rcvbytes = -1
self.max_snd_gain = 10000 self.max_snd_gain = 10000
@@ -203,7 +202,7 @@ class TrayIcon(object):
@catchdbus @catchdbus
def update_tray_icon(self, state=None, info=None): def update_tray_icon(self, state=None, info=None):
""" Updates the tray icon and current connection status. """ """ Updates the tray icon and current connection status. """
if not self.use_tray or not DBUS_AVAIL: return False if not DBUS_AVAIL: return False
if not state or not info: if not state or not info:
[state, info] = daemon.GetConnectionStatus() [state, info] = daemon.GetConnectionStatus()
@@ -330,7 +329,7 @@ class TrayIcon(object):
tray icons. tray icons.
""" """
def __init__(self, use_tray): def __init__(self):
menu = """ menu = """
<ui> <ui>
<menubar name="Menubar"> <menubar name="Menubar">
@@ -361,7 +360,6 @@ class TrayIcon(object):
props.parent) props.parent)
self.gui_win = None self.gui_win = None
self.current_icon_path = None self.current_icon_path = None
self.use_tray = use_tray
self._is_scanning = False self._is_scanning = False
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/") net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
net_menuitem.connect("activate", self.on_net_menu_activate) net_menuitem.connect("activate", self.on_net_menu_activate)
@@ -571,14 +569,9 @@ class TrayIcon(object):
for machines running versions of GTK < 2.10. for machines running versions of GTK < 2.10.
""" """
def __init__(self, use_tray=True): def __init__(self):
"""Initializes the tray icon""" """Initializes the tray icon"""
TrayIcon.TrayIconGUI.__init__(self, use_tray) TrayIcon.TrayIconGUI.__init__(self)
self.use_tray = use_tray
if not use_tray:
self.toggle_wicd_gui()
return
self.tooltip = gtk.Tooltips() self.tooltip = gtk.Tooltips()
self.eb = gtk.EventBox() self.eb = gtk.EventBox()
self.tray = egg.trayicon.TrayIcon("WicdTrayIcon") self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
@@ -601,7 +594,6 @@ class TrayIcon(object):
def set_from_file(self, val=None): def set_from_file(self, val=None):
""" Calls set_from_file on the gtk.Image for the tray icon. """ """ Calls set_from_file on the gtk.Image for the tray icon. """
if not self.use_tray: return
self.pic.set_from_file(val) self.pic.set_from_file(val)
def set_tooltip(self, val): def set_tooltip(self, val):
@@ -611,7 +603,6 @@ class TrayIcon(object):
tray icon. tray icon.
""" """
if not self.use_tray: return
self.tooltip.set_tip(self.eb, val) self.tooltip.set_tip(self.eb, val)
@@ -622,13 +613,8 @@ class TrayIcon(object):
Uses gtk.StatusIcon to implement a tray icon. Uses gtk.StatusIcon to implement a tray icon.
""" """
def __init__(self, use_tray=True): def __init__(self):
TrayIcon.TrayIconGUI.__init__(self, use_tray) TrayIcon.TrayIconGUI.__init__(self)
self.use_tray = use_tray
if not use_tray:
self.toggle_wicd_gui()
return
gtk.StatusIcon.__init__(self) gtk.StatusIcon.__init__(self)
self.current_icon_path = '' self.current_icon_path = ''
@@ -645,7 +631,6 @@ class TrayIcon(object):
def set_from_file(self, path=None): def set_from_file(self, path=None):
""" Sets a new tray icon picture. """ """ Sets a new tray icon picture. """
if not self.use_tray: return
if path != self.current_icon_path: if path != self.current_icon_path:
self.current_icon_path = path self.current_icon_path = path
gtk.StatusIcon.set_from_file(self, path) gtk.StatusIcon.set_from_file(self, path)
@@ -716,9 +701,6 @@ def main(argv):
argv -- The arguments passed to the script. argv -- The arguments passed to the script.
""" """
use_tray = True
animate = True
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'nha', ['help', 'no-tray', opts, args = getopt.getopt(sys.argv[1:], 'nha', ['help', 'no-tray',
'no-animate']) 'no-animate'])
@@ -727,6 +709,8 @@ def main(argv):
usage() usage()
sys.exit(2) sys.exit(2)
use_tray = True
animate = True
for opt, a in opts: for opt, a in opts:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
usage() usage()
@@ -750,7 +734,7 @@ def main(argv):
sys.exit(0) sys.exit(0)
# Set up the tray icon GUI and backend # Set up the tray icon GUI and backend
tray_icon = TrayIcon(use_tray, animate) tray_icon = TrayIcon(animate)
# Check to see if wired profile chooser was called before icon # Check to see if wired profile chooser was called before icon
# was launched (typically happens on startup or daemon restart). # was launched (typically happens on startup or daemon restart).
@@ -767,7 +751,8 @@ def main(argv):
'org.wicd.daemon.wireless') 'org.wicd.daemon.wireless')
bus.add_signal_receiver(tray_icon.tr.tray_scan_started, bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
'SendStartScanSignal', 'org.wicd.daemon.wireless') 'SendStartScanSignal', 'org.wicd.daemon.wireless')
bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(), bus.add_signal_receiver(lambda: (handle_no_dbus() or
tray_icon.icon_info.set_not_connected_state()),
"DaemonClosing", 'org.wicd.daemon') "DaemonClosing", 'org.wicd.daemon')
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting", bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
"org.wicd.daemon") "org.wicd.daemon")

View File

@@ -1053,7 +1053,7 @@ class WirelessDaemon(dbus.service.Object):
""" Returns the current signal strength. """ """ Returns the current signal strength. """
try: try:
strength = int(self.wifi.GetSignalStrength(iwconfig)) strength = int(self.wifi.GetSignalStrength(iwconfig))
except: except TypeError:
strength = 0 strength = 0
return strength return strength

View File

@@ -47,7 +47,7 @@ essid_pattern = re.compile('.*ESSID:"?(.*?)"?\s*\n', __re_mode)
ap_mac_pattern = re.compile('.*Address: (.*?)\n', __re_mode) ap_mac_pattern = re.compile('.*Address: (.*?)\n', __re_mode)
channel_pattern = re.compile('.*Channel:? ?(\d\d?)', __re_mode) channel_pattern = re.compile('.*Channel:? ?(\d\d?)', __re_mode)
strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode) strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode)
altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)', __re_mode) altstrength_pattern = re.compile('.*Signal level:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode)
signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)', __re_mode) signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)', __re_mode)
mode_pattern = re.compile('.*Mode:(.*?)\n', __re_mode) mode_pattern = re.compile('.*Mode:(.*?)\n', __re_mode)
freq_pattern = re.compile('.*Frequency:(.*?)\n', __re_mode) freq_pattern = re.compile('.*Frequency:(.*?)\n', __re_mode)
@@ -383,7 +383,7 @@ class BaseInterface(object):
the connection attempt. the connection attempt.
Keyword arguments: Keyword arguments:
pipe -- stdout pipe to the dhcpcd process. pipe -- stdout pipe to the dhclient process.
Returns: Returns:
'success' if succesful', an error code string otherwise. 'success' if succesful', an error code string otherwise.
@@ -408,7 +408,7 @@ class BaseInterface(object):
""" Determines if obtaining an IP using pump succeeded. """ Determines if obtaining an IP using pump succeeded.
Keyword arguments: Keyword arguments:
pipe -- stdout pipe to the dhcpcd process. pipe -- stdout pipe to the pump process.
Returns: Returns:
'success' if succesful, an error code string otherwise. 'success' if succesful, an error code string otherwise.
@@ -443,7 +443,7 @@ class BaseInterface(object):
while not dhcpcd_complete: while not dhcpcd_complete:
line = pipe.readline() line = pipe.readline()
if line.startswith("Error"): if "Error" in line or "timed out" in line:
dhcpcd_success = False dhcpcd_success = False
dhcpcd_complete = True dhcpcd_complete = True
elif line == '': elif line == '':
@@ -1083,18 +1083,8 @@ class BaseWirelessInterface(BaseInterface):
# Link Quality # Link Quality
# Set strength to -1 if the quality is not found # Set strength to -1 if the quality is not found
ap['quality'] = self._get_link_quality(cell)
# more of the patch from if ap['quality'] is None:
# https://bugs.launchpad.net/wicd/+bug/175104
if (strength_pattern.match(cell)):
[(strength, max_strength)] = strength_pattern.findall(cell)
if max_strength:
ap["quality"] = 100 * int(strength) // int(max_strength)
else:
ap["quality"] = int(strength)
elif misc.RunRegex(altstrength_pattern,cell):
ap['quality'] = misc.RunRegex(altstrength_pattern, cell)
else:
ap['quality'] = -1 ap['quality'] = -1
# Signal Strength (only used if user doesn't want link # Signal Strength (only used if user doesn't want link
@@ -1190,6 +1180,22 @@ class BaseWirelessInterface(BaseInterface):
bssid = misc.RunRegex(bssid_pattern, output) bssid = misc.RunRegex(bssid_pattern, output)
return bssid return bssid
def _get_link_quality(self, output):
""" Parse out the link quality from iwlist scan or iwconfig output. """
try:
[(strength, max_strength)] = strength_pattern.findall(output)
except ValueError:
(strength, max_strength) = (None, None)
if strength in ['', None]:
[(strength, max_strength)] = altstrength_pattern.findall(output)
if strength not in ['', None] and max_strength:
return (100 * int(strength) // int(max_strength))
elif strength not in ["", None]:
return int(strength)
else:
return None
def GetSignalStrength(self, iwconfig=None): def GetSignalStrength(self, iwconfig=None):
""" Get the signal strength of the current network. """ Get the signal strength of the current network.
@@ -1203,22 +1209,7 @@ class BaseWirelessInterface(BaseInterface):
output = misc.Run(cmd) output = misc.Run(cmd)
else: else:
output = iwconfig output = iwconfig
return self._get_link_quality(output)
strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)',
re.I | re.M | re.S)
altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)', re.I | re.M | re.S)
[(strength, max_strength)] = strength_pattern.findall(output)
if max_strength and strength:
if int(max_strength) != 0:
return 100 * int(strength) // int(max_strength)
else:
# Prevent a divide by zero error.
strength = int(strength)
if strength is None:
strength = misc.RunRegex(altstrength_pattern, output)
return strength
def GetDBMStrength(self, iwconfig=None): def GetDBMStrength(self, iwconfig=None):
""" Get the dBm signal strength of the current network. """ Get the dBm signal strength of the current network.