Merge lp:~oreilldf/wicd/global-scripts into lp:wicd/1.6
- global-scripts
- Merge into experimental
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Adam Blackburn | Approve | ||
Robby Workman (community) | Approve | ||
Review via email: mp+4039@code.launchpad.net |
Commit message
Description of the change
Dan O'Reilly (oreilldf) wrote : | # |
Robby Workman (rworkman) wrote : | # |
Untested here, but the logic and such looks correct.
Adam Blackburn (adamblackburn) wrote : | # |
Looks fine.
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/
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/
- 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
1 | === modified file 'in/wicd=wpath.py.in' | |||
2 | --- in/wicd=wpath.py.in 2009-01-24 03:13:27 +0000 | |||
3 | +++ in/wicd=wpath.py.in 2009-02-27 05:40:19 +0000 | |||
4 | @@ -26,6 +26,10 @@ | |||
5 | 26 | lib = '%LIB%' | 26 | lib = '%LIB%' |
6 | 27 | share = '%SHARE%' | 27 | share = '%SHARE%' |
7 | 28 | etc = '%ETC%' | 28 | etc = '%ETC%' |
8 | 29 | scripts = '%SCRIPTS%' | ||
9 | 30 | disconnectscripts = '%DISCONNECTSCRIPTS%' | ||
10 | 31 | preconnectscripts = '%PRECONNECTSCRIPTS%' | ||
11 | 32 | postconnectscripts = '%POSTCONNECTSCRIPTS%' | ||
12 | 29 | images = '%IMAGES%' | 33 | images = '%IMAGES%' |
13 | 30 | encryption = '%ENCRYPTION%' | 34 | encryption = '%ENCRYPTION%' |
14 | 31 | bin = '%BIN%' | 35 | bin = '%BIN%' |
15 | 32 | 36 | ||
16 | === modified file 'setup.py' | |||
17 | --- setup.py 2009-02-21 06:37:38 +0000 | |||
18 | +++ setup.py 2009-02-27 05:40:19 +0000 | |||
19 | @@ -51,6 +51,10 @@ | |||
20 | 51 | ('lib=', None, 'set the lib directory'), | 51 | ('lib=', None, 'set the lib directory'), |
21 | 52 | ('share=', None, 'set the share directory'), | 52 | ('share=', None, 'set the share directory'), |
22 | 53 | ('etc=', None, 'set the etc directory'), | 53 | ('etc=', None, 'set the etc directory'), |
23 | 54 | ('scripts=', None, 'set the global scripts directory'), | ||
24 | 55 | ('disconnectscripts=', None, 'set the global disconnect scripts directory'), | ||
25 | 56 | ('preconnectscripts=', None, 'set the global preconnect scripts directory'), | ||
26 | 57 | ('postconnectscripts=', None, 'set the global postconnect scripts directory'), | ||
27 | 54 | ('images=', None, 'set the image directory'), | 58 | ('images=', None, 'set the image directory'), |
28 | 55 | ('encryption=', None, 'set the encryption template directory'), | 59 | ('encryption=', None, 'set the encryption template directory'), |
29 | 56 | ('bin=', None, 'set the bin directory'), | 60 | ('bin=', None, 'set the bin directory'), |
30 | @@ -96,6 +100,10 @@ | |||
31 | 96 | self.lib = '/usr/lib/wicd/' | 100 | self.lib = '/usr/lib/wicd/' |
32 | 97 | self.share = '/usr/share/wicd/' | 101 | self.share = '/usr/share/wicd/' |
33 | 98 | self.etc = '/etc/wicd/' | 102 | self.etc = '/etc/wicd/' |
34 | 103 | self.scripts = self.etc + "scripts/" | ||
35 | 104 | self.preconnectscripts = self.scripts + "preconnect/" | ||
36 | 105 | self.postconnectscripts = self.scripts + "postconnect/" | ||
37 | 106 | self.disconnectscripts = self.scripts + "disconnect/" | ||
38 | 99 | self.icons = '/usr/share/icons/hicolor/' | 107 | self.icons = '/usr/share/icons/hicolor/' |
39 | 100 | self.images = '/usr/share/pixmaps/wicd/' | 108 | self.images = '/usr/share/pixmaps/wicd/' |
40 | 101 | self.encryption = self.etc + 'encryption/templates/' | 109 | self.encryption = self.etc + 'encryption/templates/' |
41 | @@ -175,10 +183,12 @@ | |||
42 | 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, |
43 | 176 | # or the path is not a proper absolute path, raise an error | 184 | # or the path is not a proper absolute path, raise an error |
44 | 177 | try: | 185 | try: |
46 | 178 | pmtemp = subprocess.Popen(["pkg-config","--variable=pm_sleephooks","pm-utils"], stdout=subprocess.PIPE) | 186 | pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks", |
47 | 187 | "pm-utils"], stdout=subprocess.PIPE) | ||
48 | 179 | returncode = pmtemp.wait() # let it finish, and get the exit code | 188 | returncode = pmtemp.wait() # let it finish, and get the exit code |
49 | 180 | pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout | 189 | pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout |
51 | 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 \ |
52 | 191 | not os.path.isabs(pmutils_candidate): | ||
53 | 182 | raise ValueError | 192 | raise ValueError |
54 | 183 | else: | 193 | else: |
55 | 184 | self.pmutils = pmutils_candidate | 194 | self.pmutils = pmutils_candidate |
56 | @@ -189,7 +199,8 @@ | |||
57 | 189 | kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE) | 199 | kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE) |
58 | 190 | returncode = kdetemp.wait() # let it finish, and get the exit code | 200 | returncode = kdetemp.wait() # let it finish, and get the exit code |
59 | 191 | kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout | 201 | kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout |
61 | 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 \ |
62 | 203 | not os.path.isabs(kdedir_candidate): | ||
63 | 193 | raise ValueError | 204 | raise ValueError |
64 | 194 | else: | 205 | else: |
65 | 195 | self.kdedir = kdedir_candidate + '/share/autostart' | 206 | self.kdedir = kdedir_candidate + '/share/autostart' |
66 | @@ -218,11 +229,10 @@ | |||
67 | 218 | 229 | ||
68 | 219 | 230 | ||
69 | 220 | def finalize_options(self): | 231 | def finalize_options(self): |
75 | 221 | if self.distro_detect_failed == True: | 232 | if self.distro_detect_failed and not self.no_install_init and \ |
76 | 222 | if not self.no_install_init: | 233 | 'FAIL' in [self.init, self.initfile]: |
77 | 223 | if self.init == 'FAIL' or self.initfile == 'FAIL': | 234 | print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ |
78 | 224 | print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ | 235 | 'Please specify --init and --initfile to continue with configuration.' |
74 | 225 | 'Please specify --init and --initfile to continue with configuration.' | ||
79 | 226 | 236 | ||
80 | 227 | 237 | ||
81 | 228 | # loop through the argument definitions in user_options | 238 | # loop through the argument definitions in user_options |
82 | @@ -408,6 +418,10 @@ | |||
83 | 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', |
84 | 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']), |
85 | 410 | (wpath.autostart, ['other/wicd-tray.desktop', ]), | 420 | (wpath.autostart, ['other/wicd-tray.desktop', ]), |
86 | 421 | (wpath.scripts, []), | ||
87 | 422 | (wpath.disconnectscripts, []), | ||
88 | 423 | (wpath.preconnectscripts, []), | ||
89 | 424 | (wpath.postconnectscripts, []), | ||
90 | 411 | ] | 425 | ] |
91 | 412 | if not wpath.no_install_ncurses: | 426 | if not wpath.no_install_ncurses: |
92 | 413 | data.append(( wpath.lib, ['curses/curses_misc.py'])) | 427 | data.append(( wpath.lib, ['curses/curses_misc.py'])) |
93 | @@ -456,14 +470,16 @@ | |||
94 | 456 | python setup.py configure has not yet been run.''' | 470 | python setup.py configure has not yet been run.''' |
95 | 457 | 471 | ||
96 | 458 | 472 | ||
99 | 459 | wpactrl_ext = Extension(name = 'wpactrl', sources = ['depends/python-wpactrl/wpa_ctrl.c', 'depends/python-wpactrl/wpactrl.c'], | 473 | wpactrl_ext = Extension(name = 'wpactrl', |
100 | 460 | extra_compile_args = ["-fno-strict-aliasing"]) | 474 | sources = ['depends/python-wpactrl/wpa_ctrl.c', |
101 | 475 | 'depends/python-wpactrl/wpactrl.c'], | ||
102 | 476 | extra_compile_args = ["-fno-strict-aliasing"]) | ||
103 | 461 | 477 | ||
107 | 462 | iwscan_ext = Extension(name = 'iwscan', | 478 | iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'], |
108 | 463 | libraries = ['iw'], | 479 | sources = ['depends/python-iwscan/pyiwscan.c']) |
106 | 464 | sources = ['depends/python-iwscan/pyiwscan.c']) | ||
109 | 465 | 480 | ||
111 | 466 | setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, | 481 | setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, |
112 | 482 | 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, | ||
113 | 467 | name="Wicd", | 483 | name="Wicd", |
114 | 468 | version=VERSION_NUM, | 484 | version=VERSION_NUM, |
115 | 469 | description="A wireless and wired network manager", | 485 | description="A wireless and wired network manager", |
116 | @@ -476,16 +492,12 @@ | |||
117 | 476 | connect at startup to any preferred network within range. | 492 | connect at startup to any preferred network within range. |
118 | 477 | """, | 493 | """, |
119 | 478 | author="Adam Blackburn, Dan O'Reilly", | 494 | author="Adam Blackburn, Dan O'Reilly", |
121 | 479 | author_email="compwiz18@users.sourceforge.net, imdano@users.sourceforge.net", | 495 | author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com", |
122 | 480 | url="http://wicd.net", | 496 | url="http://wicd.net", |
123 | 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", |
128 | 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', |
129 | 483 | py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', | 499 | 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', |
130 | 484 | 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', | 500 | 'wicd.logfile', 'wicd.backend', 'wicd.configmanager', 'wicd.guiutil'], |
127 | 485 | 'wicd.configmanager', 'wicd.guiutil'], | ||
131 | 486 | ext_modules=[iwscan_ext, wpactrl_ext], | 501 | ext_modules=[iwscan_ext, wpactrl_ext], |
132 | 487 | data_files=data | 502 | data_files=data |
133 | 488 | ) | 503 | ) |
134 | 489 | ##print "Running post-install configuration..." | ||
135 | 490 | ##os.system("other/postinst") | ||
136 | 491 | ##print 'Done.' | ||
137 | 492 | 504 | ||
138 | === modified file 'wicd/misc.py' | |||
139 | --- wicd/misc.py 2009-02-27 05:08:31 +0000 | |||
140 | +++ wicd/misc.py 2009-02-28 20:16:45 +0000 | |||
141 | @@ -58,7 +58,7 @@ | |||
142 | 58 | GKSUDO = 1 | 58 | GKSUDO = 1 |
143 | 59 | KDESU = 2 | 59 | KDESU = 2 |
144 | 60 | KTSUSS = 3 | 60 | KTSUSS = 3 |
146 | 61 | __sudo_dict = { | 61 | _sudo_dict = { |
147 | 62 | AUTO : "", | 62 | AUTO : "", |
148 | 63 | GKSUDO : "gksudo", | 63 | GKSUDO : "gksudo", |
149 | 64 | KDESU : "kdesu", | 64 | KDESU : "kdesu", |
150 | @@ -172,9 +172,20 @@ | |||
151 | 172 | """ write a line to a file """ | 172 | """ write a line to a file """ |
152 | 173 | my_file.write(text + "\n") | 173 | my_file.write(text + "\n") |
153 | 174 | 174 | ||
155 | 175 | def ExecuteScript(script): | 175 | def ExecuteScripts(scripts_dir, verbose=False): |
156 | 176 | """ Execute every executable file in a given directory. """ | ||
157 | 177 | for obj in os.listdir(scripts_dir): | ||
158 | 178 | obj = os.path.abspath(os.path.join(scripts_dir, obj)) | ||
159 | 179 | if os.path.isfile(obj) and os.access(obj, os.X_OK): | ||
160 | 180 | ExecuteScript(os.path.abspath(obj), verbose=verbose) | ||
161 | 181 | |||
162 | 182 | def ExecuteScript(script, verbose=False): | ||
163 | 176 | """ Execute a command and send its output to the bit bucket. """ | 183 | """ Execute a command and send its output to the bit bucket. """ |
165 | 177 | call("%s > /dev/null 2>&1" % script, shell=True) | 184 | if verbose: |
166 | 185 | print "Executing %s" % script | ||
167 | 186 | ret = call("%s > /dev/null 2>&1" % script, shell=True) | ||
168 | 187 | if verbose: | ||
169 | 188 | "%s returned %s" % (script, ret) | ||
170 | 178 | 189 | ||
171 | 179 | def ReadFile(filename): | 190 | def ReadFile(filename): |
172 | 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 """ |
173 | @@ -427,7 +438,7 @@ | |||
174 | 427 | def choose_sudo_prog(prog_num=0): | 438 | def choose_sudo_prog(prog_num=0): |
175 | 428 | """ Try to intelligently decide which graphical sudo program to use. """ | 439 | """ Try to intelligently decide which graphical sudo program to use. """ |
176 | 429 | if prog_num: | 440 | if prog_num: |
178 | 430 | return find_path(__sudo_dict[prog_num]) | 441 | return find_path(_sudo_dict[prog_num]) |
179 | 431 | desktop_env = detect_desktop_environment() | 442 | desktop_env = detect_desktop_environment() |
180 | 432 | env_path = os.environ['PATH'].split(":") | 443 | env_path = os.environ['PATH'].split(":") |
181 | 433 | paths = [] | 444 | paths = [] |
182 | 434 | 445 | ||
183 | === modified file 'wicd/networking.py' | |||
184 | --- wicd/networking.py 2009-02-27 05:35:53 +0000 | |||
185 | +++ wicd/networking.py 2009-02-28 20:16:45 +0000 | |||
186 | @@ -202,10 +202,12 @@ | |||
187 | 202 | def Disconnect(self, *args, **kargs): | 202 | def Disconnect(self, *args, **kargs): |
188 | 203 | """ Disconnect from the network. """ | 203 | """ Disconnect from the network. """ |
189 | 204 | iface = self.iface | 204 | iface = self.iface |
191 | 205 | if self.disconnect_script != None: | 205 | misc.ExecuteScripts(wpath.disconnectscripts, self.debug) |
192 | 206 | if self.disconnect_script: | ||
193 | 206 | print 'Running disconnect script' | 207 | print 'Running disconnect script' |
194 | 207 | misc.ExecuteScript(expand_script_macros(self.disconnect_script, | 208 | misc.ExecuteScript(expand_script_macros(self.disconnect_script, |
196 | 208 | 'disconnection', *args)) | 209 | 'disconnection', *args), |
197 | 210 | self.debug) | ||
198 | 209 | iface.ReleaseDHCP() | 211 | iface.ReleaseDHCP() |
199 | 210 | iface.SetAddress('0.0.0.0') | 212 | iface.SetAddress('0.0.0.0') |
200 | 211 | iface.FlushRoutes() | 213 | iface.FlushRoutes() |
201 | @@ -369,6 +371,10 @@ | |||
202 | 369 | iface.Down() | 371 | iface.Down() |
203 | 370 | 372 | ||
204 | 371 | @abortable | 373 | @abortable |
205 | 374 | def run_global_scripts_if_needed(self, script_dir): | ||
206 | 375 | misc.ExecuteScripts(script_dir, verbose=self.debug) | ||
207 | 376 | |||
208 | 377 | @abortable | ||
209 | 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'): |
210 | 373 | """ Execute a given script if needed. | 379 | """ Execute a given script if needed. |
211 | 374 | 380 | ||
212 | @@ -379,7 +385,8 @@ | |||
213 | 379 | """ | 385 | """ |
214 | 380 | if script: | 386 | if script: |
215 | 381 | print 'Executing %s script' % (msg) | 387 | print 'Executing %s script' % (msg) |
217 | 382 | misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid)) | 388 | misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid), |
218 | 389 | self.debug) | ||
219 | 383 | 390 | ||
220 | 384 | @abortable | 391 | @abortable |
221 | 385 | def flush_routes(self, iface): | 392 | def flush_routes(self, iface): |
222 | @@ -761,6 +768,7 @@ | |||
223 | 761 | self.is_connecting = True | 768 | self.is_connecting = True |
224 | 762 | 769 | ||
225 | 763 | # Run pre-connection script. | 770 | # Run pre-connection script. |
226 | 771 | self.run_global_scripts_if_needed(wpath.preconnectscripts) | ||
227 | 764 | self.run_script_if_needed(self.before_script, 'pre-connection', | 772 | self.run_script_if_needed(self.before_script, 'pre-connection', |
228 | 765 | self.network['bssid'], self.network['essid']) | 773 | self.network['bssid'], self.network['essid']) |
229 | 766 | 774 | ||
230 | @@ -803,6 +811,7 @@ | |||
231 | 803 | self.set_dns_addresses() | 811 | self.set_dns_addresses() |
232 | 804 | 812 | ||
233 | 805 | # Run post-connection script. | 813 | # Run post-connection script. |
234 | 814 | self.run_global_scripts_if_needed(wpath.postconnectscripts) | ||
235 | 806 | self.run_script_if_needed(self.after_script, 'post-connection', | 815 | self.run_script_if_needed(self.after_script, 'post-connection', |
236 | 807 | self.network['bssid'], self.network['essid']) | 816 | self.network['bssid'], self.network['essid']) |
237 | 808 | 817 | ||
238 | @@ -971,6 +980,7 @@ | |||
239 | 971 | self.is_connecting = True | 980 | self.is_connecting = True |
240 | 972 | 981 | ||
241 | 973 | # Run pre-connection script. | 982 | # Run pre-connection script. |
242 | 983 | self.run_global_scripts_if_needed(wpath.preconnectscripts) | ||
243 | 974 | self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', | 984 | self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', |
244 | 975 | 'wired') | 985 | 'wired') |
245 | 976 | 986 | ||
246 | @@ -989,6 +999,7 @@ | |||
247 | 989 | self.set_dns_addresses() | 999 | self.set_dns_addresses() |
248 | 990 | 1000 | ||
249 | 991 | # Run post-connection script. | 1001 | # Run post-connection script. |
250 | 1002 | self.run_global_scripts_if_needed(wpath.postconnectscripts) | ||
251 | 992 | self.run_script_if_needed(self.after_script, 'post-connection', 'wired', | 1003 | self.run_script_if_needed(self.after_script, 'post-connection', 'wired', |
252 | 993 | 'wired') | 1004 | 'wired') |
253 | 994 | 1005 |
Adds global script directories to /etc/wicd.