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

Initial crack at global scripts support. Also includes some setup.py tweaks.

This commit is contained in:
Dan O'Reilly
2009-02-27 00:40:19 -05:00
parent a23fbcede5
commit e40afce104
3 changed files with 52 additions and 25 deletions

View File

@@ -26,6 +26,10 @@ curses_revision = '%CURSES_REVNO%'
lib = '%LIB%' lib = '%LIB%'
share = '%SHARE%' share = '%SHARE%'
etc = '%ETC%' etc = '%ETC%'
scripts = '%SCRIPTS%'
disconnectscripts = '%DISCONNECTSCRIPTS%'
preconnectscripts = '%PRECONNECTSCRIPTS%'
postconnectscripts = '%POSTCONNECTSCRIPTS%'
images = '%IMAGES%' images = '%IMAGES%'
encryption = '%ENCRYPTION%' encryption = '%ENCRYPTION%'
bin = '%BIN%' bin = '%BIN%'

View File

@@ -51,6 +51,10 @@ class configure(Command):
('lib=', None, 'set the lib directory'), ('lib=', None, 'set the lib directory'),
('share=', None, 'set the share directory'), ('share=', None, 'set the share directory'),
('etc=', None, 'set the etc directory'), ('etc=', None, 'set the etc directory'),
('scripts=', None, 'set the global scripts directory'),
('disconnectscripts=', None, 'set the global disconnect scripts directory'),
('preconnectscripts=', None, 'set the global preconnect scripts directory'),
('postconnectscripts=', None, 'set the global postconnect scripts directory'),
('images=', None, 'set the image directory'), ('images=', None, 'set the image directory'),
('encryption=', None, 'set the encryption template directory'), ('encryption=', None, 'set the encryption template directory'),
('bin=', None, 'set the bin directory'), ('bin=', None, 'set the bin directory'),
@@ -96,6 +100,10 @@ class configure(Command):
self.lib = '/usr/lib/wicd/' self.lib = '/usr/lib/wicd/'
self.share = '/usr/share/wicd/' self.share = '/usr/share/wicd/'
self.etc = '/etc/wicd/' self.etc = '/etc/wicd/'
self.scripts = self.etc + "scripts/"
self.preconnectscripts = self.scripts + "preconnect/"
self.postconnectscripts = self.scripts + "postconnect/"
self.disconnectscripts = self.scripts + "disconnect/"
self.icons = '/usr/share/icons/hicolor/' self.icons = '/usr/share/icons/hicolor/'
self.images = '/usr/share/pixmaps/wicd/' self.images = '/usr/share/pixmaps/wicd/'
self.encryption = self.etc + 'encryption/templates/' self.encryption = self.etc + 'encryption/templates/'
@@ -175,10 +183,12 @@ class configure(Command):
# If we don't get anything from *-config, or it didn't run properly, # If we don't get anything from *-config, or it didn't run properly,
# or the path is not a proper absolute path, raise an error # or the path is not a proper absolute path, raise an error
try: try:
pmtemp = subprocess.Popen(["pkg-config","--variable=pm_sleephooks","pm-utils"], stdout=subprocess.PIPE) pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks",
"pm-utils"], stdout=subprocess.PIPE)
returncode = pmtemp.wait() # let it finish, and get the exit code returncode = pmtemp.wait() # let it finish, and get the exit code
pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout
if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate): if len(pmutils_candidate) == 0 or returncode != 0 or \
not os.path.isabs(pmutils_candidate):
raise ValueError raise ValueError
else: else:
self.pmutils = pmutils_candidate self.pmutils = pmutils_candidate
@@ -189,7 +199,8 @@ class configure(Command):
kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE) kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE)
returncode = kdetemp.wait() # let it finish, and get the exit code returncode = kdetemp.wait() # let it finish, and get the exit code
kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout
if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate): if len(kdedir_candidate) == 0 or returncode != 0 or \
not os.path.isabs(kdedir_candidate):
raise ValueError raise ValueError
else: else:
self.kdedir = kdedir_candidate + '/share/autostart' self.kdedir = kdedir_candidate + '/share/autostart'
@@ -218,9 +229,8 @@ class configure(Command):
def finalize_options(self): def finalize_options(self):
if self.distro_detect_failed == True: if self.distro_detect_failed and not self.no_install_init and \
if not self.no_install_init: 'FAIL' in [self.init, self.initfile]:
if self.init == 'FAIL' or self.initfile == 'FAIL':
print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \
'Please specify --init and --initfile to continue with configuration.' 'Please specify --init and --initfile to continue with configuration.'
@@ -408,6 +418,10 @@ try:
(wpath.lib, ['wicd/wicd-client.py', 'wicd/monitor.py', 'wicd/wicd-daemon.py', 'wicd/configscript.py', 'wicd/suspend.py', 'wicd/autoconnect.py']), #'wicd/wicd-gui.py', (wpath.lib, ['wicd/wicd-client.py', 'wicd/monitor.py', 'wicd/wicd-daemon.py', 'wicd/configscript.py', 'wicd/suspend.py', 'wicd/autoconnect.py']), #'wicd/wicd-gui.py',
(wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']), (wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']),
(wpath.autostart, ['other/wicd-tray.desktop', ]), (wpath.autostart, ['other/wicd-tray.desktop', ]),
(wpath.scripts, []),
(wpath.disconnectscripts, []),
(wpath.preconnectscripts, []),
(wpath.postconnectscripts, []),
] ]
if not wpath.no_install_ncurses: if not wpath.no_install_ncurses:
data.append(( wpath.lib, ['curses/curses_misc.py'])) data.append(( wpath.lib, ['curses/curses_misc.py']))
@@ -456,14 +470,16 @@ except Exception, e:
python setup.py configure has not yet been run.''' python setup.py configure has not yet been run.'''
wpactrl_ext = Extension(name = 'wpactrl', sources = ['depends/python-wpactrl/wpa_ctrl.c', 'depends/python-wpactrl/wpactrl.c'], wpactrl_ext = Extension(name = 'wpactrl',
sources = ['depends/python-wpactrl/wpa_ctrl.c',
'depends/python-wpactrl/wpactrl.c'],
extra_compile_args = ["-fno-strict-aliasing"]) extra_compile_args = ["-fno-strict-aliasing"])
iwscan_ext = Extension(name = 'iwscan', iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'],
libraries = ['iw'],
sources = ['depends/python-iwscan/pyiwscan.c']) sources = ['depends/python-iwscan/pyiwscan.c'])
setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, setup(cmdclass={'configure' : configure, 'get_translations' : get_translations,
'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated},
name="Wicd", name="Wicd",
version=VERSION_NUM, version=VERSION_NUM,
description="A wireless and wired network manager", description="A wireless and wired network manager",
@@ -476,16 +492,12 @@ encryption types, such as WPA and WEP. Wicd will automatically
connect at startup to any preferred network within range. connect at startup to any preferred network within range.
""", """,
author="Adam Blackburn, Dan O'Reilly", author="Adam Blackburn, Dan O'Reilly",
author_email="compwiz18@users.sourceforge.net, imdano@users.sourceforge.net", author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com",
url="http://wicd.net", url="http://wicd.net",
license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'], py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools',
py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager',
'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', 'wicd.logfile', 'wicd.backend', 'wicd.configmanager', 'wicd.guiutil'],
'wicd.configmanager', 'wicd.guiutil'],
ext_modules=[iwscan_ext, wpactrl_ext], ext_modules=[iwscan_ext, wpactrl_ext],
data_files=data data_files=data
) )
##print "Running post-install configuration..."
##os.system("other/postinst")
##print 'Done.'

View File

@@ -202,10 +202,12 @@ class Controller(object):
def Disconnect(self, *args, **kargs): def Disconnect(self, *args, **kargs):
""" Disconnect from the network. """ """ Disconnect from the network. """
iface = self.iface iface = self.iface
if self.disconnect_script != None: misc.ExecuteScripts(wpath.disconnectscripts, self.debug)
if self.disconnect_script:
print 'Running disconnect script' print 'Running disconnect script'
misc.ExecuteScript(expand_script_macros(self.disconnect_script, misc.ExecuteScript(expand_script_macros(self.disconnect_script,
'disconnection', *args)) 'disconnection', *args),
self.debug)
iface.ReleaseDHCP() iface.ReleaseDHCP()
iface.SetAddress('0.0.0.0') iface.SetAddress('0.0.0.0')
iface.FlushRoutes() iface.FlushRoutes()
@@ -368,6 +370,10 @@ class ConnectThread(threading.Thread):
self.SetStatus('interface_down') self.SetStatus('interface_down')
iface.Down() iface.Down()
@abortable
def run_global_scripts_if_needed(self, script_dir):
misc.ExecuteScripts(script_dir, verbose=self.debug)
@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'):
""" Execute a given script if needed. """ Execute a given script if needed.
@@ -379,7 +385,8 @@ class ConnectThread(threading.Thread):
""" """
if script: if script:
print 'Executing %s script' % (msg) print 'Executing %s script' % (msg)
misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid)) misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid),
self.debug)
@abortable @abortable
def flush_routes(self, iface): def flush_routes(self, iface):
@@ -761,6 +768,7 @@ 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_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'])
@@ -803,6 +811,7 @@ class WirelessConnectThread(ConnectThread):
self.set_dns_addresses() self.set_dns_addresses()
# Run post-connection script. # Run post-connection script.
self.run_global_scripts_if_needed(wpath.postconnectscripts)
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'])
@@ -971,6 +980,7 @@ 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_script_if_needed(self.before_script, 'pre-connection', 'wired', self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
'wired') 'wired')
@@ -989,6 +999,7 @@ class WiredConnectThread(ConnectThread):
self.set_dns_addresses() self.set_dns_addresses()
# Run post-connection script. # Run post-connection script.
self.run_global_scripts_if_needed(wpath.postconnectscripts)
self.run_script_if_needed(self.after_script, 'post-connection', 'wired', self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
'wired') 'wired')