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

Merged with r265 of mainline 1.6, providing PyLintish fixes

This commit is contained in:
Andrew Psaltis
2009-01-31 02:13:18 -05:00
12 changed files with 38 additions and 41 deletions

View File

@@ -40,8 +40,7 @@ except Exception, e:
sys.exit(1)
def handler(*args):
loop.quit()
pass
def error_handler(*args):
print>>sys.stderr, 'Async error autoconnecting.'
sys.exit(3)
@@ -51,7 +50,8 @@ if __name__ == '__main__':
time.sleep(2)
daemon.SetSuspend(False)
if not daemon.CheckIfConnecting():
daemon.AutoConnect(True, reply_handler=handler, error_handler=handler)
daemon.AutoConnect(True, reply_handler=handler,
error_handler=error_handler)
except Exception, e:
print>>sys.stderr, "Exception caught: %s" % str(e)
print>>sys.stderr, 'Error autoconnecting.'

View File

@@ -56,11 +56,11 @@ class BackendManager(object):
def get_available_backends(self):
""" Returns a list of all valid backends in the backend directory. """
be_list = [""]
be_list = []
for f in os.listdir(self.backend_dir):
if self._valid_backend_file(os.path.join(self.backend_dir, f)):
be_list.append(f[3:-3])
return be_list
return be_list or [""]
def get_update_interval(self):
""" Returns how often in seconds the wicd monitor should update. """
@@ -90,7 +90,7 @@ class BackendManager(object):
fail(backend_name, 'Invalid backend file.')
return None
def _validate_backend(self, backend):
def _validate_backend(self, backend, backend_name):
""" Ensures that a backend module is valid. """
failed = False
if not backend.NAME:
@@ -117,7 +117,7 @@ class BackendManager(object):
backend = self._load_backend(backend_name)
if not backend : return None
failed = self._validate_backend(backend)
failed = self._validate_backend(backend, backend_name)
if failed:
return None

View File

@@ -500,7 +500,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return 100 * int(strength) // int(max_strength)
else:
# Prevent a divide by zero error.
ap['quality'] = int(strength)
strength = int(strength)
if strength is None:
strength = misc.RunRegex(altstrength_pattern, output)

View File

@@ -293,8 +293,8 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
if not self.scan_iface:
try:
self.scan_iface = iwscan.WirelessInterface(self.iface)
except (iwscan.error, e):
print "GetNetworks caught an exception: %s" %s
except iwscan.error, e:
print "GetNetworks caught an exception: %s" % e
return []
results = self.scan_iface.Scan()

View File

@@ -26,7 +26,7 @@ reusable for other purposes as well.
from ConfigParser import RawConfigParser
from wicd.misc import stringToNone, Noneify, to_unicode
from wicd.misc import Noneify, to_unicode
class ConfigManager(RawConfigParser):
@@ -120,7 +120,7 @@ class ConfigManager(RawConfigParser):
RawConfigParser.write(self, configfile)
configfile.close()
def remove_section(self,section):
def remove_section(self, section):
""" Wrapper around the ConfigParser.remove_section() method.
This method only calls the ConfigParser.remove_section() method
@@ -131,4 +131,5 @@ class ConfigManager(RawConfigParser):
RawConfigParser.remove_section(self, section)
def reload(self):
""" Re-reads the config file, in case it was edited out-of-band. """
self.read(self.config_file)

View File

@@ -211,13 +211,13 @@ def ParseEncryption(network):
# Write the data to the files then chmod them so they can't be read
# by normal users.
file = open(wpath.networks + network["bssid"].replace(":", "").lower(), "w")
f = open(wpath.networks + network["bssid"].replace(":", "").lower(), "w")
os.chmod(wpath.networks + network["bssid"].replace(":", "").lower(), 0600)
os.chown(wpath.networks + network["bssid"].replace(":", "").lower(), 0, 0)
# We could do this above, but we'd like to read protect
# them before we write, so that it can't be read.
file.write(z)
file.close()
f.write(z)
f.close()
def LoadEncryptionMethods():
""" Load encryption methods from configuration files

View File

@@ -43,7 +43,6 @@ dbus_dict = dbusmanager.get_dbus_ifaces()
daemon = dbus_dict["daemon"]
wired = dbus_dict["wired"]
wireless = dbus_dict["wireless"]
bus = dbusmanager.get_bus()
monitor = to_time = update_callback = None
@@ -76,7 +75,7 @@ class ConnectionStatus(object):
1) A wired connection is not in use, but a cable is plugged
in, and the user has chosen to switch to a wired connection
whenever its available, even if already connected to a
wireless network
wireless network.
2) A wired connection is currently active.
@@ -92,6 +91,10 @@ class ConnectionStatus(object):
self.still_wired = True
return True
# Wired connection isn't active
elif wired_ip and self.still_wired:
# If we still have an IP, but no cable is plugged in
# we should disconnect to clear it.
wired.DisconnectWired()
self.still_wired = False
return False
@@ -203,6 +206,13 @@ class ConnectionStatus(object):
return True
def _force_update_connection_status(self):
""" Run a connection status update on demand.
Removes the scheduled update_connection_status()
call, explicitly calls the function, and reschedules
it.
"""
global update_callback
gobject.source_remove(update_callback)
self.update_connection_status()
@@ -289,17 +299,6 @@ class ConnectionStatus(object):
error_handler=err_handle)
self.reconnecting = False
#def rescan_networks(self):
# """ Calls a wireless scan. """
# try:
# if daemon.GetSuspend() or daemon.CheckIfConnecting():
# return True
# wireless.Scan()
# except dbus.exceptions.DBusException, e:
# print 'dbus exception while attempting rescan: %s' % str(e)
# finally:
# return True
def reply_handle():
""" Just a dummy function needed for asynchronous dbus calls. """
pass

View File

@@ -45,7 +45,6 @@ import re
import time
import threading
import thread
import re
# wicd imports
import misc
@@ -82,21 +81,25 @@ def get_backend_list():
return [""]
def get_backend_update_interval():
""" Returns the suggested connection status update interval. """
if BACKEND_MGR:
return BACKEND_MGR.get_update_interval()
else:
return 5 # Seconds, this should never happen though.
def get_current_backend():
""" Returns the current backend instance. """
if BACKEND_MGR:
return BACKEND_MGR.get_current_backend()
else:
return None
def get_backend_description(backend_name):
""" Returns the description of the currently loaded backend. """
return BACKEND_MGR.get_backend_description(backend_name)
def get_backend_description_dict():
""" Returns a dict of all available backend descriptions. """
d = {}
for be in get_backend_list():
if be:

View File

@@ -320,7 +320,6 @@ class PreferencesDialog(object):
# "" is included as a hack for DBus limitations, so we remove it.
self.backends.remove("")
cur_backend = daemon.GetSavedBackend()
for x in self.backends:
self.backendcombo.append_text(x)

View File

@@ -69,10 +69,7 @@ misc.RenameProcess("wicd-client")
if __name__ == '__main__':
wpath.chdir(__file__)
daemon = None
wireless = None
wired = None
wired = None
daemon = wireless = wired = None
DBUS_AVAIL = False
language = misc.get_language_list_tray()
@@ -362,7 +359,6 @@ class TrayIcon(object):
def on_activate(self, data=None):
""" Opens the wicd GUI. """
global DBUS_AVAIL
if DBUS_AVAIL:
self.toggle_wicd_gui()
else:
@@ -644,7 +640,7 @@ Arguments:
""" % wpath.version
def setup_dbus(force=True):
global bus, daemon, wireless, wired, DBUS_AVAIL
global daemon, wireless, wired, DBUS_AVAIL
print "Connecting to daemon..."
try:
dbusmanager.connect_to_dbus()
@@ -661,7 +657,6 @@ def setup_dbus(force=True):
else:
return False
bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon']
wireless = dbus_ifaces['wireless']

View File

@@ -1131,7 +1131,7 @@ class WirelessDaemon(dbus.service.Object):
def ReadWirelessNetworkProfile(self, id):
""" Reads in wireless profile as the active network """
cur_network = self.LastScan[id]
essid_key = "essid:" + cur_network["essid"]
essid_key = "essid:%s" % cur_network["essid"]
bssid_key = cur_network["bssid"]
if self.config.get(essid_key, 'use_settings_globally'):
@@ -1167,7 +1167,7 @@ class WirelessDaemon(dbus.service.Object):
cur_network = self.LastScan[id]
bssid_key = cur_network["bssid"]
essid_key = "essid:" + str(cur_network["essid"])
essid_key = "essid:%s" % cur_network["essid"]
self.config.remove_section(bssid_key)
self.config.add_section(bssid_key)

View File

@@ -34,7 +34,7 @@ class WirelessInterface() -- Control a wireless network interface.
import os
import re
import random
from string import maketrans, translate, punctuation
from string import maketrans, translate
import wpath
import misc