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

A bunch of small fixes for errors/warnings reported by Pylint.

This commit is contained in:
Dan O'Reilly
2009-01-31 00:31:50 -05:00
parent 339b622b09
commit d22a59cbcc
12 changed files with 38 additions and 41 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -26,7 +26,7 @@ reusable for other purposes as well.
from ConfigParser import RawConfigParser from ConfigParser import RawConfigParser
from wicd.misc import stringToNone, Noneify, to_unicode from wicd.misc import Noneify, to_unicode
class ConfigManager(RawConfigParser): class ConfigManager(RawConfigParser):
@@ -131,4 +131,5 @@ class ConfigManager(RawConfigParser):
RawConfigParser.remove_section(self, section) RawConfigParser.remove_section(self, section)
def reload(self): def reload(self):
""" Re-reads the config file, in case it was edited out-of-band. """
self.read(self.config_file) 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 # Write the data to the files then chmod them so they can't be read
# by normal users. # 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.chmod(wpath.networks + network["bssid"].replace(":", "").lower(), 0600)
os.chown(wpath.networks + network["bssid"].replace(":", "").lower(), 0, 0) os.chown(wpath.networks + network["bssid"].replace(":", "").lower(), 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.
file.write(z) f.write(z)
file.close() f.close()
def LoadEncryptionMethods(): def LoadEncryptionMethods():
""" Load encryption methods from configuration files """ Load encryption methods from configuration files

View File

@@ -43,7 +43,6 @@ dbus_dict = dbusmanager.get_dbus_ifaces()
daemon = dbus_dict["daemon"] daemon = dbus_dict["daemon"]
wired = dbus_dict["wired"] wired = dbus_dict["wired"]
wireless = dbus_dict["wireless"] wireless = dbus_dict["wireless"]
bus = dbusmanager.get_bus()
monitor = to_time = update_callback = None 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 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 in, and the user has chosen to switch to a wired connection
whenever its available, even if already connected to a whenever its available, even if already connected to a
wireless network wireless network.
2) A wired connection is currently active. 2) A wired connection is currently active.
@@ -92,6 +91,10 @@ class ConnectionStatus(object):
self.still_wired = True self.still_wired = True
return True return True
# Wired connection isn't active # 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 self.still_wired = False
return False return False
@@ -203,6 +206,13 @@ class ConnectionStatus(object):
return True return True
def _force_update_connection_status(self): 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 global update_callback
gobject.source_remove(update_callback) gobject.source_remove(update_callback)
self.update_connection_status() self.update_connection_status()
@@ -289,17 +299,6 @@ class ConnectionStatus(object):
error_handler=err_handle) error_handler=err_handle)
self.reconnecting = False 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(): def reply_handle():
""" Just a dummy function needed for asynchronous dbus calls. """ """ Just a dummy function needed for asynchronous dbus calls. """
pass pass

View File

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

View File

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

View File

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

View File

@@ -1131,7 +1131,7 @@ class WirelessDaemon(dbus.service.Object):
def ReadWirelessNetworkProfile(self, id): def ReadWirelessNetworkProfile(self, id):
""" Reads in wireless profile as the active network """ """ Reads in wireless profile as the active network """
cur_network = self.LastScan[id] cur_network = self.LastScan[id]
essid_key = "essid:" + cur_network["essid"] essid_key = "essid:%s" % cur_network["essid"]
bssid_key = cur_network["bssid"] bssid_key = cur_network["bssid"]
if self.config.get(essid_key, 'use_settings_globally'): if self.config.get(essid_key, 'use_settings_globally'):
@@ -1167,7 +1167,7 @@ class WirelessDaemon(dbus.service.Object):
cur_network = self.LastScan[id] cur_network = self.LastScan[id]
bssid_key = cur_network["bssid"] 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.remove_section(bssid_key)
self.config.add_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 os
import re import re
import random import random
from string import maketrans, translate, punctuation from string import maketrans, translate
import wpath import wpath
import misc import misc