mirror of
https://github.com/gryf/wicd.git
synced 2026-02-20 17:05:46 +01:00
Get rid of unneeded "use_tray" variable being passed around in wicd-client.
Add some methods for executing multiple scripts to be use for global scripts later. Remove some rogue extra whitespace in networking.py
This commit is contained in:
21
wicd/misc.py
21
wicd/misc.py
@@ -57,7 +57,7 @@ ROUTE = 2
|
|||||||
GKSUDO = 1
|
GKSUDO = 1
|
||||||
KDESU = 2
|
KDESU = 2
|
||||||
KTSUSS = 3
|
KTSUSS = 3
|
||||||
sudo_dict = {
|
_sudo_dict = {
|
||||||
AUTO : "",
|
AUTO : "",
|
||||||
GKSUDO : "gksudo",
|
GKSUDO : "gksudo",
|
||||||
KDESU : "kdesu",
|
KDESU : "kdesu",
|
||||||
@@ -171,9 +171,20 @@ def WriteLine(my_file, text):
|
|||||||
""" write a line to a file """
|
""" write a line to a file """
|
||||||
my_file.write(text + "\n")
|
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. """
|
""" 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):
|
def ReadFile(filename):
|
||||||
""" read in a file and return it's contents as a string """
|
""" read in a file and return it's contents as a string """
|
||||||
@@ -409,7 +420,7 @@ def get_sudo_cmd(msg, prog_num=0):
|
|||||||
def choose_sudo_prog(prog_num=0):
|
def choose_sudo_prog(prog_num=0):
|
||||||
""" Try to intelligently decide which graphical sudo program to use. """
|
""" Try to intelligently decide which graphical sudo program to use. """
|
||||||
if prog_num:
|
if prog_num:
|
||||||
return find_path(sudo_dict[prog_num])
|
return find_path(_sudo_dict[prog_num])
|
||||||
desktop_env = detect_desktop_environment()
|
desktop_env = detect_desktop_environment()
|
||||||
env_path = os.environ['PATH'].split(":")
|
env_path = os.environ['PATH'].split(":")
|
||||||
paths = []
|
paths = []
|
||||||
@@ -667,4 +678,4 @@ def timeout_add(time, func, milli=False):
|
|||||||
else:
|
else:
|
||||||
if not milli: time = time * 1000
|
if not milli: time = time * 1000
|
||||||
return gobject.timeout_add(time, func)
|
return gobject.timeout_add(time, func)
|
||||||
|
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ class ConnectThread(threading.Thread):
|
|||||||
print 'Setting the broadcast address...' + self.network['broadcast']
|
print 'Setting the broadcast address...' + self.network['broadcast']
|
||||||
iface.SetAddress(broadcast=self.network['broadcast'])
|
iface.SetAddress(broadcast=self.network['broadcast'])
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def set_ip_address(self, iface):
|
def set_ip_address(self, iface):
|
||||||
""" Set the IP address for the given interface.
|
""" Set the IP address for the given interface.
|
||||||
|
|
||||||
@@ -420,7 +420,7 @@ class ConnectThread(threading.Thread):
|
|||||||
self.abort_connection(dhcp_status)
|
self.abort_connection(dhcp_status)
|
||||||
return
|
return
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def set_dns_addresses(self):
|
def set_dns_addresses(self):
|
||||||
""" Set the DNS address(es).
|
""" Set the DNS address(es).
|
||||||
|
|
||||||
@@ -443,7 +443,7 @@ class ConnectThread(threading.Thread):
|
|||||||
self.network.get('dns_domain'),
|
self.network.get('dns_domain'),
|
||||||
self.network.get('search_domain'))
|
self.network.get('search_domain'))
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def release_dhcp_clients(self, iface):
|
def release_dhcp_clients(self, iface):
|
||||||
""" Release all running dhcp clients. """
|
""" Release all running dhcp clients. """
|
||||||
print "Releasing DHCP leases..."
|
print "Releasing DHCP leases..."
|
||||||
@@ -474,7 +474,7 @@ class ConnectThread(threading.Thread):
|
|||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def put_iface_up(self, iface):
|
def put_iface_up(self, iface):
|
||||||
""" Bring up given interface. """
|
""" Bring up given interface. """
|
||||||
print 'Putting interface up...'
|
print 'Putting interface up...'
|
||||||
@@ -819,7 +819,7 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
print 'Stopping wpa_supplicant'
|
print 'Stopping wpa_supplicant'
|
||||||
wiface.StopWPA()
|
wiface.StopWPA()
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def generate_psk_and_authenticate(self, wiface):
|
def generate_psk_and_authenticate(self, wiface):
|
||||||
""" Generates a PSK and authenticates if necessary.
|
""" Generates a PSK and authenticates if necessary.
|
||||||
|
|
||||||
|
|||||||
@@ -109,12 +109,12 @@ class TrayIcon(object):
|
|||||||
Base Class for implementing a tray icon to display network status.
|
Base Class for implementing a tray icon to display network status.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, use_tray, animate):
|
def __init__(self, animate):
|
||||||
if USE_EGG:
|
if USE_EGG:
|
||||||
self.tr = self.EggTrayIconGUI(use_tray)
|
self.tr = self.EggTrayIconGUI()
|
||||||
else:
|
else:
|
||||||
self.tr = self.StatusTrayIconGUI(use_tray)
|
self.tr = self.StatusTrayIconGUI()
|
||||||
self.icon_info = self.TrayConnectionInfo(self.tr, use_tray, animate)
|
self.icon_info = self.TrayConnectionInfo(self.tr, animate)
|
||||||
|
|
||||||
def is_embedded(self):
|
def is_embedded(self):
|
||||||
if USE_EGG:
|
if USE_EGG:
|
||||||
@@ -125,7 +125,7 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
class TrayConnectionInfo(object):
|
class TrayConnectionInfo(object):
|
||||||
""" Class for updating the tray icon status. """
|
""" Class for updating the tray icon status. """
|
||||||
def __init__(self, tr, use_tray=True, animate=True):
|
def __init__(self, tr, animate=True):
|
||||||
""" Initialize variables needed for the icon status methods. """
|
""" Initialize variables needed for the icon status methods. """
|
||||||
self.last_strength = -2
|
self.last_strength = -2
|
||||||
self.still_wired = False
|
self.still_wired = False
|
||||||
@@ -133,7 +133,6 @@ class TrayIcon(object):
|
|||||||
self.tried_reconnect = False
|
self.tried_reconnect = False
|
||||||
self.connection_lost_counter = 0
|
self.connection_lost_counter = 0
|
||||||
self.tr = tr
|
self.tr = tr
|
||||||
self.use_tray = use_tray
|
|
||||||
self.last_sndbytes = -1
|
self.last_sndbytes = -1
|
||||||
self.last_rcvbytes = -1
|
self.last_rcvbytes = -1
|
||||||
self.max_snd_gain = 10000
|
self.max_snd_gain = 10000
|
||||||
@@ -203,7 +202,7 @@ class TrayIcon(object):
|
|||||||
@catchdbus
|
@catchdbus
|
||||||
def update_tray_icon(self, state=None, info=None):
|
def update_tray_icon(self, state=None, info=None):
|
||||||
""" Updates the tray icon and current connection status. """
|
""" Updates the tray icon and current connection status. """
|
||||||
if not self.use_tray or not DBUS_AVAIL: return False
|
if not DBUS_AVAIL: return False
|
||||||
|
|
||||||
if not state or not info:
|
if not state or not info:
|
||||||
[state, info] = daemon.GetConnectionStatus()
|
[state, info] = daemon.GetConnectionStatus()
|
||||||
@@ -330,7 +329,7 @@ class TrayIcon(object):
|
|||||||
tray icons.
|
tray icons.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, use_tray):
|
def __init__(self):
|
||||||
menu = """
|
menu = """
|
||||||
<ui>
|
<ui>
|
||||||
<menubar name="Menubar">
|
<menubar name="Menubar">
|
||||||
@@ -361,7 +360,6 @@ class TrayIcon(object):
|
|||||||
props.parent)
|
props.parent)
|
||||||
self.gui_win = None
|
self.gui_win = None
|
||||||
self.current_icon_path = None
|
self.current_icon_path = None
|
||||||
self.use_tray = use_tray
|
|
||||||
self._is_scanning = False
|
self._is_scanning = False
|
||||||
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
||||||
net_menuitem.connect("activate", self.on_net_menu_activate)
|
net_menuitem.connect("activate", self.on_net_menu_activate)
|
||||||
@@ -571,14 +569,9 @@ class TrayIcon(object):
|
|||||||
for machines running versions of GTK < 2.10.
|
for machines running versions of GTK < 2.10.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, use_tray=True):
|
def __init__(self):
|
||||||
"""Initializes the tray icon"""
|
"""Initializes the tray icon"""
|
||||||
TrayIcon.TrayIconGUI.__init__(self, use_tray)
|
TrayIcon.TrayIconGUI.__init__(self)
|
||||||
self.use_tray = use_tray
|
|
||||||
if not use_tray:
|
|
||||||
self.toggle_wicd_gui()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.tooltip = gtk.Tooltips()
|
self.tooltip = gtk.Tooltips()
|
||||||
self.eb = gtk.EventBox()
|
self.eb = gtk.EventBox()
|
||||||
self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
|
self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
|
||||||
@@ -601,7 +594,6 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def set_from_file(self, val=None):
|
def set_from_file(self, val=None):
|
||||||
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
||||||
if not self.use_tray: return
|
|
||||||
self.pic.set_from_file(val)
|
self.pic.set_from_file(val)
|
||||||
|
|
||||||
def set_tooltip(self, val):
|
def set_tooltip(self, val):
|
||||||
@@ -611,7 +603,6 @@ class TrayIcon(object):
|
|||||||
tray icon.
|
tray icon.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.use_tray: return
|
|
||||||
self.tooltip.set_tip(self.eb, val)
|
self.tooltip.set_tip(self.eb, val)
|
||||||
|
|
||||||
|
|
||||||
@@ -622,13 +613,8 @@ class TrayIcon(object):
|
|||||||
Uses gtk.StatusIcon to implement a tray icon.
|
Uses gtk.StatusIcon to implement a tray icon.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, use_tray=True):
|
def __init__(self):
|
||||||
TrayIcon.TrayIconGUI.__init__(self, use_tray)
|
TrayIcon.TrayIconGUI.__init__(self)
|
||||||
self.use_tray = use_tray
|
|
||||||
if not use_tray:
|
|
||||||
self.toggle_wicd_gui()
|
|
||||||
return
|
|
||||||
|
|
||||||
gtk.StatusIcon.__init__(self)
|
gtk.StatusIcon.__init__(self)
|
||||||
|
|
||||||
self.current_icon_path = ''
|
self.current_icon_path = ''
|
||||||
@@ -645,7 +631,6 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def set_from_file(self, path=None):
|
def set_from_file(self, path=None):
|
||||||
""" Sets a new tray icon picture. """
|
""" Sets a new tray icon picture. """
|
||||||
if not self.use_tray: return
|
|
||||||
if path != self.current_icon_path:
|
if path != self.current_icon_path:
|
||||||
self.current_icon_path = path
|
self.current_icon_path = path
|
||||||
gtk.StatusIcon.set_from_file(self, path)
|
gtk.StatusIcon.set_from_file(self, path)
|
||||||
@@ -716,9 +701,6 @@ def main(argv):
|
|||||||
argv -- The arguments passed to the script.
|
argv -- The arguments passed to the script.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
use_tray = True
|
|
||||||
animate = True
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'nha', ['help', 'no-tray',
|
opts, args = getopt.getopt(sys.argv[1:], 'nha', ['help', 'no-tray',
|
||||||
'no-animate'])
|
'no-animate'])
|
||||||
@@ -727,6 +709,8 @@ def main(argv):
|
|||||||
usage()
|
usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
use_tray = True
|
||||||
|
animate = True
|
||||||
for opt, a in opts:
|
for opt, a in opts:
|
||||||
if opt in ('-h', '--help'):
|
if opt in ('-h', '--help'):
|
||||||
usage()
|
usage()
|
||||||
@@ -750,7 +734,7 @@ def main(argv):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Set up the tray icon GUI and backend
|
# Set up the tray icon GUI and backend
|
||||||
tray_icon = TrayIcon(use_tray, animate)
|
tray_icon = TrayIcon(animate)
|
||||||
|
|
||||||
# Check to see if wired profile chooser was called before icon
|
# Check to see if wired profile chooser was called before icon
|
||||||
# was launched (typically happens on startup or daemon restart).
|
# was launched (typically happens on startup or daemon restart).
|
||||||
@@ -767,7 +751,8 @@ def main(argv):
|
|||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
||||||
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(),
|
bus.add_signal_receiver(lambda: (handle_no_dbus() or
|
||||||
|
tray_icon.icon_info.set_not_connected_state()),
|
||||||
"DaemonClosing", 'org.wicd.daemon')
|
"DaemonClosing", 'org.wicd.daemon')
|
||||||
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
|
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
|
||||||
"org.wicd.daemon")
|
"org.wicd.daemon")
|
||||||
|
|||||||
Reference in New Issue
Block a user