Merge lp:~nataliabidart/ubuntuone-client/tool-no-params into lp:ubuntuone-client
- tool-no-params
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 1000 |
Merged at revision: | 1002 |
Proposed branch: | lp:~nataliabidart/ubuntuone-client/tool-no-params |
Merge into: | lp:ubuntuone-client |
Diff against target: |
458 lines (+73/-64) 1 file modified
ubuntuone/platform/linux/tools.py (+73/-64) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-client/tool-no-params |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
dobey (community) | Approve | ||
Alejandro J. Cura (community) | Approve | ||
Review via email: mp+64610@code.launchpad.net |
Commit message
- No mandatory creation param for SyncDaemonTool (LP: #797405).
Description of the change
To post a comment you must log in.
Revision history for this message
dobey (dobey) wrote : | # |
For the things alecu mentioned.
review:
Needs Fixing
- 1000. By Natalia Bidart
-
Typos.
Revision history for this message
dobey (dobey) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ubuntuone/platform/linux/tools.py' |
2 | --- ubuntuone/platform/linux/tools.py 2011-06-09 10:08:57 +0000 |
3 | +++ ubuntuone/platform/linux/tools.py 2011-06-15 17:24:40 +0000 |
4 | @@ -15,12 +15,15 @@ |
5 | # |
6 | # You should have received a copy of the GNU General Public License along |
7 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
8 | -""" SyncDaemon Tools """ |
9 | -import dbus |
10 | + |
11 | +"""SyncDaemon Tools.""" |
12 | + |
13 | import logging |
14 | import time |
15 | import sys |
16 | |
17 | +import dbus |
18 | + |
19 | from ubuntuone.platform.linux.dbus_interface import ( |
20 | DBUS_IFACE_NAME, |
21 | DBUS_IFACE_STATUS_NAME, |
22 | @@ -39,8 +42,10 @@ |
23 | |
24 | |
25 | def is_running(bus=None): |
26 | - """Check if there is a syncdaemon instance running or if |
27 | - the name is registered in the bus. |
28 | + """Check if there is a syncdaemon instance running. |
29 | + |
30 | + Running means the name is registered in the given bus. |
31 | + |
32 | """ |
33 | if bus is None: |
34 | bus = dbus.SessionBus() |
35 | @@ -52,17 +57,17 @@ |
36 | |
37 | |
38 | class DBusClient(object): |
39 | - """ Low level dbus client. To help testing the DBus interface. """ |
40 | + """Low level dbus client. To help testing the DBus interface.""" |
41 | |
42 | def __init__(self, bus, path, interface, destination=DBUS_IFACE_NAME): |
43 | - """ create the instance """ |
44 | + """Create the instance.""" |
45 | self.bus = bus |
46 | self.path = path |
47 | self.interface = interface |
48 | self.destination = destination |
49 | |
50 | def send_signal(self, signal, *args): |
51 | - """ Send method with *args """ |
52 | + """Send method with *args.""" |
53 | msg = SignalMessage(self.path, self.interface, |
54 | signal) |
55 | msg.set_no_reply(True) |
56 | @@ -70,7 +75,7 @@ |
57 | self.bus.send_message(msg) |
58 | |
59 | def call_method(self, method, *args, **kwargs): |
60 | - """ Call method with *args and **kwargs over dbus""" |
61 | + """Call method with *args and **kwargs over dbus.""" |
62 | msg = MethodCallMessage(self.destination, self.path, self.interface, |
63 | method) |
64 | msg.set_no_reply(True) |
65 | @@ -86,7 +91,7 @@ |
66 | assert error_handler != None |
67 | |
68 | def parse_reply(message): |
69 | - """ handle the reply message""" |
70 | + """Handle the reply message.""" |
71 | if isinstance(message, ErrorMessage): |
72 | return error_handler(DBusException( |
73 | name=message.get_error_name(), |
74 | @@ -105,27 +110,29 @@ |
75 | |
76 | |
77 | class SyncDaemonTool(object): |
78 | - """ Various utility methods to test/play with the SyncDaemon. """ |
79 | + """Various utility methods to test/play with the SyncDaemon.""" |
80 | |
81 | - def __init__(self, bus): |
82 | + def __init__(self, bus=None): |
83 | + if bus is None: |
84 | + bus = dbus.SessionBus() |
85 | self.bus = bus |
86 | self.last_event = 0 |
87 | self.delayed_call = None |
88 | self.log = logging.getLogger('ubuntuone.SyncDaemon.SDTool') |
89 | |
90 | def _get_dict(self, a_dict): |
91 | - """ Converts a dict returned by dbus to a dict of strings. """ |
92 | + """Converts a dict returned by dbus to a dict of strings.""" |
93 | str_dict = {} |
94 | for key in a_dict: |
95 | str_dict[key] = unicode(a_dict[key]) |
96 | return str_dict |
97 | |
98 | def wait_connected(self): |
99 | - """ Wait until syncdaemon is connected to the server. """ |
100 | + """Wait until syncdaemon is connected to the server.""" |
101 | self.log.debug('wait_connected') |
102 | d = defer.Deferred() |
103 | def check_connection_status(): |
104 | - """ Check if the daemon is up and running. """ |
105 | + """Check if the daemon is up and running.""" |
106 | # check if the syncdaemon is running |
107 | # catch all errors, pylint: disable-msg=W0703 |
108 | try: |
109 | @@ -141,12 +148,10 @@ |
110 | return d |
111 | |
112 | def get_current_downloads(self): |
113 | - """ Return a deferred that 'll be called with the list |
114 | - of current downloads |
115 | - """ |
116 | + """Return a deferred that will be fired with the current downloads.""" |
117 | d = defer.Deferred() |
118 | def current_downloads(): |
119 | - """ Call Status.current_downloads """ |
120 | + """Call Status.current_downloads.""" |
121 | status_client = DBusClient(self.bus, '/status', |
122 | DBUS_IFACE_STATUS_NAME) |
123 | status_client.call_method('current_downloads', |
124 | @@ -154,7 +159,7 @@ |
125 | error_handler=d.errback) |
126 | |
127 | def reply_handler(downloads): |
128 | - """ current downloads callback """ |
129 | + """Current downloads callback.""" |
130 | downloads_str = [] |
131 | for download in downloads: |
132 | downloads_str.append(self._get_dict(download)) |
133 | @@ -164,12 +169,14 @@ |
134 | return d |
135 | |
136 | def wait_all_downloads(self, verbose=False): |
137 | - """ Wait until there is no more pending downloads """ |
138 | + """Wait until there is no more pending downloads.""" |
139 | self.log.debug('wait_all_downloads') |
140 | d = self.get_current_downloads() |
141 | def reply_handler(downloads): |
142 | - """ Check if the are downloads in progress, and reschelude a |
143 | - new check if there is at least one. |
144 | + """Check if the are downloads in progress. |
145 | + |
146 | + If so, reschelude a new check if there is at least one. |
147 | + |
148 | """ |
149 | if verbose: |
150 | sys.stdout.write(', %s' % str(len(downloads))) |
151 | @@ -188,12 +195,10 @@ |
152 | return d |
153 | |
154 | def get_current_uploads(self): |
155 | - """ Return a deferred that 'll be called with the list |
156 | - of current uploads |
157 | - """ |
158 | + """Return a deferred that will be called with the current uploads.""" |
159 | d = defer.Deferred() |
160 | def current_uploads(): |
161 | - """ Call Status.current_uploads """ |
162 | + """Call Status.current_uploads.""" |
163 | status_client = DBusClient(self.bus, '/status', |
164 | DBUS_IFACE_STATUS_NAME) |
165 | status_client.call_method('current_uploads', |
166 | @@ -201,7 +206,7 @@ |
167 | error_handler=d.errback) |
168 | |
169 | def reply_handler(uploads): |
170 | - """ reply handler """ |
171 | + """Reply handler.""" |
172 | uploads_str = [] |
173 | for upload in uploads: |
174 | uploads_str.append(self._get_dict(upload)) |
175 | @@ -211,13 +216,15 @@ |
176 | return d |
177 | |
178 | def wait_all_uploads(self, verbose=False): |
179 | - """ Wait until there is no more pending uploads """ |
180 | + """Wait until there is no more pending uploads.""" |
181 | self.log.debug('wait_all_uploads') |
182 | d = self.get_current_uploads() |
183 | |
184 | def reply_handler(uploads): |
185 | - """ Check if the are downloads in progress, and reschelude a |
186 | - new check if there is at least one. |
187 | + """Check if the are downloads in progress. |
188 | + |
189 | + If so, reschelude a new check if there is at least one. |
190 | + |
191 | """ |
192 | if verbose: |
193 | sys.stdout.write(', %s' % str(len(uploads))) |
194 | @@ -290,7 +297,9 @@ |
195 | return d |
196 | |
197 | def wait_for_nirvana(self, last_event_interval=5, verbose=False): |
198 | - """ Wait until the syncdaemon reachs nirvana. This is when there are: |
199 | + """Wait until the syncdaemon reachs nirvana. |
200 | + |
201 | + This is when there are: |
202 | - the syncdaemon is connected |
203 | - 0 transfers inprogress |
204 | - no more events are fired in the event queue |
205 | @@ -306,7 +315,7 @@ |
206 | return d |
207 | |
208 | def accept_share(self, share_id): |
209 | - """ Accept the share with id: share_id. """ |
210 | + """Accept the share with id: share_id.""" |
211 | self.log.debug('accept_share(%s)', share_id) |
212 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
213 | d = self.wait_for_signal('ShareAnswerResponse', |
214 | @@ -317,7 +326,7 @@ |
215 | return d |
216 | |
217 | def reject_share(self, share_id): |
218 | - """ Reject the share with id: share_id. """ |
219 | + """Reject the share with id: share_id.""" |
220 | self.log.debug('reject_share(%s)', share_id) |
221 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
222 | d = self.wait_for_signal('ShareAnswerResponse', |
223 | @@ -360,12 +369,12 @@ |
224 | yield d |
225 | |
226 | def get_shares(self): |
227 | - """ Get the list of shares (accepted or not) """ |
228 | + """Get the list of shares (accepted or not).""" |
229 | self.log.debug('get_shares') |
230 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
231 | d = defer.Deferred() |
232 | def reply_handler(results): |
233 | - """ get_shares reply handler. """ |
234 | + """Get_shares reply handler.""" |
235 | shares = [] |
236 | for result in results: |
237 | shares.append(self._get_dict(result)) |
238 | @@ -378,8 +387,10 @@ |
239 | return d |
240 | |
241 | def refresh_shares(self): |
242 | - """ Call refresh_shares method via DBus. |
243 | + """Call refresh_shares method via DBus. |
244 | + |
245 | Request a refresh of share list to the server. |
246 | + |
247 | """ |
248 | self.log.debug('refresh_shares') |
249 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
250 | @@ -390,7 +401,7 @@ |
251 | return d |
252 | |
253 | def offer_share(self, path, username, name, access_level): |
254 | - """ Offer a share at the specified path to user with id: username. """ |
255 | + """Offer a share at the specified path to user with id: username.""" |
256 | self.log.debug('offer_share(%s, %s, %s, %s)', |
257 | path, username, name, access_level) |
258 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
259 | @@ -402,12 +413,12 @@ |
260 | return d |
261 | |
262 | def list_shared(self): |
263 | - """ get the list of the shares "shared"/created/offered. """ |
264 | + """Get the list of the shares "shared"/created/offered.""" |
265 | self.log.debug('list_shared') |
266 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
267 | d = defer.Deferred() |
268 | def reply_handler(results): |
269 | - """ get_shares reply handler. """ |
270 | + """Get_shares reply handler.""" |
271 | shares = [] |
272 | for result in results: |
273 | shares.append(self._get_dict(result)) |
274 | @@ -420,8 +431,7 @@ |
275 | |
276 | def wait_for_signals(self, signal_ok, signal_error, |
277 | dbus_iface=DBUS_IFACE_FOLDERS_NAME): |
278 | - """wait for one of the specified DBus signals |
279 | - this returns a deferred |
280 | + """Wait for one of the specified DBus signals, return a deferred. |
281 | |
282 | @param signal_ok: this will fire the deferred's callback |
283 | @param signal_error: the will fire the deferred's errback |
284 | @@ -500,7 +510,7 @@ |
285 | DBUS_IFACE_FOLDERS_NAME) |
286 | d = defer.Deferred() |
287 | def reply_handler(results): |
288 | - """ get_folders reply handler. """ |
289 | + """Get_folders reply handler.""" |
290 | folders = [] |
291 | for result in results: |
292 | folders.append(self._get_dict(result)) |
293 | @@ -522,7 +532,7 @@ |
294 | return d |
295 | |
296 | def get_metadata(self, path): |
297 | - """ calls the exposed mtehod FileSystem.get_metadata using DBus. """ |
298 | + """Call the exposed mtehod FileSystem.get_metadata using DBus.""" |
299 | self.log.debug('get_metadata(%s)', path) |
300 | fs_client = DBusClient(self.bus, '/filesystem', DBUS_IFACE_FS_NAME) |
301 | d = defer.Deferred() |
302 | @@ -555,7 +565,7 @@ |
303 | defer.returnValue(file_info) |
304 | |
305 | def quit(self): |
306 | - """quit the syncdaemon""" |
307 | + """Quit the syncdaemon.""" |
308 | self.log.debug('quit') |
309 | # avoid triggering dbus activation while calling quit |
310 | if not is_running(self.bus): |
311 | @@ -566,7 +576,7 @@ |
312 | reply_handler=d.callback, |
313 | error_handler=d.errback) |
314 | def check(r): |
315 | - """wait 0.5 sec to return, to allow syncdaemon to shutdown""" |
316 | + """Wait 0.5 sec to return, to allow syncdaemon to shutdown.""" |
317 | d1 = defer.Deferred() |
318 | reactor.callLater(0.5, d1.callback, r) |
319 | return d1 |
320 | @@ -574,15 +584,16 @@ |
321 | return d |
322 | |
323 | def wait_for_signal(self, signal_name, filter): |
324 | - """wait for the specified DBus signal (the first received). |
325 | - 'filter' is used to fire the deferred callback. |
326 | + """Wait for the specified DBus signal (the first received). |
327 | |
328 | @param signal_name: the signal name |
329 | - @param filter: a callable to filter signal, must return True |
330 | + @param filter: a callable to filter signal, must return True, and is |
331 | + used to fire the deferred callback. |
332 | + |
333 | """ |
334 | d = defer.Deferred() |
335 | def signal_handler(result): |
336 | - """handle the signals and fires the call/errback""" |
337 | + """Handle the signals and fires the call/errback""" |
338 | try: |
339 | if filter(result) and not d.called: |
340 | d.callback(result) |
341 | @@ -593,14 +604,14 @@ |
342 | match = self.bus.add_signal_receiver(signal_handler, |
343 | signal_name=signal_name) |
344 | def cleanup(result): |
345 | - """remove the signal receiver from the bus.""" |
346 | + """Remove the signal receiver from the bus.""" |
347 | self.bus.remove_signal_receiver(match) |
348 | return result |
349 | d.addCallback(cleanup) |
350 | return d |
351 | |
352 | def connect(self): |
353 | - """Connect syncdaemon""" |
354 | + """Connect syncdaemon.""" |
355 | sd_client = DBusClient(self.bus, '/', DBUS_IFACE_SYNC_NAME) |
356 | d = defer.Deferred() |
357 | sd_client.call_method('connect', |
358 | @@ -609,7 +620,7 @@ |
359 | return d |
360 | |
361 | def disconnect(self): |
362 | - """Disconnect syncdaemon""" |
363 | + """Disconnect syncdaemon.""" |
364 | sd_client = DBusClient(self.bus, '/', DBUS_IFACE_SYNC_NAME) |
365 | d = defer.Deferred() |
366 | sd_client.call_method('disconnect', |
367 | @@ -618,7 +629,7 @@ |
368 | return d |
369 | |
370 | def get_status(self): |
371 | - """Get the current_status dict""" |
372 | + """Get the current_status dict.""" |
373 | d = defer.Deferred() |
374 | status_client = DBusClient(self.bus, '/status', |
375 | DBUS_IFACE_STATUS_NAME) |
376 | @@ -655,7 +666,7 @@ |
377 | return d |
378 | |
379 | def waiting_content(self): |
380 | - """Returns the waiting content queue elements.""" |
381 | + """Return the waiting content queue elements.""" |
382 | d = defer.Deferred() |
383 | status_client = DBusClient(self.bus, '/status', |
384 | DBUS_IFACE_STATUS_NAME) |
385 | @@ -665,9 +676,7 @@ |
386 | return d |
387 | |
388 | def start(self): |
389 | - """Start syncdaemon using the StartServiceByName method |
390 | - if it's not running. |
391 | - """ |
392 | + """Start syncdaemon if it's not running.""" |
393 | if not is_running(self.bus): |
394 | wait_d = self.wait_for_signal('StatusChanged', lambda x: x) |
395 | d = defer.Deferred() |
396 | @@ -856,7 +865,7 @@ |
397 | # callbacks used by u1sdtool script |
398 | |
399 | def show_shared(shares, out): |
400 | - """ Callback that prints the list of shared shares""" |
401 | + """Callback that prints the list of shared shares.""" |
402 | if len(shares) == 0: |
403 | out.write("No shared\n") |
404 | else: |
405 | @@ -871,7 +880,7 @@ |
406 | |
407 | |
408 | def show_folders(folders, out): |
409 | - """ Callback that prints the list of user defined folders""" |
410 | + """Callback that prints the list of user defined folders.""" |
411 | if len(folders) == 0: |
412 | out.write("No folders\n") |
413 | else: |
414 | @@ -895,7 +904,7 @@ |
415 | |
416 | |
417 | def show_shares(shares, out): |
418 | - """ Callback that print the list of shares""" |
419 | + """Callback that prints the list of shares.""" |
420 | if len(shares) == 0: |
421 | out.write("No shares\n") |
422 | else: |
423 | @@ -909,7 +918,7 @@ |
424 | |
425 | |
426 | def show_path_info(result, path, out): |
427 | - """ print the path info to stdout""" |
428 | + """Print the path info to stdout.""" |
429 | out_encoding = out.encoding |
430 | if out_encoding is None: |
431 | out_encoding = 'utf-8' |
432 | @@ -921,7 +930,7 @@ |
433 | |
434 | |
435 | def show_uploads(uploads, out): |
436 | - """ print the uploads to stdout""" |
437 | + """Print the uploads to stdout.""" |
438 | if uploads: |
439 | out.write("Current uploads:\n") |
440 | else: |
441 | @@ -934,7 +943,7 @@ |
442 | |
443 | |
444 | def show_downloads(downloads, out): |
445 | - """ print the downloas to stdout""" |
446 | + """Print the downloads to stdout.""" |
447 | if downloads: |
448 | out.write("Current downloads:\n") |
449 | else: |
450 | @@ -993,7 +1002,7 @@ |
451 | |
452 | |
453 | def show_waiting_content(waiting_ops, out): |
454 | - """Print the waiting_content result""" |
455 | + """Print the waiting_content result.""" |
456 | out.write("Warning: this option is deprecated! Use '--waiting' instead\n") |
457 | value_tpl = "operation='%(operation)s' node_id='%(node)s' " + \ |
458 | "share_id='%(share)s' path='%(path)s'" |
Branch looks good.
A few details in the fixed docstrings:
line 419: it should be "prints"
line 446: "downloads" is spelled wrong.