1
0
mirror of https://github.com/gryf/wicd.git synced 2026-01-05 21:34:16 +01:00

Fixing implementation in ioctl

This commit is contained in:
Dario Freddi
2009-03-02 11:44:57 +01:00
5 changed files with 128 additions and 71 deletions

View File

@@ -296,6 +296,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
ap["bssid"] = cell["bssid"]
ap["mode"] = cell["mode"]
ap["bitrates"] = cell["bitrate"]
if cell["enc"]:
ap["encryption"] = True
@@ -484,14 +485,27 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
""" Get the current bitrate for the interface. """
if not self.iface: return ""
data = (self.iface + '\0' * 32)[:32]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
fmt = "ihbb"
size = struct.calcsize(fmt)
try:
result = fcntl.ioctl(self.sock.fileno(), SIOCGIWAP, data)[16:]
data = fcntl.ioctl(s, 0x8B21, ifreq)[16:]  # 0x8B21 is SIOCGIWRATE in /usr/include/linux/wireless.h
except IOError, e:
if self.verbose:
print "SIOCGIWAP failed: " + str(e)
return ""
raw_addr = struct.unpack("xxBBBBBB", result[:8])
return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr
f, e, x, x = struct.unpack(fmt, data[:size])
return (f / 1000000) + ' Mb/s'
def GetOperationalMode(self, iwconfig=None):
""" Get the MAC address for the interface. """
# TODO: implement me
return ''
def GetAvailableAuthMethods(self, iwlistauth=None):
""" Get the MAC address for the interface. """
# TODO: Implement me
return ''
def GetSignalStrength(self, iwconfig=None):
""" Get the signal strength of the current network.

View File

@@ -58,7 +58,7 @@ ROUTE = 2
GKSUDO = 1
KDESU = 2
KTSUSS = 3
__sudo_dict = {
_sudo_dict = {
AUTO : "",
GKSUDO : "gksudo",
KDESU : "kdesu",
@@ -172,9 +172,20 @@ def WriteLine(my_file, text):
""" write a line to a file """
my_file.write(text + "\n")
def ExecuteScript(script):
def ExecuteScripts(scripts_dir, verbose=False):
""" Execute every executable file in a given directory. """
for obj in os.listdir(scripts_dir):
obj = os.path.abspath(os.path.join(scripts_dir, obj))
if os.path.isfile(obj) and os.access(obj, os.X_OK):
ExecuteScript(os.path.abspath(obj), verbose=verbose)
def ExecuteScript(script, verbose=False):
""" Execute a command and send its output to the bit bucket. """
call("%s > /dev/null 2>&1" % script, shell=True)
if verbose:
print "Executing %s" % script
ret = call("%s > /dev/null 2>&1" % script, shell=True)
if verbose:
"%s returned %s" % (script, ret)
def ReadFile(filename):
""" read in a file and return it's contents as a string """
@@ -342,7 +353,11 @@ def get_gettext():
if osLanguage:
langs += osLanguage.split(":")
try:
lc, encoding = locale.getdefaultlocale()
# This avoids a bug: locale.getdefaultlocale() prefers
# LC_CTYPE over LANG/LANGUAGE
lc, encoding = locale.getdefaultlocale(envvars=('LC_MESSAGES',
'LC_ALL', 'LANG',
'LANGUAGE'))
except ValueError, e:
print str(e)
print "Default locale unavailable, falling back to en_US"
@@ -427,7 +442,7 @@ def get_sudo_cmd(msg, prog_num=0):
def choose_sudo_prog(prog_num=0):
""" Try to intelligently decide which graphical sudo program to use. """
if prog_num:
return find_path(__sudo_dict[prog_num])
return find_path(_sudo_dict[prog_num])
desktop_env = detect_desktop_environment()
env_path = os.environ['PATH'].split(":")
paths = []

View File

@@ -46,7 +46,6 @@ import re
import time
import threading
import os
import thread
from signal import SIGTERM
# wicd imports
@@ -203,10 +202,12 @@ class Controller(object):
def Disconnect(self, *args, **kargs):
""" Disconnect from the network. """
iface = self.iface
if self.disconnect_script != None:
misc.ExecuteScripts(wpath.disconnectscripts, self.debug)
if self.disconnect_script:
print 'Running disconnect script'
misc.ExecuteScript(expand_script_macros(self.disconnect_script,
'disconnection', *args))
'disconnection', *args),
self.debug)
iface.ReleaseDHCP()
iface.SetAddress('0.0.0.0')
iface.FlushRoutes()
@@ -268,7 +269,7 @@ class ConnectThread(threading.Thread):
is_connecting = None
should_die = False
lock = thread.allocate_lock()
lock = threading.Lock()
def __init__(self, network, interface_name, before_script, after_script,
disconnect_script, gdns1, gdns2, gdns3, gdns_dom, gsearch_dom,
@@ -369,6 +370,10 @@ class ConnectThread(threading.Thread):
self.SetStatus('interface_down')
iface.Down()
@abortable
def run_global_scripts_if_needed(self, script_dir):
misc.ExecuteScripts(script_dir, verbose=self.debug)
@abortable
def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):
""" Execute a given script if needed.
@@ -380,7 +385,8 @@ class ConnectThread(threading.Thread):
"""
if script:
print 'Executing %s script' % (msg)
misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid))
misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid),
self.debug)
@abortable
def flush_routes(self, iface):
@@ -471,7 +477,7 @@ class ConnectThread(threading.Thread):
try:
if self._should_die:
self.connect_aborted('aborted')
thread.exit()
raise SystemExit
finally:
self.lock.release()
@@ -792,6 +798,7 @@ class WirelessConnectThread(ConnectThread):
self.is_connecting = True
# Run pre-connection script.
self.run_global_scripts_if_needed(wpath.preconnectscripts)
self.run_script_if_needed(self.before_script, 'pre-connection',
self.network['bssid'], self.network['essid'])
@@ -834,6 +841,7 @@ class WirelessConnectThread(ConnectThread):
self.set_dns_addresses()
# Run post-connection script.
self.run_global_scripts_if_needed(wpath.postconnectscripts)
self.run_script_if_needed(self.after_script, 'post-connection',
self.network['bssid'], self.network['essid'])
@@ -1002,6 +1010,7 @@ class WiredConnectThread(ConnectThread):
self.is_connecting = True
# Run pre-connection script.
self.run_global_scripts_if_needed(wpath.preconnectscripts)
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
'wired')
@@ -1020,6 +1029,7 @@ class WiredConnectThread(ConnectThread):
self.set_dns_addresses()
# Run post-connection script.
self.run_global_scripts_if_needed(wpath.postconnectscripts)
self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
'wired')