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

Merge r463 of mainline 1.6.

This commit is contained in:
Andrew Psaltis
2009-10-31 17:55:04 -04:00
11 changed files with 103 additions and 102 deletions

View File

@@ -65,8 +65,11 @@ class DynWrap(urwid.AttrWrap):
def __init__(self,w,sensitive=True,attrs=('editbx','editnfc'),focus_attr='editfc'): def __init__(self,w,sensitive=True,attrs=('editbx','editnfc'),focus_attr='editfc'):
self._attrs=attrs self._attrs=attrs
self._sensitive = sensitive self._sensitive = sensitive
cur_attr = attrs[0] if sensitive else attrs[1] if sensitive:
cur_attr = attrs[0]
else:
cur_attr = attrs[1]
self.__super.__init__(w,cur_attr,focus_attr) self.__super.__init__(w,cur_attr,focus_attr)
@@ -211,24 +214,27 @@ class TabColumns(urwid.WidgetWrap):
return True return True
def keypress(self,size,key): def keypress(self,size,key):
if key == "meta [" or key == "meta ]": # If the key is page up or page down, move focus to the tabs and call
# left or right on the tabs.
if key == "page up" or key == "page down":
self._w.get_body().set_focus(0) self._w.get_body().set_focus(0)
newK = 'left' if key[-1] == '[' else 'right' if key == "page up":
newK = 'left'
else:
newK = 'right'
self.keypress(size,newK) self.keypress(size,newK)
self._w.get_body().set_focus(1) self._w.get_body().set_focus(1)
else: else:
key = self._w.keypress(size,key) key = self._w.keypress(size,key)
wid = self.pile.get_focus().get_body() wid = self.pile.get_focus().get_body()
if wid == self.columns: if wid == self.columns:
# lw = self.listbox.body
# lw.pop(1)
self.active_tab.set_attr('body') self.active_tab.set_attr('body')
self.columns.get_focus().set_attr('tab active') self.columns.get_focus().set_attr('tab active')
self.active_tab = self.columns.get_focus() self.active_tab = self.columns.get_focus()
self.gen_pile(self.tab_map[self.active_tab]) self.gen_pile(self.tab_map[self.active_tab])
return key return key
# self.listbox.body = lw
def mouse_event(self,size,event,button,x,y,focus): def mouse_event(self,size,event,button,x,y,focus):
wid = self.pile.get_focus().get_body() wid = self.pile.get_focus().get_body()
if wid == self.columns: if wid == self.columns:
@@ -564,26 +570,11 @@ class OptCols(urwid.WidgetWrap):
# callbacks map the text contents to its assigned callback. # callbacks map the text contents to its assigned callback.
self.callbacks = [] self.callbacks = []
for cmd in tuples: for cmd in tuples:
splitcmd = cmd[0].split() key = reduce(lambda s,(f,t):s.replace(f,t), [ \
key = '' ('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'), \
for part in splitcmd: ('left', '<-'), ('right', '->'), \
if part == 'ctrl': ('page up', 'Page Up'), ('page down', 'Page Down'), \
key+='Ctrl+' ('esc', 'ESC'), ('enter', 'Enter'), ('f10','F10')], cmd[0])
elif part == 'meta':
# If anyone has a problem with this, they can bother me
# about it.
key+='Alt+'
else:
if part == 'left':
key += '<-'
elif part == 'right':
key += '->'
elif part == 'esc':
key += 'ESC'
elif part == 'enter':
key += 'Enter'
else:
key += part
if debug: if debug:
callback = self.debugClick callback = self.debugClick

View File

@@ -292,9 +292,7 @@ class PrefsDialog(urwid.WidgetWrap):
### Advanced settings ### Advanced settings
# wpa_supplicant janx # wpa_supplicant janx
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel", self.wpadrivers = wireless.GetWpaSupplicantDrivers()
"ndiswrapper", "ipw"]
self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers)
self.wpadrivers.append("ralink_legacy") self.wpadrivers.append("ralink_legacy")
# Same as above with the dbus.String # Same as above with the dbus.String
self.thedrivers = [unicode(w) for w in self.wpadrivers] self.thedrivers = [unicode(w) for w in self.wpadrivers]

View File

@@ -3,8 +3,8 @@
""" wicd-curses. (curses/urwid-based) console interface to wicd """ wicd-curses. (curses/urwid-based) console interface to wicd
Provides the a console UI for wicd, so that people with broken X servers can Provides a console UI for wicd, so that people with broken X servers can
at least get a network connection. Or those who don't like using X. ;-) at least get a network connection. Or those who don't like using X and/or GTK.
""" """
@@ -254,9 +254,14 @@ def help_dialog(body):
def run_configscript(parent,netname,nettype): def run_configscript(parent,netname,nettype):
configfile = wpath.etc+netname+'-settings.conf' configfile = wpath.etc+netname+'-settings.conf'
header = 'profile' if nettype == 'wired' else 'BSSID' if nettype != 'wired':
profname = netname if nettype == 'wired' else wireless.GetWirelessProperty( header = 'profile'
int(netname),'bssid') else:
header ='BSSID'
if nettype == 'wired':
profname = nettype
else:
profname = wireless.GetWirelessProperty( int(netname),'bssid')
theText = [ theText = [
language['cannot_edit_scripts_1'].replace('$A',configfile).replace('$B',header), language['cannot_edit_scripts_1'].replace('$A',configfile).replace('$B',header),
"\n\n["+profname+"]\n\n", "\n\n["+profname+"]\n\n",
@@ -329,7 +334,12 @@ class NetLabel(urwid.WidgetWrap):
str(wireless.GetWirelessProperty(id, strenstr))) str(wireless.GetWirelessProperty(id, strenstr)))
self.essid = wireless.GetWirelessProperty(id, 'essid') self.essid = wireless.GetWirelessProperty(id, 'essid')
self.bssid = wireless.GetWirelessProperty(id, 'bssid') self.bssid = wireless.GetWirelessProperty(id, 'bssid')
self.encrypt = wireless.GetWirelessProperty(id,'encryption_method') if wireless.GetWirelessProperty(id, 'encryption') else language['unsecured']
if wireless.GetWirelessProperty(id, 'encryption'):
self.encrypt = wireless.GetWirelessProperty(id,'encryption_method')
else:
self.encrypt = language['unsecured']
self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc
self.channel = wireless.GetWirelessProperty(id, 'channel') self.channel = wireless.GetWirelessProperty(id, 'channel')
theString = ' %-*s %25s %9s %17s %6s %4s' % (gap, theString = ' %-*s %25s %9s %17s %6s %4s' % (gap,
@@ -400,7 +410,6 @@ class WiredComboBox(ComboBox):
self.rebuild_combobox() self.rebuild_combobox()
self.set_focus(prev_focus) self.set_focus(prev_focus)
else: else:
print "updating..."
wired.ReadWiredNetworkProfile(self.get_selected_profile()) wired.ReadWiredNetworkProfile(self.get_selected_profile())
if key == 'delete': if key == 'delete':
if len(self.theList) == 1: if len(self.theList) == 1:
@@ -583,11 +592,11 @@ class appGUI():
def init_other_optcols(self): def init_other_optcols(self):
# The "tabbed" preferences dialog # The "tabbed" preferences dialog
self.prefCols = OptCols( [ ('meta enter','OK'), self.prefCols = OptCols( [ ('f10','OK'),
('meta [','Tab Left',), ('page up','Tab Left',),
('meta ]','Tab Right'), ('page down', 'Tab Right'),
('esc','Cancel') ], self.handle_keys) ('esc','Cancel') ], self.handle_keys)
self.confCols = OptCols( [ ('meta enter','OK'), self.confCols = OptCols( [ ('f10','OK'),
('esc','Cancel') ],self.handle_keys) ('esc','Cancel') ],self.handle_keys)
# Does what it says it does # Does what it says it does
@@ -768,6 +777,7 @@ class appGUI():
self.tcount+=1 self.tcount+=1
toAppend=self.twirl[self.tcount % 4] toAppend=self.twirl[self.tcount % 4]
self.status_label.set_text(text+' '+toAppend) self.status_label.set_text(text+' '+toAppend)
self.update_ui()
return True return True
# Make sure the screen is still working by providing a pretty counter. # Make sure the screen is still working by providing a pretty counter.
@@ -776,6 +786,7 @@ class appGUI():
#@wrap_exceptions #@wrap_exceptions
def update_time(self): def update_time(self):
self.time_label.set_text(strftime('%H:%M:%S')) self.time_label.set_text(strftime('%H:%M:%S'))
self.update_ui()
return True return True
# Yeah, I'm copying code. Anything wrong with that? # Yeah, I'm copying code. Anything wrong with that?
@@ -902,7 +913,7 @@ class appGUI():
if k == 'esc' or k == 'q' or k == 'Q': if k == 'esc' or k == 'q' or k == 'Q':
self.restore_primary() self.restore_primary()
break break
if k == 'meta enter': if k == 'f10':
self.diag.save_settings() self.diag.save_settings()
self.restore_primary() self.restore_primary()
break break
@@ -911,17 +922,16 @@ class appGUI():
continue continue
def call_update_ui(self,source,cb_condition): def call_update_ui(self,source,cb_condition):
self.update_ui(from_key=True) self.update_ui(True)
return True return True
# Redraw the screen # Redraw the screen
@wrap_exceptions @wrap_exceptions
def update_ui(self,from_key=True,from_alarm=False): def update_ui(self,from_key=False):
#self.update_status()
canvas = self.frame.render( (self.size),True )
if not ui._started: if not ui._started:
return False return False
canvas = self.frame.render( (self.size),True )
# Update the screen # Update the screen
ui.draw_screen((self.size),canvas) ui.draw_screen((self.size),canvas)
# Get the input data # Get the input data
@@ -932,24 +942,12 @@ class appGUI():
# Resolve any "alarms" in the waiting # Resolve any "alarms" in the waiting
if self.update_tag != None: if self.update_tag != None:
gobject.source_remove(self.update_tag) gobject.source_remove(self.update_tag)
if max_wait == None: if from_key:
max_wait = 25 max_wait = 20
else: self.update_tag = gobject.timeout_add(max_wait, \
max_wait *= 100 self.update_ui,True)
self.handle_keys(keys)
max_wait = int(max_wait) return False
self.update_tag = gobject.timeout_add(max_wait, \
self.update_ui,False,True)
#print keys
#if keys == []:
# return True
self.handle_keys(keys)
# If we came from the "alarm", die.
if from_alarm:
return False
return True
def connect(self, nettype, networkid, networkentry=None): def connect(self, nettype, networkid, networkentry=None):
""" Initiates the connection process in the daemon. """ """ Initiates the connection process in the daemon. """

View File

@@ -60,8 +60,6 @@ Delete the selected wired network profile (from the wired network combo box at t
.TP .TP
.BR F2 .BR F2
Rename the selected wired network profile (from the wired network combo box at the top) Rename the selected wired network profile (from the wired network combo box at the top)
.\".PP
.\"The following are not implemented yet:
.TP .TP
.BR S .BR S
.\"Bring up the script selector for the selected network (requires superuser privileges) .\"Bring up the script selector for the selected network (requires superuser privileges)
@@ -75,13 +73,6 @@ Raise the Ad-Hoc network creation dialog
.I ~/.wicd/WHEREAREMYFILES .I ~/.wicd/WHEREAREMYFILES
Reminder that your network configuration files are not here ;-) Reminder that your network configuration files are not here ;-)
.PP .PP
These following are not used yet:
.TP
.I %LIB%colors.py
Tentative location of the system color schemes
.TP
.I ~/.wicd/colors.py
Custom color schemes.
.SH "SEE ALSO" .SH "SEE ALSO"
.BR wicd-client (1), .BR wicd-client (1),
.BR wicd (8) .BR wicd (8)

View File

@@ -31,7 +31,7 @@ class WirelessInterface() -- Control a wireless network interface.
from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \ from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \
GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \ GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \
BaseWiredInterface, BaseInterface BaseWiredInterface, BaseInterface, GetWpaSupplicantDrivers
NAME = "external" NAME = "external"
UPDATE_INTERVAL = 5 UPDATE_INTERVAL = 5

View File

@@ -34,7 +34,8 @@ from wicd import misc
from wicd import wpath from wicd import wpath
from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \ from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \
GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \ GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \
BaseWiredInterface, BaseInterface, wep_pattern, signaldbm_pattern, neediface BaseWiredInterface, BaseInterface, GetWpaSupplicantDrivers, wep_pattern, \
signaldbm_pattern, neediface
try: try:
import iwscan import iwscan

View File

@@ -124,6 +124,9 @@ class ConfigManager(RawConfigParser):
def write(self): def write(self):
""" Writes the loaded config file to disk. """ """ Writes the loaded config file to disk. """
for section in self.sections():
if not section:
self.remove_section(section)
configfile = open(self.config_file, 'w') configfile = open(self.config_file, 'w')
RawConfigParser.write(self, configfile) RawConfigParser.write(self, configfile)
configfile.close() configfile.close()

View File

@@ -528,6 +528,14 @@ class ConnectThread(threading.Thread):
print 'Putting interface up...' print 'Putting interface up...'
self.SetStatus('interface_up') self.SetStatus('interface_up')
iface.Up() iface.Up()
for x in range(0, 5):
time.sleep(2)
if iface.IsUp():
return
self.abort_if_needed()
# If we get here, the interface never came up
print "WARNING: Timed out waiting for interface to come up"
class Wireless(Controller): class Wireless(Controller):
@@ -697,10 +705,9 @@ class Wireless(Controller):
""" Get the out of iwconfig. """ """ Get the out of iwconfig. """
return self.wiface.GetIwconfig() return self.wiface.GetIwconfig()
def GetWpaSupplicantDrivers(self, drivers): def GetWpaSupplicantDrivers(self):
""" Returns all valid wpa_supplicant drivers in a list. """ """ Returns all valid wpa_supplicant drivers on the system. """
return [driver for driver in drivers if return BACKEND.GetWpaSupplicantDrivers()
BACKEND.IsValidWpaSuppDriver(driver)]
def StopWPA(self): def StopWPA(self):
return self.wiface.StopWPA() return self.wiface.StopWPA()
@@ -771,7 +778,7 @@ class Wireless(Controller):
iwconfig = self.GetIwconfig() iwconfig = self.GetIwconfig()
else: else:
iwconfig = None iwconfig = None
bssid = self.wiface.GetBSSID(iwconfig), bssid = self.wiface.GetBSSID(iwconfig)
essid = self.wiface.GetCurrentNetwork(iwconfig) essid = self.wiface.GetCurrentNetwork(iwconfig)
Controller.Disconnect(self, bssid, essid) Controller.Disconnect(self, bssid, essid)

View File

@@ -375,9 +375,7 @@ class PreferencesDialog(object):
# Replacement for the combo box hack # Replacement for the combo box hack
self.wpadrivercombo = build_combobox("pref_wpa_combobox") self.wpadrivercombo = build_combobox("pref_wpa_combobox")
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel", self.wpadrivers = wireless.GetWpaSupplicantDrivers()
"ndiswrapper", "ipw"]
self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers)
self.wpadrivers.append("ralink_legacy") self.wpadrivers.append("ralink_legacy")
for x in self.wpadrivers: for x in self.wpadrivers:

View File

@@ -1145,7 +1145,7 @@ class WirelessDaemon(dbus.service.Object):
'predisconnectscript') 'predisconnectscript')
self.wifi.post_disconnect_script = self.GetWirelessProperty(id, self.wifi.post_disconnect_script = self.GetWirelessProperty(id,
'postdisconnectscript') 'postdisconnectscript')
print 'Connecting to wireless network ' + self.LastScan[id]['essid'] print 'Connecting to wireless network ' + str(self.LastScan[id]['essid'])
self.daemon.wired_bus.wired.Disconnect() self.daemon.wired_bus.wired.Disconnect()
self.daemon.SetForcedDisconnect(False) self.daemon.SetForcedDisconnect(False)
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
@@ -1270,9 +1270,9 @@ class WirelessDaemon(dbus.service.Object):
self.config.remove_section(essid_key) self.config.remove_section(essid_key)
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetWpaSupplicantDrivers(self, drivers): def GetWpaSupplicantDrivers(self):
""" Returns all valid wpa_supplicant drivers in a given list. """ """ Returns all valid wpa_supplicant drivers. """
return self.wifi.GetWpaSupplicantDrivers(drivers) return self.wifi.GetWpaSupplicantDrivers()
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def ReloadConfig(self): def ReloadConfig(self):
@@ -1447,6 +1447,8 @@ class WiredDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CreateWiredNetworkProfile(self, profilename, default=False): def CreateWiredNetworkProfile(self, profilename, default=False):
""" Creates a wired network profile. """ """ Creates a wired network profile. """
if not profilename:
return False
profilename = misc.to_unicode(profilename) profilename = misc.to_unicode(profilename)
print "Creating wired profile for " + profilename print "Creating wired profile for " + profilename
if self.config.has_section(profilename): if self.config.has_section(profilename):
@@ -1687,7 +1689,7 @@ def main(argv):
logpath = os.path.join(wpath.log, 'wicd.log') logpath = os.path.join(wpath.log, 'wicd.log')
if not os.path.exists(wpath.log): if not os.path.exists(wpath.log):
os.makedirs(wpath.log) os.makedirs(wpath.log)
os.chmod(wpath.log, 755) os.chmod(wpath.log, 0755)
output = ManagedStdio(logpath) output = ManagedStdio(logpath)
if os.path.exists(logpath): if os.path.exists(logpath):
try: try:

View File

@@ -156,6 +156,17 @@ def NeedsExternalCalls():
""" Returns True if the backend needs to use an external program. """ """ Returns True if the backend needs to use an external program. """
raise NotImplementedError raise NotImplementedError
def GetWpaSupplicantDrivers():
""" Returns a list of all valid wpa_supplicant drivers. """
output = misc.Run(["wpa_supplicant", "-h"])
try:
output = output.split("drivers:")[1].split("options:")[0].strip()
except:
print "Warning: Couldn't get list of valid wpa_supplicant drivers"
return [""]
patt = re.compile("(\S+)\s+=.*")
return patt.findall(output) or [""]
def IsValidWpaSuppDriver(driver): def IsValidWpaSuppDriver(driver):
""" Returns True if given string is a valid wpa_supplicant driver. """ """ Returns True if given string is a valid wpa_supplicant driver. """
output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iolan19", output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iolan19",
@@ -551,19 +562,20 @@ class BaseInterface(object):
if self.verbose: print cmd if self.verbose: print cmd
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
pipe = self.dhcp_object.stdout pipe = self.dhcp_object.stdout
client_dict = { misc.DHCLIENT : self._parse_dhclient,
misc.DHCPCD : self._parse_dhcpcd,
misc.PUMP : self._parse_pump,
misc.UDHCPC : self._parse_udhcpc,
}
DHCP_CLIENT = self._get_dhcp_command() DHCP_CLIENT = self._get_dhcp_command()
if DHCP_CLIENT == misc.DHCLIENT: if DHCP_CLIENT in client_dict:
return self._parse_dhclient(pipe) ret = client_dict[DHCP_CLIENT](pipe)
elif DHCP_CLIENT == misc.PUMP:
return self._parse_pump(pipe)
elif DHCP_CLIENT == misc.DHCPCD:
return self._parse_dhcpcd(pipe)
elif DHCP_CLIENT == misc.UDHCPC:
return self._parse_udhcpc(pipe)
else: else:
print 'ERROR no dhclient found!' print "ERROR: no dhcp client found"
ret = None
return ret
@neediface(False) @neediface(False)
def ReleaseDHCP(self): def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """ """ Release the DHCP lease for this interface. """
@@ -844,7 +856,7 @@ class BaseWirelessInterface(BaseInterface):
essid -- essid to set the interface to essid -- essid to set the interface to
""" """
cmd = ['iwconfig', self.iface, 'essid', essid] cmd = ['iwconfig', self.iface, 'essid', str(essid)]
if self.verbose: print str(cmd) if self.verbose: print str(cmd)
misc.Run(cmd) misc.Run(cmd)
@@ -1055,7 +1067,7 @@ class BaseWirelessInterface(BaseInterface):
if not wpa_pass_path: return None if not wpa_pass_path: return None
key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*', key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
re.I | re.M | re.S) re.I | re.M | re.S)
cmd = [wpa_pass_path, network['essid'], str(network['key'])] cmd = [wpa_pass_path, str(network['essid']), str(network['key'])]
if self.verbose: print cmd if self.verbose: print cmd
return misc.RunRegex(key_pattern, misc.Run(cmd)) return misc.RunRegex(key_pattern, misc.Run(cmd))