1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-24 07:02:29 +01:00

Make the ioctl backends use of python-iwscan and python-wpactrl optional.

Don't use __all__ in wnettools.py, and make the backends explicitly import the methods/classes they need from wnettools.py.
This commit is contained in:
Dan O'Reilly
2009-03-23 01:28:50 -04:00
parent d09344b329
commit bb9d3690de
3 changed files with 40 additions and 25 deletions

View File

@@ -31,7 +31,9 @@ class WirelessInterface() -- Control a wireless network interface.
from wicd import misc
from wicd import wnettools
from wicd.wnettools import *
from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \
GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \
BaseWiredInterface, BaseInterface
import re
import os
import os.path
@@ -53,11 +55,11 @@ RALINK_DRIVER = 'ralink legacy'
def NeedsExternalCalls(*args, **kargs):
""" Return True, since this backend using iwconfig/ifconfig. """
""" Return True, since this backend uses iwconfig/ifconfig. """
return True
class Interface(wnettools.BaseInterface):
class Interface(BaseInterface):
""" Control a network interface. """
def __init__(self, iface, verbose=False):
""" Initialize the object.
@@ -67,11 +69,11 @@ class Interface(wnettools.BaseInterface):
verbose -- whether to print every command run
"""
wnettools.BaseInterface.__init__(self, iface, verbose)
BaseInterface.__init__(self, iface, verbose)
self.Check()
class WiredInterface(Interface, wnettools.BaseWiredInterface):
class WiredInterface(Interface, BaseWiredInterface):
""" Control a wired network interface. """
def __init__(self, iface, verbose=False):
""" Initialise the wired network interface class.
@@ -81,11 +83,11 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
verbose -- print all commands
"""
wnettools.BaseWiredInterface.__init__(self, iface, verbose)
BaseWiredInterface.__init__(self, iface, verbose)
Interface.__init__(self, iface, verbose)
class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
class WirelessInterface(Interface, BaseWirelessInterface):
""" Control a wireless network interface. """
def __init__(self, iface, verbose=False, wpa_driver='wext'):
""" Initialise the wireless network interface class.
@@ -95,7 +97,6 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
verbose -- print all commands
"""
wnettools.BaseWirelessInterface.__init__(self, iface, verbose,
wpa_driver)
BaseWirelessInterface.__init__(self, iface, verbose, wpa_driver)
Interface.__init__(self, iface, verbose)

View File

@@ -33,11 +33,23 @@ class WirelessInterface() -- Control a wireless network interface.
from wicd import misc
from wicd import wnettools
from wicd import wpath
from wicd.wnettools import *
from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \
GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \
BaseWiredInterface, BaseInterface
from wicd.wnettools import wep_pattern, signaldbm_pattern, neediface
import iwscan
import wpactrl
try:
import iwscan
IWSCAN_AVAIL = True
except ImportError:
print "WARNING: python-iwscan not found, falling back to using iwlist scan."
IWSCAN_AVAIL = False
try:
import wpactrl
WPACTRL_AVAIL = True
except ImportError:
print "WARNING: python-wpactrl not found, falling back to using wpa_cli."
WPACTRL_AVAIL = False
import re
import os
@@ -56,7 +68,7 @@ This backend uses IOCTL calls and python libraries to query
network information whenever possible. This makes it fast,
but it may not work properly on all systems.
Dependencies:
(Optional) Dependencies:
python-wpactrl (http://projects.otaku42.de/wiki/PythonWpaCtrl)
python-iwscan (http://projects.otaku42.de/browser/python-iwscan/)"""
@@ -105,7 +117,7 @@ def NeedsExternalCalls(*args, **kargs):
return False
class Interface(wnettools.BaseInterface):
class Interface(BaseInterface):
""" Control a network interface. """
def __init__(self, iface, verbose=False):
""" Initialise the object.
@@ -115,7 +127,7 @@ class Interface(wnettools.BaseInterface):
verbose -- whether to print every command run
"""
wnettools.BaseInterface.__init__(self, iface, verbose)
BaseInterface.__init__(self, iface, verbose)
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.Check()
@@ -162,7 +174,7 @@ class Interface(wnettools.BaseInterface):
return bool(flags & 1)
class WiredInterface(Interface, wnettools.BaseWiredInterface):
class WiredInterface(Interface, BaseWiredInterface):
""" Control a wired network interface. """
def __init__(self, iface, verbose=False):
""" Initialise the wired network interface class.
@@ -172,7 +184,7 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
verbose -- print all commands
"""
wnettools.BaseWiredInterface.__init__(self, iface, verbose)
BaseWiredInterface.__init__(self, iface, verbose)
Interface.__init__(self, iface, verbose)
@neediface(False)
@@ -240,7 +252,7 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
return bool(reg & 0x0004)
class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
class WirelessInterface(Interface, BaseWirelessInterface):
""" Control a wireless network interface. """
def __init__(self, iface, verbose=False, wpa_driver='wext'):
""" Initialise the wireless network interface class.
@@ -250,7 +262,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
verbose -- print all commands
"""
wnettools.BaseWirelessInterface.__init__(self, iface, verbose,
BaseWirelessInterface.__init__(self, iface, verbose,
wpa_driver)
Interface.__init__(self, iface, verbose)
self.scan_iface = None
@@ -263,6 +275,10 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
A list containing available wireless networks.
"""
if not IWSCAN_AVAIL:
# Use the slow version if python-iwscan isn't available.
return BaseWirelessInterface.GetNetworks(self)
if not self.scan_iface:
try:
self.scan_iface = iwscan.WirelessInterface(self.iface)
@@ -361,9 +377,10 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
False otherwise.
"""
error= "Unable to find ctrl_interface for wpa_supplicant. " + \
"Could not validate authentication."
if not WPACTRL_AVAIL:
# If we don't have python-wpactrl, use the slow version.
return BaseWirelessInterface.ValidateAuthentication(self, auth_time)
# Right now there's no way to do this for ralink drivers
if self.wpa_driver == RALINK_DRIVER:
return True

View File

@@ -72,9 +72,6 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ '
blacklist_norm = ";`$!*|><&\\"
blank_trans = maketrans("", "")
__all__ = ["GetDefaultGateway", "GetWiredInterfaces",
"GetWirelessInterfaces", "IsValidWpaSuppDriver"]
def _sanitize_string(string):
if string:
return translate(str(string), blank_trans, blacklist_norm)