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 | lib = '%LIB%' |
6 | share = '%SHARE%' |
7 | etc = '%ETC%' |
8 | +scripts = '%SCRIPTS%' |
9 | +disconnectscripts = '%DISCONNECTSCRIPTS%' |
10 | +preconnectscripts = '%PRECONNECTSCRIPTS%' |
11 | +postconnectscripts = '%POSTCONNECTSCRIPTS%' |
12 | images = '%IMAGES%' |
13 | encryption = '%ENCRYPTION%' |
14 | bin = '%BIN%' |
15 | |
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 | ('lib=', None, 'set the lib directory'), |
21 | ('share=', None, 'set the share directory'), |
22 | ('etc=', None, 'set the etc directory'), |
23 | + ('scripts=', None, 'set the global scripts directory'), |
24 | + ('disconnectscripts=', None, 'set the global disconnect scripts directory'), |
25 | + ('preconnectscripts=', None, 'set the global preconnect scripts directory'), |
26 | + ('postconnectscripts=', None, 'set the global postconnect scripts directory'), |
27 | ('images=', None, 'set the image directory'), |
28 | ('encryption=', None, 'set the encryption template directory'), |
29 | ('bin=', None, 'set the bin directory'), |
30 | @@ -96,6 +100,10 @@ |
31 | self.lib = '/usr/lib/wicd/' |
32 | self.share = '/usr/share/wicd/' |
33 | self.etc = '/etc/wicd/' |
34 | + self.scripts = self.etc + "scripts/" |
35 | + self.preconnectscripts = self.scripts + "preconnect/" |
36 | + self.postconnectscripts = self.scripts + "postconnect/" |
37 | + self.disconnectscripts = self.scripts + "disconnect/" |
38 | self.icons = '/usr/share/icons/hicolor/' |
39 | self.images = '/usr/share/pixmaps/wicd/' |
40 | self.encryption = self.etc + 'encryption/templates/' |
41 | @@ -175,10 +183,12 @@ |
42 | # If we don't get anything from *-config, or it didn't run properly, |
43 | # or the path is not a proper absolute path, raise an error |
44 | try: |
45 | - pmtemp = subprocess.Popen(["pkg-config","--variable=pm_sleephooks","pm-utils"], stdout=subprocess.PIPE) |
46 | + pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks", |
47 | + "pm-utils"], stdout=subprocess.PIPE) |
48 | returncode = pmtemp.wait() # let it finish, and get the exit code |
49 | pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout |
50 | - if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate): |
51 | + if len(pmutils_candidate) == 0 or returncode != 0 or \ |
52 | + not os.path.isabs(pmutils_candidate): |
53 | raise ValueError |
54 | else: |
55 | self.pmutils = pmutils_candidate |
56 | @@ -189,7 +199,8 @@ |
57 | kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE) |
58 | returncode = kdetemp.wait() # let it finish, and get the exit code |
59 | kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout |
60 | - if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate): |
61 | + if len(kdedir_candidate) == 0 or returncode != 0 or \ |
62 | + not os.path.isabs(kdedir_candidate): |
63 | raise ValueError |
64 | else: |
65 | self.kdedir = kdedir_candidate + '/share/autostart' |
66 | @@ -218,11 +229,10 @@ |
67 | |
68 | |
69 | def finalize_options(self): |
70 | - if self.distro_detect_failed == True: |
71 | - if not self.no_install_init: |
72 | - if self.init == 'FAIL' or self.initfile == 'FAIL': |
73 | - print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ |
74 | - 'Please specify --init and --initfile to continue with configuration.' |
75 | + if self.distro_detect_failed and not self.no_install_init and \ |
76 | + 'FAIL' in [self.init, self.initfile]: |
77 | + print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ |
78 | + 'Please specify --init and --initfile to continue with configuration.' |
79 | |
80 | |
81 | # loop through the argument definitions in user_options |
82 | @@ -408,6 +418,10 @@ |
83 | (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 | (wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']), |
85 | (wpath.autostart, ['other/wicd-tray.desktop', ]), |
86 | + (wpath.scripts, []), |
87 | + (wpath.disconnectscripts, []), |
88 | + (wpath.preconnectscripts, []), |
89 | + (wpath.postconnectscripts, []), |
90 | ] |
91 | if not wpath.no_install_ncurses: |
92 | data.append(( wpath.lib, ['curses/curses_misc.py'])) |
93 | @@ -456,14 +470,16 @@ |
94 | python setup.py configure has not yet been run.''' |
95 | |
96 | |
97 | -wpactrl_ext = Extension(name = 'wpactrl', sources = ['depends/python-wpactrl/wpa_ctrl.c', 'depends/python-wpactrl/wpactrl.c'], |
98 | - extra_compile_args = ["-fno-strict-aliasing"]) |
99 | +wpactrl_ext = Extension(name = 'wpactrl', |
100 | + sources = ['depends/python-wpactrl/wpa_ctrl.c', |
101 | + 'depends/python-wpactrl/wpactrl.c'], |
102 | + extra_compile_args = ["-fno-strict-aliasing"]) |
103 | |
104 | -iwscan_ext = Extension(name = 'iwscan', |
105 | - libraries = ['iw'], |
106 | - sources = ['depends/python-iwscan/pyiwscan.c']) |
107 | +iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'], |
108 | + sources = ['depends/python-iwscan/pyiwscan.c']) |
109 | |
110 | -setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, |
111 | +setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, |
112 | + 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, |
113 | name="Wicd", |
114 | version=VERSION_NUM, |
115 | description="A wireless and wired network manager", |
116 | @@ -476,16 +492,12 @@ |
117 | connect at startup to any preferred network within range. |
118 | """, |
119 | author="Adam Blackburn, Dan O'Reilly", |
120 | - author_email="compwiz18@users.sourceforge.net, imdano@users.sourceforge.net", |
121 | + author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com", |
122 | url="http://wicd.net", |
123 | license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", |
124 | - ## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'], |
125 | - py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', |
126 | - 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', |
127 | - 'wicd.configmanager', 'wicd.guiutil'], |
128 | + py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', |
129 | + 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', |
130 | + 'wicd.logfile', 'wicd.backend', 'wicd.configmanager', 'wicd.guiutil'], |
131 | ext_modules=[iwscan_ext, wpactrl_ext], |
132 | data_files=data |
133 | ) |
134 | -##print "Running post-install configuration..." |
135 | -##os.system("other/postinst") |
136 | -##print 'Done.' |
137 | |
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 | GKSUDO = 1 |
143 | KDESU = 2 |
144 | KTSUSS = 3 |
145 | -__sudo_dict = { |
146 | +_sudo_dict = { |
147 | AUTO : "", |
148 | GKSUDO : "gksudo", |
149 | KDESU : "kdesu", |
150 | @@ -172,9 +172,20 @@ |
151 | """ write a line to a file """ |
152 | my_file.write(text + "\n") |
153 | |
154 | -def ExecuteScript(script): |
155 | +def ExecuteScripts(scripts_dir, verbose=False): |
156 | + """ Execute every executable file in a given directory. """ |
157 | + for obj in os.listdir(scripts_dir): |
158 | + obj = os.path.abspath(os.path.join(scripts_dir, obj)) |
159 | + if os.path.isfile(obj) and os.access(obj, os.X_OK): |
160 | + ExecuteScript(os.path.abspath(obj), verbose=verbose) |
161 | + |
162 | +def ExecuteScript(script, verbose=False): |
163 | """ Execute a command and send its output to the bit bucket. """ |
164 | - call("%s > /dev/null 2>&1" % script, shell=True) |
165 | + if verbose: |
166 | + print "Executing %s" % script |
167 | + ret = call("%s > /dev/null 2>&1" % script, shell=True) |
168 | + if verbose: |
169 | + "%s returned %s" % (script, ret) |
170 | |
171 | def ReadFile(filename): |
172 | """ read in a file and return it's contents as a string """ |
173 | @@ -427,7 +438,7 @@ |
174 | def choose_sudo_prog(prog_num=0): |
175 | """ Try to intelligently decide which graphical sudo program to use. """ |
176 | if prog_num: |
177 | - return find_path(__sudo_dict[prog_num]) |
178 | + return find_path(_sudo_dict[prog_num]) |
179 | desktop_env = detect_desktop_environment() |
180 | env_path = os.environ['PATH'].split(":") |
181 | paths = [] |
182 | |
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 | def Disconnect(self, *args, **kargs): |
188 | """ Disconnect from the network. """ |
189 | iface = self.iface |
190 | - if self.disconnect_script != None: |
191 | + misc.ExecuteScripts(wpath.disconnectscripts, self.debug) |
192 | + if self.disconnect_script: |
193 | print 'Running disconnect script' |
194 | misc.ExecuteScript(expand_script_macros(self.disconnect_script, |
195 | - 'disconnection', *args)) |
196 | + 'disconnection', *args), |
197 | + self.debug) |
198 | iface.ReleaseDHCP() |
199 | iface.SetAddress('0.0.0.0') |
200 | iface.FlushRoutes() |
201 | @@ -369,6 +371,10 @@ |
202 | iface.Down() |
203 | |
204 | @abortable |
205 | + def run_global_scripts_if_needed(self, script_dir): |
206 | + misc.ExecuteScripts(script_dir, verbose=self.debug) |
207 | + |
208 | + @abortable |
209 | def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'): |
210 | """ Execute a given script if needed. |
211 | |
212 | @@ -379,7 +385,8 @@ |
213 | """ |
214 | if script: |
215 | print 'Executing %s script' % (msg) |
216 | - misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid)) |
217 | + misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid), |
218 | + self.debug) |
219 | |
220 | @abortable |
221 | def flush_routes(self, iface): |
222 | @@ -761,6 +768,7 @@ |
223 | self.is_connecting = True |
224 | |
225 | # Run pre-connection script. |
226 | + self.run_global_scripts_if_needed(wpath.preconnectscripts) |
227 | self.run_script_if_needed(self.before_script, 'pre-connection', |
228 | self.network['bssid'], self.network['essid']) |
229 | |
230 | @@ -803,6 +811,7 @@ |
231 | self.set_dns_addresses() |
232 | |
233 | # Run post-connection script. |
234 | + self.run_global_scripts_if_needed(wpath.postconnectscripts) |
235 | self.run_script_if_needed(self.after_script, 'post-connection', |
236 | self.network['bssid'], self.network['essid']) |
237 | |
238 | @@ -971,6 +980,7 @@ |
239 | self.is_connecting = True |
240 | |
241 | # Run pre-connection script. |
242 | + self.run_global_scripts_if_needed(wpath.preconnectscripts) |
243 | self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', |
244 | 'wired') |
245 | |
246 | @@ -989,6 +999,7 @@ |
247 | self.set_dns_addresses() |
248 | |
249 | # Run post-connection script. |
250 | + self.run_global_scripts_if_needed(wpath.postconnectscripts) |
251 | self.run_script_if_needed(self.after_script, 'post-connection', 'wired', |
252 | 'wired') |
253 |
Adds global script directories to /etc/wicd.