Merge lp:~oreilldf/wicd/global-scripts into lp:wicd/1.6

Proposed by Dan O'Reilly
Status: Merged
Approved by: Adam Blackburn
Approved revision: 302
Merged at revision: not available
Proposed branch: lp:~oreilldf/wicd/global-scripts
Merge into: lp:wicd/1.6
Diff against target: None lines
To merge this branch: bzr merge lp:~oreilldf/wicd/global-scripts
Reviewer Review Type Date Requested Status
Adam Blackburn Approve
Robby Workman (community) Approve
Review via email: mp+4039@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dan O'Reilly (oreilldf) wrote :

Adds global script directories to /etc/wicd.

Revision history for this message
Robby Workman (rworkman) wrote :

Untested here, but the logic and such looks correct.

review: Approve
Revision history for this message
Adam Blackburn (adamblackburn) wrote :

Looks fine.

review: Approve
Revision history for this message
Robby Workman (rworkman) wrote :

After testing with the changes, everything seems to work correctly (I just wrote some dummy scripts to echo into a logfile).

For the UI, I wonder if prepending the full path to the scripts directory would be workable; in other words, all the user would type is the actual *name* of the script (e.g. "whatever.sh" instead of "/etc/wicd/scripts/postconnect/whatever.sh")

Revision history for this message
Dan O'Reilly (oreilldf) wrote :

"For the UI, I wonder if prepending the full path to the scripts directory would be workable; in other words, all the user would type is the actual *name* of the script (e.g. "whatever.sh" instead of "/etc/wicd/scripts/postconnect/whatever.sh")"I wasn't planning on having a UI component at all. Any executable file in the script directory gets executed at the appropriate time.

lp:~oreilldf/wicd/global-scripts updated
303. By Dan O'Reilly

Merge.

304. By Dan O'Reilly

Don't provide separate options for pre/post/disconnect scripts. Just a parent scripts directory.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'in/wicd=wpath.py.in'
--- in/wicd=wpath.py.in 2009-01-24 03:13:27 +0000
+++ in/wicd=wpath.py.in 2009-02-27 05:40:19 +0000
@@ -26,6 +26,10 @@
26lib = '%LIB%'26lib = '%LIB%'
27share = '%SHARE%'27share = '%SHARE%'
28etc = '%ETC%'28etc = '%ETC%'
29scripts = '%SCRIPTS%'
30disconnectscripts = '%DISCONNECTSCRIPTS%'
31preconnectscripts = '%PRECONNECTSCRIPTS%'
32postconnectscripts = '%POSTCONNECTSCRIPTS%'
29images = '%IMAGES%'33images = '%IMAGES%'
30encryption = '%ENCRYPTION%'34encryption = '%ENCRYPTION%'
31bin = '%BIN%'35bin = '%BIN%'
3236
=== modified file 'setup.py'
--- setup.py 2009-02-21 06:37:38 +0000
+++ setup.py 2009-02-27 05:40:19 +0000
@@ -51,6 +51,10 @@
51 ('lib=', None, 'set the lib directory'),51 ('lib=', None, 'set the lib directory'),
52 ('share=', None, 'set the share directory'),52 ('share=', None, 'set the share directory'),
53 ('etc=', None, 'set the etc directory'),53 ('etc=', None, 'set the etc directory'),
54 ('scripts=', None, 'set the global scripts directory'),
55 ('disconnectscripts=', None, 'set the global disconnect scripts directory'),
56 ('preconnectscripts=', None, 'set the global preconnect scripts directory'),
57 ('postconnectscripts=', None, 'set the global postconnect scripts directory'),
54 ('images=', None, 'set the image directory'),58 ('images=', None, 'set the image directory'),
55 ('encryption=', None, 'set the encryption template directory'),59 ('encryption=', None, 'set the encryption template directory'),
56 ('bin=', None, 'set the bin directory'),60 ('bin=', None, 'set the bin directory'),
@@ -96,6 +100,10 @@
96 self.lib = '/usr/lib/wicd/'100 self.lib = '/usr/lib/wicd/'
97 self.share = '/usr/share/wicd/'101 self.share = '/usr/share/wicd/'
98 self.etc = '/etc/wicd/'102 self.etc = '/etc/wicd/'
103 self.scripts = self.etc + "scripts/"
104 self.preconnectscripts = self.scripts + "preconnect/"
105 self.postconnectscripts = self.scripts + "postconnect/"
106 self.disconnectscripts = self.scripts + "disconnect/"
99 self.icons = '/usr/share/icons/hicolor/'107 self.icons = '/usr/share/icons/hicolor/'
100 self.images = '/usr/share/pixmaps/wicd/'108 self.images = '/usr/share/pixmaps/wicd/'
101 self.encryption = self.etc + 'encryption/templates/'109 self.encryption = self.etc + 'encryption/templates/'
@@ -175,10 +183,12 @@
175 # If we don't get anything from *-config, or it didn't run properly, 183 # If we don't get anything from *-config, or it didn't run properly,
176 # or the path is not a proper absolute path, raise an error184 # or the path is not a proper absolute path, raise an error
177 try:185 try:
178 pmtemp = subprocess.Popen(["pkg-config","--variable=pm_sleephooks","pm-utils"], stdout=subprocess.PIPE)186 pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks",
187 "pm-utils"], stdout=subprocess.PIPE)
179 returncode = pmtemp.wait() # let it finish, and get the exit code188 returncode = pmtemp.wait() # let it finish, and get the exit code
180 pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout189 pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout
181 if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate):190 if len(pmutils_candidate) == 0 or returncode != 0 or \
191 not os.path.isabs(pmutils_candidate):
182 raise ValueError192 raise ValueError
183 else:193 else:
184 self.pmutils = pmutils_candidate194 self.pmutils = pmutils_candidate
@@ -189,7 +199,8 @@
189 kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE)199 kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE)
190 returncode = kdetemp.wait() # let it finish, and get the exit code200 returncode = kdetemp.wait() # let it finish, and get the exit code
191 kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout201 kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout
192 if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate):202 if len(kdedir_candidate) == 0 or returncode != 0 or \
203 not os.path.isabs(kdedir_candidate):
193 raise ValueError204 raise ValueError
194 else:205 else:
195 self.kdedir = kdedir_candidate + '/share/autostart'206 self.kdedir = kdedir_candidate + '/share/autostart'
@@ -218,11 +229,10 @@
218229
219230
220 def finalize_options(self):231 def finalize_options(self):
221 if self.distro_detect_failed == True:232 if self.distro_detect_failed and not self.no_install_init and \
222 if not self.no_install_init:233 'FAIL' in [self.init, self.initfile]:
223 if self.init == 'FAIL' or self.initfile == 'FAIL':234 print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \
224 print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \235 'Please specify --init and --initfile to continue with configuration.'
225 'Please specify --init and --initfile to continue with configuration.'
226 236
227 237
228 # loop through the argument definitions in user_options238 # loop through the argument definitions in user_options
@@ -408,6 +418,10 @@
408 (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', 418 (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',
409 (wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']),419 (wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']),
410 (wpath.autostart, ['other/wicd-tray.desktop', ]),420 (wpath.autostart, ['other/wicd-tray.desktop', ]),
421 (wpath.scripts, []),
422 (wpath.disconnectscripts, []),
423 (wpath.preconnectscripts, []),
424 (wpath.postconnectscripts, []),
411 ]425 ]
412 if not wpath.no_install_ncurses:426 if not wpath.no_install_ncurses:
413 data.append(( wpath.lib, ['curses/curses_misc.py']))427 data.append(( wpath.lib, ['curses/curses_misc.py']))
@@ -456,14 +470,16 @@
456python setup.py configure has not yet been run.'''470python setup.py configure has not yet been run.'''
457471
458472
459wpactrl_ext = Extension(name = 'wpactrl', sources = ['depends/python-wpactrl/wpa_ctrl.c', 'depends/python-wpactrl/wpactrl.c'],473wpactrl_ext = Extension(name = 'wpactrl',
460 extra_compile_args = ["-fno-strict-aliasing"])474 sources = ['depends/python-wpactrl/wpa_ctrl.c',
475 'depends/python-wpactrl/wpactrl.c'],
476 extra_compile_args = ["-fno-strict-aliasing"])
461477
462iwscan_ext = Extension(name = 'iwscan',478iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'],
463 libraries = ['iw'],479 sources = ['depends/python-iwscan/pyiwscan.c'])
464 sources = ['depends/python-iwscan/pyiwscan.c'])
465 480
466setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated},481setup(cmdclass={'configure' : configure, 'get_translations' : get_translations,
482 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated},
467 name="Wicd",483 name="Wicd",
468 version=VERSION_NUM,484 version=VERSION_NUM,
469 description="A wireless and wired network manager",485 description="A wireless and wired network manager",
@@ -476,16 +492,12 @@
476connect at startup to any preferred network within range.492connect at startup to any preferred network within range.
477""",493""",
478 author="Adam Blackburn, Dan O'Reilly",494 author="Adam Blackburn, Dan O'Reilly",
479 author_email="compwiz18@users.sourceforge.net, imdano@users.sourceforge.net",495 author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com",
480 url="http://wicd.net",496 url="http://wicd.net",
481 license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",497 license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
482 ## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'],498 py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools',
483 py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', 499 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager',
484 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', 500 'wicd.logfile', 'wicd.backend', 'wicd.configmanager', 'wicd.guiutil'],
485 'wicd.configmanager', 'wicd.guiutil'],
486 ext_modules=[iwscan_ext, wpactrl_ext],501 ext_modules=[iwscan_ext, wpactrl_ext],
487 data_files=data502 data_files=data
488 )503 )
489##print "Running post-install configuration..."
490##os.system("other/postinst")
491##print 'Done.'
492504
=== modified file 'wicd/misc.py'
--- wicd/misc.py 2009-02-27 05:08:31 +0000
+++ wicd/misc.py 2009-02-28 20:16:45 +0000
@@ -58,7 +58,7 @@
58GKSUDO = 158GKSUDO = 1
59KDESU = 259KDESU = 2
60KTSUSS = 360KTSUSS = 3
61__sudo_dict = { 61_sudo_dict = {
62 AUTO : "",62 AUTO : "",
63 GKSUDO : "gksudo",63 GKSUDO : "gksudo",
64 KDESU : "kdesu",64 KDESU : "kdesu",
@@ -172,9 +172,20 @@
172 """ write a line to a file """172 """ write a line to a file """
173 my_file.write(text + "\n")173 my_file.write(text + "\n")
174174
175def ExecuteScript(script):175def ExecuteScripts(scripts_dir, verbose=False):
176 """ Execute every executable file in a given directory. """
177 for obj in os.listdir(scripts_dir):
178 obj = os.path.abspath(os.path.join(scripts_dir, obj))
179 if os.path.isfile(obj) and os.access(obj, os.X_OK):
180 ExecuteScript(os.path.abspath(obj), verbose=verbose)
181
182def ExecuteScript(script, verbose=False):
176 """ Execute a command and send its output to the bit bucket. """183 """ Execute a command and send its output to the bit bucket. """
177 call("%s > /dev/null 2>&1" % script, shell=True)184 if verbose:
185 print "Executing %s" % script
186 ret = call("%s > /dev/null 2>&1" % script, shell=True)
187 if verbose:
188 "%s returned %s" % (script, ret)
178189
179def ReadFile(filename):190def ReadFile(filename):
180 """ read in a file and return it's contents as a string """191 """ read in a file and return it's contents as a string """
@@ -427,7 +438,7 @@
427def choose_sudo_prog(prog_num=0):438def choose_sudo_prog(prog_num=0):
428 """ Try to intelligently decide which graphical sudo program to use. """439 """ Try to intelligently decide which graphical sudo program to use. """
429 if prog_num:440 if prog_num:
430 return find_path(__sudo_dict[prog_num])441 return find_path(_sudo_dict[prog_num])
431 desktop_env = detect_desktop_environment()442 desktop_env = detect_desktop_environment()
432 env_path = os.environ['PATH'].split(":")443 env_path = os.environ['PATH'].split(":")
433 paths = []444 paths = []
434445
=== modified file 'wicd/networking.py'
--- wicd/networking.py 2009-02-27 05:35:53 +0000
+++ wicd/networking.py 2009-02-28 20:16:45 +0000
@@ -202,10 +202,12 @@
202 def Disconnect(self, *args, **kargs):202 def Disconnect(self, *args, **kargs):
203 """ Disconnect from the network. """203 """ Disconnect from the network. """
204 iface = self.iface204 iface = self.iface
205 if self.disconnect_script != None:205 misc.ExecuteScripts(wpath.disconnectscripts, self.debug)
206 if self.disconnect_script:
206 print 'Running disconnect script'207 print 'Running disconnect script'
207 misc.ExecuteScript(expand_script_macros(self.disconnect_script,208 misc.ExecuteScript(expand_script_macros(self.disconnect_script,
208 'disconnection', *args))209 'disconnection', *args),
210 self.debug)
209 iface.ReleaseDHCP()211 iface.ReleaseDHCP()
210 iface.SetAddress('0.0.0.0')212 iface.SetAddress('0.0.0.0')
211 iface.FlushRoutes()213 iface.FlushRoutes()
@@ -369,6 +371,10 @@
369 iface.Down()371 iface.Down()
370 372
371 @abortable373 @abortable
374 def run_global_scripts_if_needed(self, script_dir):
375 misc.ExecuteScripts(script_dir, verbose=self.debug)
376
377 @abortable
372 def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):378 def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):
373 """ Execute a given script if needed.379 """ Execute a given script if needed.
374 380
@@ -379,7 +385,8 @@
379 """385 """
380 if script:386 if script:
381 print 'Executing %s script' % (msg)387 print 'Executing %s script' % (msg)
382 misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid))388 misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid),
389 self.debug)
383 390
384 @abortable391 @abortable
385 def flush_routes(self, iface):392 def flush_routes(self, iface):
@@ -761,6 +768,7 @@
761 self.is_connecting = True768 self.is_connecting = True
762 769
763 # Run pre-connection script.770 # Run pre-connection script.
771 self.run_global_scripts_if_needed(wpath.preconnectscripts)
764 self.run_script_if_needed(self.before_script, 'pre-connection', 772 self.run_script_if_needed(self.before_script, 'pre-connection',
765 self.network['bssid'], self.network['essid'])773 self.network['bssid'], self.network['essid'])
766774
@@ -803,6 +811,7 @@
803 self.set_dns_addresses()811 self.set_dns_addresses()
804 812
805 # Run post-connection script.813 # Run post-connection script.
814 self.run_global_scripts_if_needed(wpath.postconnectscripts)
806 self.run_script_if_needed(self.after_script, 'post-connection', 815 self.run_script_if_needed(self.after_script, 'post-connection',
807 self.network['bssid'], self.network['essid'])816 self.network['bssid'], self.network['essid'])
808817
@@ -971,6 +980,7 @@
971 self.is_connecting = True980 self.is_connecting = True
972981
973 # Run pre-connection script.982 # Run pre-connection script.
983 self.run_global_scripts_if_needed(wpath.preconnectscripts)
974 self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', 984 self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
975 'wired')985 'wired')
976986
@@ -989,6 +999,7 @@
989 self.set_dns_addresses()999 self.set_dns_addresses()
990 1000
991 # Run post-connection script.1001 # Run post-connection script.
1002 self.run_global_scripts_if_needed(wpath.postconnectscripts)
992 self.run_script_if_needed(self.after_script, 'post-connection', 'wired', 1003 self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
993 'wired')1004 'wired')
9941005

Subscribers

People subscribed via source and target branches

to status/vote changes: