mirror of
https://github.com/gryf/wicd.git
synced 2025-12-23 06:37:59 +01:00
added support for passing parameters to the global scripts
This commit is contained in:
11
wicd/misc.py
11
wicd/misc.py
@@ -180,18 +180,19 @@ 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 ExecuteScripts(scripts_dir, verbose=False):
|
def ExecuteScripts(scripts_dir, verbose=False, extra_parameters=()):
|
||||||
""" Execute every executable file in a given directory. """
|
""" Execute every executable file in a given directory. """
|
||||||
for obj in os.listdir(scripts_dir):
|
for obj in os.listdir(scripts_dir):
|
||||||
obj = os.path.abspath(os.path.join(scripts_dir, obj))
|
obj = os.path.abspath(os.path.join(scripts_dir, obj))
|
||||||
if os.path.isfile(obj) and os.access(obj, os.X_OK):
|
if os.path.isfile(obj) and os.access(obj, os.X_OK):
|
||||||
ExecuteScript(os.path.abspath(obj), verbose=verbose)
|
ExecuteScript(os.path.abspath(obj), verbose=verbose,
|
||||||
|
extra_parameters=extra_parameters)
|
||||||
|
|
||||||
def ExecuteScript(script, verbose=False):
|
def ExecuteScript(script, verbose=False, extra_parameters=()):
|
||||||
""" Execute a command and send its output to the bit bucket. """
|
""" Execute a command and send its output to the bit bucket. """
|
||||||
if verbose:
|
if verbose:
|
||||||
print "Executing %s" % script
|
print "Executing %s with params %s" % (script, ' '.join(extra_parameters))
|
||||||
ret = call("%s > /dev/null 2>&1" % script, shell=True)
|
ret = call("%s %s > /dev/null 2>&1" % (script, ' '.join(extra_parameters)), shell=True)
|
||||||
if verbose:
|
if verbose:
|
||||||
print "%s returned %s" % (script, ret)
|
print "%s returned %s" % (script, ret)
|
||||||
|
|
||||||
|
|||||||
@@ -201,25 +201,34 @@ class Controller(object):
|
|||||||
"""
|
"""
|
||||||
return self.iface.GetIP(ifconfig)
|
return self.iface.GetIP(ifconfig)
|
||||||
|
|
||||||
def Disconnect(self, *args, **kargs):
|
def Disconnect(self, nettype, name, mac):
|
||||||
""" Disconnect from the network. """
|
""" Disconnect from the network. """
|
||||||
iface = self.iface
|
iface = self.iface
|
||||||
misc.ExecuteScripts(wpath.predisconnectscripts, self.debug)
|
# mac and name need to be strings
|
||||||
|
if mac == None:
|
||||||
|
mac = ''
|
||||||
|
if name == None:
|
||||||
|
name = ''
|
||||||
|
misc.ExecuteScripts(wpath.predisconnectscripts, self.debug,
|
||||||
|
extra_parameters=(nettype, name, mac))
|
||||||
if self.pre_disconnect_script:
|
if self.pre_disconnect_script:
|
||||||
print 'Running pre-disconnect script'
|
print 'Running pre-disconnect script'
|
||||||
misc.ExecuteScript(expand_script_macros(self.pre_disconnect_script,
|
misc.ExecuteScript(expand_script_macros(self.pre_disconnect_script,
|
||||||
'pre-disconnection', *args),
|
'pre-disconnection', (mac,
|
||||||
|
name)),
|
||||||
self.debug)
|
self.debug)
|
||||||
iface.ReleaseDHCP()
|
iface.ReleaseDHCP()
|
||||||
iface.SetAddress('0.0.0.0')
|
iface.SetAddress('0.0.0.0')
|
||||||
iface.FlushRoutes()
|
iface.FlushRoutes()
|
||||||
iface.Down()
|
iface.Down()
|
||||||
iface.Up()
|
iface.Up()
|
||||||
misc.ExecuteScripts(wpath.postdisconnectscripts, self.debug)
|
misc.ExecuteScripts(wpath.postdisconnectscripts, self.debug,
|
||||||
|
extra_parameters=(nettype, name, mac))
|
||||||
if self.post_disconnect_script:
|
if self.post_disconnect_script:
|
||||||
print 'Running post-disconnect script'
|
print 'Running post-disconnect script'
|
||||||
misc.ExecuteScript(expand_script_macros(self.post_disconnect_script,
|
misc.ExecuteScript(expand_script_macros(self.post_disconnect_script,
|
||||||
'post-disconnection', *args),
|
'post-disconnection',
|
||||||
|
(mac, name)),
|
||||||
self.debug)
|
self.debug)
|
||||||
|
|
||||||
def ReleaseDHCP(self):
|
def ReleaseDHCP(self):
|
||||||
@@ -387,8 +396,9 @@ class ConnectThread(threading.Thread):
|
|||||||
iface.Down()
|
iface.Down()
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def run_global_scripts_if_needed(self, script_dir):
|
def run_global_scripts_if_needed(self, script_dir, extra_parameters=()):
|
||||||
misc.ExecuteScripts(script_dir, verbose=self.debug)
|
misc.ExecuteScripts(script_dir, verbose=self.debug,
|
||||||
|
extra_parameters=extra_parameters)
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):
|
def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):
|
||||||
@@ -769,10 +779,10 @@ 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, 'wireless', essid, bssid)
|
||||||
self.StopWPA()
|
self.StopWPA()
|
||||||
|
|
||||||
def SetWPADriver(self, driver):
|
def SetWPADriver(self, driver):
|
||||||
@@ -832,7 +842,11 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
self.is_connecting = True
|
self.is_connecting = True
|
||||||
|
|
||||||
# Run pre-connection script.
|
# Run pre-connection script.
|
||||||
self.run_global_scripts_if_needed(wpath.preconnectscripts)
|
self.run_global_scripts_if_needed(wpath.preconnectscripts,
|
||||||
|
extra_parameters=('wireless',
|
||||||
|
self.network['essid'],
|
||||||
|
self.network['bssid'])
|
||||||
|
)
|
||||||
self.run_script_if_needed(self.before_script, 'pre-connection',
|
self.run_script_if_needed(self.before_script, 'pre-connection',
|
||||||
self.network['bssid'], self.network['essid'])
|
self.network['bssid'], self.network['essid'])
|
||||||
|
|
||||||
@@ -876,7 +890,11 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
self.verify_association(wiface)
|
self.verify_association(wiface)
|
||||||
|
|
||||||
# Run post-connection script.
|
# Run post-connection script.
|
||||||
self.run_global_scripts_if_needed(wpath.postconnectscripts)
|
self.run_global_scripts_if_needed(wpath.postconnectscripts,
|
||||||
|
extra_parameters=('wireless',
|
||||||
|
self.network['essid'],
|
||||||
|
self.network['bssid'])
|
||||||
|
)
|
||||||
self.run_script_if_needed(self.after_script, 'post-connection',
|
self.run_script_if_needed(self.after_script, 'post-connection',
|
||||||
self.network['bssid'], self.network['essid'])
|
self.network['bssid'], self.network['essid'])
|
||||||
|
|
||||||
@@ -989,7 +1007,7 @@ class Wired(Controller):
|
|||||||
return self.connecting_thread
|
return self.connecting_thread
|
||||||
|
|
||||||
def Disconnect(self):
|
def Disconnect(self):
|
||||||
Controller.Disconnect(self, 'wired', 'wired')
|
Controller.Disconnect(self, 'wired', 'wired', 'wired')
|
||||||
|
|
||||||
def DetectWiredInterface(self):
|
def DetectWiredInterface(self):
|
||||||
""" Attempts to automatically detect a wired interface. """
|
""" Attempts to automatically detect a wired interface. """
|
||||||
@@ -1048,7 +1066,10 @@ class WiredConnectThread(ConnectThread):
|
|||||||
self.is_connecting = True
|
self.is_connecting = True
|
||||||
|
|
||||||
# Run pre-connection script.
|
# Run pre-connection script.
|
||||||
self.run_global_scripts_if_needed(wpath.preconnectscripts)
|
self.run_global_scripts_if_needed(wpath.preconnectscripts,
|
||||||
|
extra_parameters=('wired', 'wired',
|
||||||
|
self.network['profilename'])
|
||||||
|
)
|
||||||
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
|
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
|
||||||
'wired')
|
'wired')
|
||||||
|
|
||||||
@@ -1067,7 +1088,10 @@ class WiredConnectThread(ConnectThread):
|
|||||||
self.set_dns_addresses(liface)
|
self.set_dns_addresses(liface)
|
||||||
|
|
||||||
# Run post-connection script.
|
# Run post-connection script.
|
||||||
self.run_global_scripts_if_needed(wpath.postconnectscripts)
|
self.run_global_scripts_if_needed(wpath.postconnectscripts,
|
||||||
|
extra_parameters=('wired', 'wired',
|
||||||
|
self.network['profilename'])
|
||||||
|
)
|
||||||
self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
|
self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
|
||||||
'wired')
|
'wired')
|
||||||
|
|
||||||
|
|||||||
@@ -1536,6 +1536,7 @@ class WiredDaemon(dbus.service.Object):
|
|||||||
profile[x] = misc.Noneify(self.config.get(profilename, x))
|
profile[x] = misc.Noneify(self.config.get(profilename, x))
|
||||||
profile['use_global_dns'] = bool(profile.get('use_global_dns'))
|
profile['use_global_dns'] = bool(profile.get('use_global_dns'))
|
||||||
profile['use_static_dns'] = bool(profile.get('use_static_dns'))
|
profile['use_static_dns'] = bool(profile.get('use_static_dns'))
|
||||||
|
profile['profilename'] = profilename
|
||||||
self.WiredNetwork = profile
|
self.WiredNetwork = profile
|
||||||
self._cur_wired_prof_name = profilename
|
self._cur_wired_prof_name = profilename
|
||||||
return "100: Loaded Profile"
|
return "100: Loaded Profile"
|
||||||
|
|||||||
Reference in New Issue
Block a user