Merge lp:~elachuni/software-center/pep8-test-part21 into lp:software-center
- pep8-test-part21
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2878 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part21 |
Merge into: | lp:software-center |
Diff against target: |
1289 lines (+318/-248) 10 files modified
softwarecenter/backend/__init__.py (+0/-2) softwarecenter/backend/channel_impl/aptchannels.py (+47/-43) softwarecenter/backend/spawn_helper.py (+19/-17) softwarecenter/backend/transactionswatcher.py (+38/-25) softwarecenter/backend/ubuntusso.py (+30/-23) softwarecenter/backend/unitylauncher.py (+7/-5) softwarecenter/backend/weblive.py (+71/-52) softwarecenter/backend/weblive_pristine.py (+89/-63) softwarecenter/backend/zeitgeist_simple.py (+12/-9) test/test_pep8.py (+5/-9) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part21 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
software-store-developers | Pending | ||
Review via email: mp+98200@code.launchpad.net |
Commit message
Description of the change
This branch includes whitespace fixes for about half the files under softwarecenter/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'softwarecenter/backend/__init__.py' |
2 | --- softwarecenter/backend/__init__.py 2011-08-09 08:47:43 +0000 |
3 | +++ softwarecenter/backend/__init__.py 2012-03-19 13:59:07 +0000 |
4 | @@ -21,5 +21,3 @@ |
5 | # mvo: this is only there to make pyflakes silent (otherwise it thinks |
6 | # its a unused import) |
7 | get_install_backend |
8 | - |
9 | - |
10 | |
11 | === modified file 'softwarecenter/backend/channel_impl/aptchannels.py' |
12 | --- softwarecenter/backend/channel_impl/aptchannels.py 2012-01-04 23:31:30 +0000 |
13 | +++ softwarecenter/backend/channel_impl/aptchannels.py 2012-03-19 13:59:07 +0000 |
14 | @@ -39,13 +39,14 @@ |
15 | |
16 | LOG = logging.getLogger(__name__) |
17 | |
18 | + |
19 | class AptChannelsManager(ChannelsManager): |
20 | |
21 | def __init__(self, db): |
22 | self.db = db |
23 | self.distro = get_distro() |
24 | self.backend = get_install_backend() |
25 | - self.backend.connect("channels-changed", |
26 | + self.backend.connect("channels-changed", |
27 | self._remove_no_longer_needed_extra_channels) |
28 | # kick off a background check for changes that may have been made |
29 | # in the channels list |
30 | @@ -60,7 +61,7 @@ |
31 | """ |
32 | return a list of SoftwareChannel objects in display order |
33 | according to: |
34 | - Distribution, Partners, PPAs alphabetically, |
35 | + Distribution, Partners, PPAs alphabetically, |
36 | Other channels alphabetically, Unknown channel last |
37 | """ |
38 | return self._get_channels() |
39 | @@ -70,7 +71,7 @@ |
40 | """ |
41 | return a list of SoftwareChannel objects displaying installed |
42 | packages only in display order according to: |
43 | - Distribution, Partners, PPAs alphabetically, |
44 | + Distribution, Partners, PPAs alphabetically, |
45 | Other channels alphabetically, Unknown channel last |
46 | """ |
47 | return self._get_channels(installed_only=True) |
48 | @@ -89,7 +90,7 @@ |
49 | return the new channel object |
50 | """ |
51 | # print name, icon, query |
52 | - channel = SoftwareChannel(name, None, None, |
53 | + channel = SoftwareChannel(name, None, None, |
54 | channel_icon=icon, |
55 | channel_query=query) |
56 | self.extra_channels.append(channel) |
57 | @@ -113,7 +114,7 @@ |
58 | """ |
59 | this feeds in a private sources.list entry that is |
60 | available to the user (like a private PPA) that may or |
61 | - may not be active |
62 | + may not be active |
63 | """ |
64 | # FIXME: strip out password and use apt/auth.conf |
65 | potential_new_entry = SourceEntry(source_entry) |
66 | @@ -150,14 +151,14 @@ |
67 | |
68 | def _check_for_channel_updates_timer(self): |
69 | """ |
70 | - run a background timer to see if the a-x-i data we have is |
71 | + run a background timer to see if the a-x-i data we have is |
72 | still fresh or if the cache has changed since |
73 | """ |
74 | # this is expensive and does not need UI to we shove it out |
75 | channel_update = os.path.join( |
76 | softwarecenter.paths.datadir, "update-software-center-channels") |
77 | (pid, stdin, stdout, stderr) = GObject.spawn_async( |
78 | - [channel_update], |
79 | + [channel_update], |
80 | flags=GObject.SPAWN_DO_NOT_REAP_CHILD) |
81 | GObject.child_watch_add( |
82 | pid, self._on_check_for_channel_updates_finished) |
83 | @@ -166,13 +167,14 @@ |
84 | # exit status of 1 means stuff changed |
85 | if os.WEXITSTATUS(condition) == 1: |
86 | self.db.reopen() |
87 | - |
88 | + |
89 | def _get_channels(self, installed_only=False): |
90 | """ |
91 | - (internal) implements 'channels()' and 'channels_installed_only()' properties |
92 | + (internal) implements 'channels()' and 'channels_installed_only()' |
93 | + properties |
94 | """ |
95 | distro_channel_name = self.distro.get_distro_channel_name() |
96 | - |
97 | + |
98 | # gather the set of software channels and order them |
99 | other_channel_list = [] |
100 | cached_origins = [] |
101 | @@ -181,12 +183,13 @@ |
102 | continue |
103 | channel_name = channel_iter.term[3:] |
104 | channel_origin = "" |
105 | - |
106 | + |
107 | # get origin information for this channel |
108 | m = self.db.xapiandb.postlist_begin(channel_iter.term) |
109 | doc = self.db.xapiandb.get_document(m.get_docid()) |
110 | for term_iter in doc.termlist(): |
111 | - if term_iter.term.startswith("XOO") and len(term_iter.term) > 3: |
112 | + if (term_iter.term.startswith("XOO") and |
113 | + len(term_iter.term) > 3): |
114 | channel_origin = term_iter.term[3:] |
115 | break |
116 | self._logger.debug("channel_name: %s" % channel_name) |
117 | @@ -194,7 +197,7 @@ |
118 | if channel_origin not in cached_origins: |
119 | other_channel_list.append((channel_name, channel_origin)) |
120 | cached_origins.append(channel_origin) |
121 | - |
122 | + |
123 | dist_channel = None |
124 | partner_channel = None |
125 | for_purchase_channel = None |
126 | @@ -207,9 +210,9 @@ |
127 | for (channel_name, channel_origin) in other_channel_list: |
128 | if not channel_name: |
129 | unknown_channel.append(SoftwareChannel(channel_name, |
130 | - channel_origin, |
131 | - None, |
132 | - installed_only=installed_only)) |
133 | + channel_origin, |
134 | + None, |
135 | + installed_only=installed_only)) |
136 | elif channel_name == distro_channel_name: |
137 | dist_channel = (SoftwareChannel(distro_channel_name, |
138 | channel_origin, |
139 | @@ -217,52 +220,54 @@ |
140 | installed_only=installed_only)) |
141 | elif channel_name == "Partner archive": |
142 | partner_channel = SoftwareChannel(channel_name, |
143 | - channel_origin, |
144 | - "partner", |
145 | - installed_only=installed_only) |
146 | + channel_origin, |
147 | + "partner", |
148 | + installed_only=installed_only) |
149 | elif channel_name == "notdownloadable": |
150 | if installed_only: |
151 | local_channel = SoftwareChannel(channel_name, |
152 | - None, |
153 | - None, |
154 | - installed_only=installed_only) |
155 | + None, |
156 | + None, |
157 | + installed_only=installed_only) |
158 | elif (channel_origin and |
159 | - channel_origin.startswith("LP-PPA-commercial-ppa-uploaders")): |
160 | + channel_origin.startswith("LP-PPA-commercial-ppa-uploaders")): |
161 | # do not display commercial private PPAs, they will all be |
162 | # displayed in the "for-purchase" node anyway |
163 | pass |
164 | elif channel_origin and channel_origin.startswith("LP-PPA"): |
165 | if channel_origin == "LP-PPA-app-review-board": |
166 | new_apps_channel = SoftwareChannel(channel_name, |
167 | - channel_origin, |
168 | - None, |
169 | - installed_only=installed_only) |
170 | + channel_origin, |
171 | + None, |
172 | + installed_only=installed_only) |
173 | else: |
174 | ppa_channels.append(SoftwareChannel(channel_name, |
175 | - channel_origin, |
176 | - None, |
177 | - installed_only=installed_only)) |
178 | + channel_origin, |
179 | + None, |
180 | + installed_only=installed_only)) |
181 | # TODO: detect generic repository source (e.g., Google, Inc.) |
182 | else: |
183 | other_channels.append(SoftwareChannel(channel_name, |
184 | - channel_origin, |
185 | - None, |
186 | - installed_only=installed_only)) |
187 | + channel_origin, |
188 | + None, |
189 | + installed_only=installed_only)) |
190 | |
191 | - # always display the partner channel, even if its source is not enabled |
192 | + # always display the partner channel, even if its source is not enabled |
193 | if not partner_channel and distro_channel_name == "Ubuntu": |
194 | partner_channel = SoftwareChannel("Partner archive", |
195 | "Canonical", |
196 | - "partner", |
197 | + "partner", |
198 | installed_only=installed_only) |
199 | - |
200 | - # create a "magic" channel to display items available for purchase |
201 | - for_purchase_query = xapian.Query("AH" + AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME) |
202 | - for_purchase_channel = SoftwareChannel("For Purchase", "software-center-agent", None, |
203 | - channel_icon=None, # FIXME: need an icon |
204 | - channel_query=for_purchase_query, |
205 | - installed_only=installed_only) |
206 | - |
207 | + |
208 | + # create a "magic" channel to display items available for purchase |
209 | + for_purchase_query = xapian.Query("AH" + |
210 | + AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME) |
211 | + for_purchase_channel = SoftwareChannel("For Purchase", |
212 | + "software-center-agent", None, |
213 | + channel_icon=None, # FIXME: need an icon |
214 | + channel_query=for_purchase_query, |
215 | + installed_only=installed_only) |
216 | + |
217 | # set them in order |
218 | channels = [] |
219 | if dist_channel is not None: |
220 | @@ -286,4 +291,3 @@ |
221 | else: |
222 | channel._channel_view_id = ViewPages.AVAILABLE |
223 | return channels |
224 | - |
225 | |
226 | === modified file 'softwarecenter/backend/spawn_helper.py' |
227 | --- softwarecenter/backend/spawn_helper.py 2012-02-09 10:14:46 +0000 |
228 | +++ softwarecenter/backend/spawn_helper.py 2012-03-19 13:59:07 +0000 |
229 | @@ -22,7 +22,7 @@ |
230 | # py3 compat |
231 | try: |
232 | import cPickle as pickle |
233 | - pickle # pyflakes |
234 | + pickle # pyflakes |
235 | except ImportError: |
236 | import pickle |
237 | |
238 | @@ -37,21 +37,22 @@ |
239 | |
240 | LOG = logging.getLogger(__name__) |
241 | |
242 | + |
243 | class SpawnHelper(GObject.GObject): |
244 | - |
245 | + |
246 | __gsignals__ = { |
247 | - "data-available" : (GObject.SIGNAL_RUN_LAST, |
248 | - GObject.TYPE_NONE, |
249 | - (GObject.TYPE_PYOBJECT,), |
250 | - ), |
251 | - "exited" : (GObject.SIGNAL_RUN_LAST, |
252 | - GObject.TYPE_NONE, |
253 | - (int,), |
254 | - ), |
255 | - "error" : (GObject.SIGNAL_RUN_LAST, |
256 | - GObject.TYPE_NONE, |
257 | - (str,), |
258 | - ), |
259 | + "data-available": (GObject.SIGNAL_RUN_LAST, |
260 | + GObject.TYPE_NONE, |
261 | + (GObject.TYPE_PYOBJECT,), |
262 | + ), |
263 | + "exited": (GObject.SIGNAL_RUN_LAST, |
264 | + GObject.TYPE_NONE, |
265 | + (int,), |
266 | + ), |
267 | + "error": (GObject.SIGNAL_RUN_LAST, |
268 | + GObject.TYPE_NONE, |
269 | + (str,), |
270 | + ), |
271 | } |
272 | |
273 | def __init__(self, format="pickle"): |
274 | @@ -87,7 +88,7 @@ |
275 | def run(self, cmd): |
276 | self._cmd = cmd |
277 | (pid, stdin, stdout, stderr) = GObject.spawn_async( |
278 | - cmd, flags = GObject.SPAWN_DO_NOT_REAP_CHILD, |
279 | + cmd, flags=GObject.SPAWN_DO_NOT_REAP_CHILD, |
280 | standard_output=True, standard_error=True) |
281 | LOG.debug("running: '%s' as pid: '%s'" % (cmd, pid)) |
282 | self._child_watch = GObject.child_watch_add( |
283 | @@ -104,7 +105,7 @@ |
284 | else: |
285 | LOG.warn("exit code %s from helper for '%s'" % (res, self._cmd)) |
286 | # check stderr |
287 | - err = os.read(stderr, 4*1024) |
288 | + err = os.read(stderr, 4 * 1024) |
289 | self._stderr = err |
290 | if err: |
291 | LOG.warn("got error from helper: '%s'" % err) |
292 | @@ -122,7 +123,8 @@ |
293 | data = "" |
294 | while True: |
295 | s = os.read(stdout, 1024) |
296 | - if not s: break |
297 | + if not s: |
298 | + break |
299 | data += s |
300 | os.close(stdout) |
301 | self._stdout = data |
302 | |
303 | === modified file 'softwarecenter/backend/transactionswatcher.py' |
304 | --- softwarecenter/backend/transactionswatcher.py 2011-09-15 14:24:14 +0000 |
305 | +++ softwarecenter/backend/transactionswatcher.py 2012-03-19 13:59:07 +0000 |
306 | @@ -18,42 +18,47 @@ |
307 | |
308 | from gi.repository import GObject |
309 | |
310 | + |
311 | class BaseTransaction(GObject.GObject): |
312 | """ |
313 | wrapper class for install backend dbus Transaction objects |
314 | """ |
315 | - __gsignals__ = {'progress-details-changed':(GObject.SIGNAL_RUN_FIRST, |
316 | + __gsignals__ = {'progress-details-changed': (GObject.SIGNAL_RUN_FIRST, |
317 | GObject.TYPE_NONE, |
318 | (int, int, int, int, int, int)), |
319 | - 'progress-changed':(GObject.SIGNAL_RUN_FIRST, |
320 | - GObject.TYPE_NONE, |
321 | - (GObject.TYPE_PYOBJECT, )), |
322 | - 'status-changed':(GObject.SIGNAL_RUN_FIRST, |
323 | - GObject.TYPE_NONE, |
324 | - (GObject.TYPE_PYOBJECT, )), |
325 | - 'cancellable-changed':(GObject.SIGNAL_RUN_FIRST, |
326 | - GObject.TYPE_NONE, |
327 | - (GObject.TYPE_PYOBJECT, )), |
328 | - 'role-changed':(GObject.SIGNAL_RUN_FIRST, |
329 | - GObject.TYPE_NONE, |
330 | - (GObject.TYPE_PYOBJECT, )), |
331 | - 'deleted':(GObject.SIGNAL_RUN_FIRST, |
332 | - GObject.TYPE_NONE, |
333 | - []), |
334 | + 'progress-changed': (GObject.SIGNAL_RUN_FIRST, |
335 | + GObject.TYPE_NONE, |
336 | + (GObject.TYPE_PYOBJECT, )), |
337 | + 'status-changed': (GObject.SIGNAL_RUN_FIRST, |
338 | + GObject.TYPE_NONE, |
339 | + (GObject.TYPE_PYOBJECT, )), |
340 | + 'cancellable-changed': (GObject.SIGNAL_RUN_FIRST, |
341 | + GObject.TYPE_NONE, |
342 | + (GObject.TYPE_PYOBJECT, )), |
343 | + 'role-changed': (GObject.SIGNAL_RUN_FIRST, |
344 | + GObject.TYPE_NONE, |
345 | + (GObject.TYPE_PYOBJECT, )), |
346 | + 'deleted': (GObject.SIGNAL_RUN_FIRST, |
347 | + GObject.TYPE_NONE, |
348 | + []), |
349 | } |
350 | |
351 | @property |
352 | def tid(self): |
353 | pass |
354 | + |
355 | @property |
356 | def status_details(self): |
357 | pass |
358 | + |
359 | @property |
360 | def meta_data(self): |
361 | return {} |
362 | + |
363 | @property |
364 | def cancellable(self): |
365 | return False |
366 | + |
367 | @property |
368 | def progress(self): |
369 | return False |
370 | @@ -73,22 +78,25 @@ |
371 | def cancel(self): |
372 | pass |
373 | |
374 | + |
375 | class BaseTransactionsWatcher(GObject.GObject): |
376 | - """ |
377 | - base class for objects that need to watch the install backend |
378 | + """ |
379 | + base class for objects that need to watch the install backend |
380 | for transaction changes. |
381 | |
382 | provides a "lowlevel-transactions-changed" signal |
383 | """ |
384 | |
385 | - __gsignals__ = {'lowlevel-transactions-changed': (GObject.SIGNAL_RUN_FIRST, |
386 | - GObject.TYPE_NONE, |
387 | - (str,GObject.TYPE_PYOBJECT)), |
388 | + __gsignals__ = {'lowlevel-transactions-changed': ( |
389 | + GObject.SIGNAL_RUN_FIRST, |
390 | + GObject.TYPE_NONE, |
391 | + (str, GObject.TYPE_PYOBJECT)), |
392 | } |
393 | |
394 | def get_transaction(self, tid): |
395 | """ should return a _Transaction object """ |
396 | - return None |
397 | + pass |
398 | + |
399 | |
400 | class TransactionFinishedResult(object): |
401 | """ represents the result of a transaction """ |
402 | @@ -101,6 +109,7 @@ |
403 | self.pkgname = None |
404 | self.meta_data = None |
405 | |
406 | + |
407 | class TransactionProgress(object): |
408 | """ represents the progress of the transaction """ |
409 | def __init__(self, trans): |
410 | @@ -110,14 +119,18 @@ |
411 | |
412 | # singleton |
413 | _tw = None |
414 | + |
415 | + |
416 | def get_transactions_watcher(): |
417 | global _tw |
418 | if _tw is None: |
419 | from softwarecenter.enums import USE_PACKAGEKIT_BACKEND |
420 | if not USE_PACKAGEKIT_BACKEND: |
421 | - from softwarecenter.backend.installbackend_impl.aptd import AptdaemonTransactionsWatcher |
422 | + from softwarecenter.backend.installbackend_impl.aptd import ( |
423 | + AptdaemonTransactionsWatcher) |
424 | _tw = AptdaemonTransactionsWatcher() |
425 | else: |
426 | - from softwarecenter.backend.installbackend_impl.packagekitd import PackagekitTransactionsWatcher |
427 | - _tw = PackagekitTransactionsWatcher() |
428 | + from softwarecenter.backend.installbackend_impl.packagekitd \ |
429 | + import PackagekitTransactionsWatcher |
430 | + _tw = PackagekitTransactionsWatcher() |
431 | return _tw |
432 | |
433 | === modified file 'softwarecenter/backend/ubuntusso.py' |
434 | --- softwarecenter/backend/ubuntusso.py 2012-01-06 05:43:34 +0000 |
435 | +++ softwarecenter/backend/ubuntusso.py 2012-03-19 13:59:07 +0000 |
436 | @@ -33,24 +33,24 @@ |
437 | |
438 | LOG = logging.getLogger(__name__) |
439 | |
440 | + |
441 | class UbuntuSSOAPI(GObject.GObject): |
442 | """ Ubuntu SSO interface using the oauth token from the keyring """ |
443 | |
444 | __gsignals__ = { |
445 | - "whoami" : (GObject.SIGNAL_RUN_LAST, |
446 | - GObject.TYPE_NONE, |
447 | - (GObject.TYPE_PYOBJECT,), |
448 | - ), |
449 | - "error" : (GObject.SIGNAL_RUN_LAST, |
450 | - GObject.TYPE_NONE, |
451 | - (GObject.TYPE_PYOBJECT,), |
452 | - ), |
453 | - |
454 | + "whoami": (GObject.SIGNAL_RUN_LAST, |
455 | + GObject.TYPE_NONE, |
456 | + (GObject.TYPE_PYOBJECT,), |
457 | + ), |
458 | + "error": (GObject.SIGNAL_RUN_LAST, |
459 | + GObject.TYPE_NONE, |
460 | + (GObject.TYPE_PYOBJECT,), |
461 | + ), |
462 | } |
463 | - |
464 | + |
465 | def __init__(self): |
466 | GObject.GObject.__init__(self) |
467 | - |
468 | + |
469 | def _on_whoami_data(self, spawner, piston_whoami): |
470 | self.emit("whoami", piston_whoami) |
471 | |
472 | @@ -66,6 +66,7 @@ |
473 | spawner.needs_auth = True |
474 | spawner.run_generic_piston_helper("UbuntuSsoAPI", "whoami") |
475 | |
476 | + |
477 | class UbuntuSSOAPIFake(UbuntuSSOAPI): |
478 | |
479 | def __init__(self): |
480 | @@ -76,26 +77,28 @@ |
481 | def whoami(self): |
482 | if self._fake_settings.get_setting('whoami_response') == "whoami": |
483 | self.emit("whoami", self._create_whoami_response()) |
484 | - elif self._fake_settings.get_setting('whoami_response') == "error": |
485 | + elif self._fake_settings.get_setting('whoami_response') == "error": |
486 | self.emit("error", self._make_error()) |
487 | - |
488 | + |
489 | def _create_whoami_response(self): |
490 | - username = self._fake_settings.get_setting('whoami_username') or "anyuser" |
491 | + username = (self._fake_settings.get_setting('whoami_username') or |
492 | + "anyuser") |
493 | response = { |
494 | - u'username': username.decode('utf-8'), |
495 | - u'preferred_email': u'user@email.com', |
496 | - u'displayname': u'Fake User', |
497 | - u'unverified_emails': [], |
498 | - u'verified_emails': [], |
499 | + u'username': username.decode('utf-8'), |
500 | + u'preferred_email': u'user@email.com', |
501 | + u'displayname': u'Fake User', |
502 | + u'unverified_emails': [], |
503 | + u'verified_emails': [], |
504 | u'openid_identifier': u'fnerkWt' |
505 | } |
506 | return response |
507 | - |
508 | + |
509 | def _make_error(): |
510 | return 'HTTP Error 401: Unauthorized' |
511 | |
512 | + |
513 | def get_ubuntu_sso_backend(): |
514 | - """ |
515 | + """ |
516 | factory that returns an ubuntu sso loader singelton |
517 | """ |
518 | if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ: |
519 | @@ -109,8 +112,12 @@ |
520 | # test code |
521 | def _login_success(lp, token): |
522 | print "success", lp, token |
523 | + |
524 | + |
525 | def _login_failed(lp): |
526 | print "fail", lp |
527 | + |
528 | + |
529 | def _login_need_user_and_password(sso): |
530 | import sys |
531 | sys.stdout.write("user: ") |
532 | @@ -126,9 +133,11 @@ |
533 | def _whoami(sso, result): |
534 | print "res: ", result |
535 | Gtk.main_quit() |
536 | + |
537 | def _error(sso, result): |
538 | print "err: ", result |
539 | Gtk.main_quit() |
540 | + |
541 | def _dbus_maybe_login_successful(ssologin, oauth_result): |
542 | print "got token, verify it now" |
543 | sso = UbuntuSSOAPI() |
544 | @@ -145,5 +154,3 @@ |
545 | backend.connect("login-successful", _dbus_maybe_login_successful) |
546 | backend.login_or_register() |
547 | Gtk.main() |
548 | - |
549 | - |
550 | |
551 | === modified file 'softwarecenter/backend/unitylauncher.py' |
552 | --- softwarecenter/backend/unitylauncher.py 2011-12-02 02:58:24 +0000 |
553 | +++ softwarecenter/backend/unitylauncher.py 2012-03-19 13:59:07 +0000 |
554 | @@ -21,6 +21,7 @@ |
555 | |
556 | LOG = logging.getLogger(__name__) |
557 | |
558 | + |
559 | class UnityLauncherInfo(object): |
560 | """ Simple class to keep track of application details needed for |
561 | Unity launcher integration |
562 | @@ -42,19 +43,20 @@ |
563 | self.icon_size = icon_size |
564 | self.app_install_desktop_file_path = app_install_desktop_file_path |
565 | self.trans_id = trans_id |
566 | - |
567 | + |
568 | + |
569 | class UnityLauncher(object): |
570 | """ Implements the integration between Software Center and the Unity |
571 | launcher |
572 | """ |
573 | - |
574 | + |
575 | def send_application_to_launcher(self, pkgname, launcher_info): |
576 | """ send a dbus message to the Unity launcher service to initiate |
577 | the add to launcher functionality for the specified application |
578 | - """ |
579 | - LOG.debug("sending dbus signal to Unity launcher for application: ", |
580 | + """ |
581 | + LOG.debug("sending dbus signal to Unity launcher for application: ", |
582 | launcher_info.name) |
583 | - LOG.debug(" launcher_info.icon_file_path: ", |
584 | + LOG.debug(" launcher_info.icon_file_path: ", |
585 | launcher_info.icon_file_path) |
586 | LOG.debug(" launcher_info.app_install_desktop_file_path: ", |
587 | launcher_info.app_install_desktop_file_path) |
588 | |
589 | === modified file 'softwarecenter/backend/weblive.py' |
590 | --- softwarecenter/backend/weblive.py 2011-09-15 14:24:14 +0000 |
591 | +++ softwarecenter/backend/weblive.py 2012-03-19 13:59:07 +0000 |
592 | @@ -14,11 +14,11 @@ |
593 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
594 | # GNU General Public License for more details. |
595 | # |
596 | -# You should have received a copy of the GNU General Public License |
597 | -# along with this program; if not, write to the Free Software |
598 | -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
599 | +# You should have received a copy of the GNU General Public License along with |
600 | +# this program; if not, write to the Free Software Foundation, Inc., |
601 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
602 | # |
603 | -# taken from lp:~weblive-dev/weblive/ltsp-cluster-agent-weblive/client/weblive.py |
604 | +# taken from lp:~weblive-dev/weblive/trunk/client/weblive.py |
605 | # and put into weblive_pristine.py |
606 | |
607 | import re |
608 | @@ -34,6 +34,7 @@ |
609 | from weblive_pristine import WebLive |
610 | import softwarecenter.paths |
611 | |
612 | + |
613 | class WebLiveBackend(object): |
614 | """ Backend for interacting with the WebLive service """ |
615 | |
616 | @@ -42,12 +43,12 @@ |
617 | 'https://weblive.stgraber.org/weblive/json') |
618 | |
619 | def __init__(self): |
620 | - self.weblive = WebLive(self.URL,True) |
621 | + self.weblive = WebLive(self.URL, True) |
622 | self.available_servers = [] |
623 | |
624 | - for client in (WebLiveClientX2GO,WebLiveClientQTNX): |
625 | + for client in (WebLiveClientX2GO, WebLiveClientQTNX): |
626 | if client.is_supported(): |
627 | - self.client=client() |
628 | + self.client = client() |
629 | break |
630 | |
631 | self._ready = Event() |
632 | @@ -63,7 +64,7 @@ |
633 | """ Get all the available data from WebLive """ |
634 | |
635 | self._ready.clear() |
636 | - servers=self.weblive.list_everything() |
637 | + servers = self.weblive.list_everything() |
638 | self._ready.set() |
639 | return servers |
640 | |
641 | @@ -77,7 +78,9 @@ |
642 | p.start() |
643 | |
644 | def is_pkgname_available_on_server(self, pkgname, serverid=None): |
645 | - """ Check if the package is available (on all servers or on 'serverid') """ |
646 | + """Check if the package is available (on all servers or |
647 | + on 'serverid') |
648 | + """ |
649 | |
650 | for server in self.available_servers: |
651 | if not serverid or server.name == serverid: |
652 | @@ -89,7 +92,7 @@ |
653 | def get_servers_for_pkgname(self, pkgname): |
654 | """ Return a list of servers having a given package """ |
655 | |
656 | - servers=[] |
657 | + servers = [] |
658 | for server in self.available_servers: |
659 | # No point in returning a server that's full |
660 | if server.current_users >= server.userlimit: |
661 | @@ -104,32 +107,38 @@ |
662 | session="desktop", wait=False): |
663 | """ Create a user on 'serverid' and start the session """ |
664 | |
665 | - # Use the boot_id to get a temporary unique identifier (till next reboot) |
666 | + # Use the boot_id to get a temporary unique identifier |
667 | + # (till next reboot) |
668 | if os.path.exists('/proc/sys/kernel/random/boot_id'): |
669 | - uuid=open('/proc/sys/kernel/random/boot_id','r').read().strip().replace('-','') |
670 | + uuid = open('/proc/sys/kernel/random/boot_id', |
671 | + 'r').read().strip().replace('-', '') |
672 | random.seed(uuid) |
673 | |
674 | # Generate a 20 characters string based on the boot_id |
675 | - identifier=''.join(random.choice(string.ascii_lowercase) for x in range (20)) |
676 | + identifier = ''.join(random.choice(string.ascii_lowercase) |
677 | + for x in range(20)) |
678 | |
679 | # Use the current username as the GECOS on the server |
680 | # if it's invalid (by weblive's standard), use "WebLive user" instead |
681 | - fullname=str(os.environ.get('USER','WebLive user')) |
682 | - if not re.match("^[A-Za-z0-9 ]*$",fullname) or len(fullname) == 0: |
683 | - fullname='WebLive user' |
684 | + fullname = str(os.environ.get('USER', 'WebLive user')) |
685 | + if not re.match("^[A-Za-z0-9 ]*$", fullname) or len(fullname) == 0: |
686 | + fullname = 'WebLive user' |
687 | |
688 | # Send the user's locale so it's automatically selected when connecting |
689 | - locale=os.environ.get("LANG","None").replace("UTF-8","utf8") |
690 | + locale = os.environ.get("LANG", "None").replace("UTF-8", "utf8") |
691 | |
692 | # Create the user and retrieve host and port of the target server |
693 | - connection=self.weblive.create_user(serverid, identifier, fullname, identifier, session, locale) |
694 | + connection = self.weblive.create_user(serverid, identifier, fullname, |
695 | + identifier, session, locale) |
696 | |
697 | # Connect using x2go or fallback to qtnx if not available |
698 | if (self.client): |
699 | - self.client.start_session(connection[0], connection[1], session, identifier, identifier, wait) |
700 | + self.client.start_session(connection[0], connection[1], session, |
701 | + identifier, identifier, wait) |
702 | else: |
703 | raise IOError("No remote desktop client available.") |
704 | |
705 | + |
706 | class WebLiveClient(GObject.GObject): |
707 | """ Generic WebLive client """ |
708 | |
709 | @@ -215,20 +224,21 @@ |
710 | os.mkdir(os.path.expanduser('~/.qtnx')) |
711 | |
712 | # Generate qtnx's configuration file |
713 | - filename=os.path.expanduser('~/.qtnx/%s-%s-%s.nxml') % ( |
714 | - host, port, session.replace("/","_")) |
715 | - nxml=open(filename,"w+") |
716 | - config=self.NXML_TEMPLATE |
717 | - config=config.replace("WL_NAME","%s-%s-%s" % (host, port, session.replace("/","_"))) |
718 | - config=config.replace("WL_SERVER", host) |
719 | - config=config.replace("WL_PORT",str(port)) |
720 | - config=config.replace("WL_COMMAND","weblive-session %s" % session) |
721 | + filename = os.path.expanduser('~/.qtnx/%s-%s-%s.nxml') % ( |
722 | + host, port, session.replace("/", "_")) |
723 | + nxml = open(filename, "w+") |
724 | + config = self.NXML_TEMPLATE |
725 | + config = config.replace("WL_NAME", "%s-%s-%s" % (host, port, |
726 | + session.replace("/", "_"))) |
727 | + config = config.replace("WL_SERVER", host) |
728 | + config = config.replace("WL_PORT", str(port)) |
729 | + config = config.replace("WL_COMMAND", "weblive-session %s" % session) |
730 | nxml.write(config) |
731 | nxml.close() |
732 | |
733 | # Prepare qtnx call |
734 | cmd = [self.BINARY_PATH, |
735 | - '%s-%s-%s' % (str(host), str(port), session.replace("/","_")), |
736 | + '%s-%s-%s' % (str(host), str(port), session.replace("/", "_")), |
737 | username, |
738 | password] |
739 | |
740 | @@ -237,11 +247,11 @@ |
741 | |
742 | if self.helper_progress == 10: |
743 | self.state = "connected" |
744 | - self.emit("connected",False) |
745 | + self.emit("connected", False) |
746 | return False |
747 | else: |
748 | - self.emit("progress",self.helper_progress * 10) |
749 | - self.helper_progress+=1 |
750 | + self.emit("progress", self.helper_progress * 10) |
751 | + self.helper_progress += 1 |
752 | return True |
753 | |
754 | def qtnx_start_timer(): |
755 | @@ -249,22 +259,22 @@ |
756 | status, we countdown from 20s |
757 | """ |
758 | |
759 | - self.helper_progress=0 |
760 | + self.helper_progress = 0 |
761 | qtnx_countdown() |
762 | - GObject.timeout_add_seconds( |
763 | - 2, qtnx_countdown) |
764 | + GObject.timeout_add_seconds(2, qtnx_countdown) |
765 | |
766 | qtnx_start_timer() |
767 | |
768 | if wait == False: |
769 | # Start in the background and attach a watch for when it exits |
770 | (self.helper_pid, stdin, stdout, stderr) = GObject.spawn_async( |
771 | - cmd, standard_input=True, standard_output=True, standard_error=True, |
772 | - flags=GObject.SPAWN_DO_NOT_REAP_CHILD) |
773 | - GObject.child_watch_add(self.helper_pid, self._on_qtnx_exit,filename) |
774 | + cmd, standard_input=True, standard_output=True, |
775 | + standard_error=True, flags=GObject.SPAWN_DO_NOT_REAP_CHILD) |
776 | + GObject.child_watch_add(self.helper_pid, self._on_qtnx_exit, |
777 | + filename) |
778 | else: |
779 | # Start it and wait till it finishes |
780 | - p=subprocess.Popen(cmd) |
781 | + p = subprocess.Popen(cmd) |
782 | p.wait() |
783 | |
784 | def _on_qtnx_exit(self, pid, status, filename): |
785 | @@ -276,6 +286,7 @@ |
786 | if os.path.exists(filename): |
787 | os.remove(filename) |
788 | |
789 | + |
790 | class WebLiveClientX2GO(WebLiveClient): |
791 | """ x2go client """ |
792 | |
793 | @@ -295,23 +306,27 @@ |
794 | """ Start a session using x2go """ |
795 | |
796 | # Start in the background and attach a watch for when it exits |
797 | - cmd = [os.path.join(softwarecenter.paths.datadir, softwarecenter.paths.X2GO_HELPER)] |
798 | + cmd = [os.path.join(softwarecenter.paths.datadir, |
799 | + softwarecenter.paths.X2GO_HELPER)] |
800 | (self.helper_pid, stdin, stdout, stderr) = GObject.spawn_async( |
801 | - cmd, standard_input=True, standard_output=True, standard_error=True, |
802 | - flags=GObject.SPAWN_DO_NOT_REAP_CHILD) |
803 | - self.helper_stdin=os.fdopen(stdin,"w") |
804 | - self.helper_stdout=os.fdopen(stdout) |
805 | - self.helper_stderr=os.fdopen(stderr) |
806 | + cmd, standard_input=True, standard_output=True, |
807 | + standard_error=True, flags=GObject.SPAWN_DO_NOT_REAP_CHILD) |
808 | + self.helper_stdin = os.fdopen(stdin, "w") |
809 | + self.helper_stdout = os.fdopen(stdout) |
810 | + self.helper_stderr = os.fdopen(stderr) |
811 | |
812 | # Add a watch for when the process exits |
813 | GObject.child_watch_add(self.helper_pid, self._on_x2go_exit) |
814 | |
815 | # Add a watch on stdout |
816 | - GObject.io_add_watch(self.helper_stdout, GObject.IO_IN, self._on_x2go_activity) |
817 | + GObject.io_add_watch(self.helper_stdout, GObject.IO_IN, |
818 | + self._on_x2go_activity) |
819 | |
820 | # Start the connection |
821 | self.state = "connecting" |
822 | - self.helper_stdin.write("CONNECT: \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n" % (host, port, username, password, session)) |
823 | + self.helper_stdin.write( |
824 | + "CONNECT: \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n" % |
825 | + (host, port, username, password, session)) |
826 | self.helper_stdin.flush() |
827 | |
828 | def disconnect_session(self): |
829 | @@ -329,17 +344,17 @@ |
830 | def _on_x2go_activity(self, stdout, condition): |
831 | """ Called when something appears on stdout """ |
832 | |
833 | - line=stdout.readline().strip() |
834 | + line = stdout.readline().strip() |
835 | if line.startswith("PROGRESS: "): |
836 | if line.endswith("creating"): |
837 | - self.emit("progress",10) |
838 | + self.emit("progress", 10) |
839 | elif line.endswith("connecting"): |
840 | - self.emit("progress",30) |
841 | + self.emit("progress", 30) |
842 | elif line.endswith("starting"): |
843 | - self.emit("progress",60) |
844 | + self.emit("progress", 60) |
845 | |
846 | elif line == "CONNECTED": |
847 | - self.emit("connected",True) |
848 | + self.emit("connected", True) |
849 | self.state = "connected" |
850 | elif line == "DISCONNECTED": |
851 | self.emit("disconnected") |
852 | @@ -355,6 +370,8 @@ |
853 | |
854 | # singleton |
855 | _weblive_backend = None |
856 | + |
857 | + |
858 | def get_weblive_backend(): |
859 | global _weblive_backend |
860 | if _weblive_backend is None: |
861 | @@ -374,4 +391,6 @@ |
862 | print(weblive.available_servers) |
863 | |
864 | # Start firefox on the first available server and wait for it to finish |
865 | - weblive.create_automatic_user_and_run_session(serverid=weblive.available_servers[0].name,session="firefox",wait=True) |
866 | + weblive.create_automatic_user_and_run_session( |
867 | + serverid=weblive.available_servers[0].name, session="firefox", |
868 | + wait=True) |
869 | |
870 | === modified file 'softwarecenter/backend/weblive_pristine.py' |
871 | --- softwarecenter/backend/weblive_pristine.py 2011-05-19 09:44:05 +0000 |
872 | +++ softwarecenter/backend/weblive_pristine.py 2012-03-19 13:59:07 +0000 |
873 | @@ -11,14 +11,18 @@ |
874 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
875 | # GNU General Public License for more details. |
876 | # |
877 | -# You should have received a copy of the GNU General Public License |
878 | -# along with this program; if not, write to the Free Software |
879 | -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
880 | +# You should have received a copy of the GNU General Public License along with |
881 | +# this program; if not, write to the Free Software Foundation, Inc., |
882 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
883 | # |
884 | -# taken from lp:~weblive-dev/weblive/ltsp-cluster-agent-weblive/client/weblive.py |
885 | +# taken from |
886 | +# lp:~weblive-dev/weblive/trunk/client/weblive.py |
887 | # and put into weblive_pristine.py until a ubuntu package is in main |
888 | |
889 | -import urllib, urllib2, json |
890 | +import json |
891 | +import urllib |
892 | +import urllib2 |
893 | + |
894 | |
895 | class WebLiveJsonError(Exception): |
896 | def __init__(self, value): |
897 | @@ -27,6 +31,7 @@ |
898 | def __str__(self): |
899 | return repr(self.value) |
900 | |
901 | + |
902 | class WebLiveError(Exception): |
903 | def __init__(self, value): |
904 | self.value = value |
905 | @@ -34,19 +39,23 @@ |
906 | def __str__(self): |
907 | return repr(self.value) |
908 | |
909 | + |
910 | class WebLiveLocale(object): |
911 | def __init__(self, locale, description): |
912 | self.locale = locale |
913 | self.description = description |
914 | |
915 | + |
916 | class WebLivePackage(object): |
917 | def __init__(self, pkgname, version, autoinstall): |
918 | self.pkgname = pkgname |
919 | self.version = version |
920 | self.autoinstall = autoinstall |
921 | |
922 | + |
923 | class WebLiveServer(object): |
924 | - def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall): |
925 | + def __init__(self, name, title, description, timelimit, userlimit, |
926 | + users, autoinstall): |
927 | self.name = name |
928 | self.title = title |
929 | self.description = description |
930 | @@ -56,37 +65,47 @@ |
931 | self.autoinstall = autoinstall |
932 | |
933 | def __repr__(self): |
934 | - return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s" % ( |
935 | - self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall) |
936 | + return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, " |
937 | + "current_users=%s, autoinstall=%s") % ( |
938 | + self.name, self.title, self.description, self.timelimit, |
939 | + self.userlimit, self.current_users, self.autoinstall) |
940 | + |
941 | |
942 | class WebLiveEverythingServer(WebLiveServer): |
943 | - def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall, locales, packages): |
944 | + def __init__(self, name, title, description, timelimit, userlimit, |
945 | + users, autoinstall, locales, packages): |
946 | self.locales = [WebLiveLocale(x[0], x[1]) for x in locales] |
947 | self.packages = [WebLivePackage(x[0], x[1], x[2]) for x in packages] |
948 | |
949 | - WebLiveServer.__init__(self, name, title, description, timelimit, userlimit, users, autoinstall) |
950 | + WebLiveServer.__init__(self, name, title, description, timelimit, |
951 | + userlimit, users, autoinstall) |
952 | |
953 | def __repr__(self): |
954 | - return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s" % ( |
955 | - self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall, len(self.locales), len(self.packages)) |
956 | + return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, " |
957 | + "current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s") % ( |
958 | + self.name, self.title, self.description, self.timelimit, |
959 | + self.userlimit, self.current_users, self.autoinstall, |
960 | + len(self.locales), len(self.packages)) |
961 | + |
962 | |
963 | class WebLive: |
964 | - def __init__(self,url,as_object=False): |
965 | - self.url=url |
966 | - self.as_object=as_object |
967 | + def __init__(self, url, as_object=False): |
968 | + self.url = url |
969 | + self.as_object = as_object |
970 | |
971 | - def do_query(self,query): |
972 | - page=urllib2.Request(self.url,urllib.urlencode({'query':json.dumps(query)})) |
973 | + def do_query(self, query): |
974 | + page = urllib2.Request(self.url, urllib.urlencode( |
975 | + {'query': json.dumps(query)})) |
976 | |
977 | try: |
978 | - response=urllib2.urlopen(page) |
979 | + response = urllib2.urlopen(page) |
980 | except urllib2.HTTPError, e: |
981 | raise WebLiveJsonError("HTTP return code: %s" % e.code) |
982 | except urllib2.URLError, e: |
983 | raise WebLiveJsonError("Failed to reach server: %s" % e.reason) |
984 | |
985 | try: |
986 | - reply=json.loads(response.read()) |
987 | + reply = json.loads(response.read()) |
988 | except ValueError: |
989 | raise WebLiveJsonError("Returned json object is invalid.") |
990 | |
991 | @@ -96,37 +115,44 @@ |
992 | elif reply['message'] == -2: |
993 | raise WebLiveJsonError("Missing parameter") |
994 | elif reply['message'] == -3: |
995 | - raise WebLiveJsonError("Function '%s' isn't exported over JSON." % query['action']) |
996 | + raise WebLiveJsonError("Function '%s' isn't exported " |
997 | + "over JSON." % query['action']) |
998 | else: |
999 | - raise WebLiveJsonError("Unknown error code: %s" % reply['message']) |
1000 | + raise WebLiveJsonError("Unknown error code: %s" % |
1001 | + reply['message']) |
1002 | |
1003 | if 'message' not in reply: |
1004 | raise WebLiveJsonError("Invalid json reply") |
1005 | |
1006 | return reply |
1007 | |
1008 | - def create_user(self,serverid,username,fullname,password,session,locale): |
1009 | - query={} |
1010 | - query['action']='create_user' |
1011 | - query['serverid']=serverid |
1012 | - query['username']=username |
1013 | - query['fullname']=fullname |
1014 | - query['password']=password |
1015 | - query['session']=session |
1016 | - query['locale']=locale |
1017 | - reply=self.do_query(query) |
1018 | + def create_user(self, serverid, username, fullname, password, |
1019 | + session, locale): |
1020 | + query = {} |
1021 | + query['action'] = 'create_user' |
1022 | + query['serverid'] = serverid |
1023 | + query['username'] = username |
1024 | + query['fullname'] = fullname |
1025 | + query['password'] = password |
1026 | + query['session'] = session |
1027 | + query['locale'] = locale |
1028 | + reply = self.do_query(query) |
1029 | |
1030 | if type(reply['message']) != type([]): |
1031 | if reply['message'] == 1: |
1032 | raise WebLiveError("Reached user limit, return false.") |
1033 | elif reply['message'] == 2: |
1034 | - raise WebLiveError("Different user with same username already exists.") |
1035 | + raise WebLiveError("Different user with same username " |
1036 | + "already exists.") |
1037 | elif reply['message'] == 3: |
1038 | - raise WebLiveError("Invalid fullname, must only contain alphanumeric characters and spaces.") |
1039 | + raise WebLiveError("Invalid fullname, must only contain " |
1040 | + "alphanumeric characters and spaces.") |
1041 | elif reply['message'] == 4: |
1042 | - raise WebLiveError("Invalid login, must only contain lowercase letters.") |
1043 | + raise WebLiveError("Invalid login, must only contain " |
1044 | + "lowercase letters.") |
1045 | elif reply['message'] == 5: |
1046 | - raise WebLiveError("Invalid password, must contain only alphanumeric characters.") |
1047 | + raise WebLiveError("Invalid password, must contain only " |
1048 | + "alphanumeric characters.") |
1049 | elif reply['message'] == 7: |
1050 | raise WebLiveError("Invalid server: %s" % serverid) |
1051 | else: |
1052 | @@ -135,20 +161,20 @@ |
1053 | return reply['message'] |
1054 | |
1055 | def list_everything(self): |
1056 | - query={} |
1057 | - query['action']='list_everything' |
1058 | - reply=self.do_query(query) |
1059 | + query = {} |
1060 | + query['action'] = 'list_everything' |
1061 | + reply = self.do_query(query) |
1062 | |
1063 | if type(reply['message']) != type({}): |
1064 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
1065 | - % (type({}),type(reply['message']))) |
1066 | + % (type({}), type(reply['message']))) |
1067 | |
1068 | if not self.as_object: |
1069 | return reply['message'] |
1070 | else: |
1071 | - servers=[] |
1072 | + servers = [] |
1073 | for server in reply['message']: |
1074 | - attr=reply['message'][server] |
1075 | + attr = reply['message'][server] |
1076 | servers.append(WebLiveEverythingServer( |
1077 | server, |
1078 | attr['title'], |
1079 | @@ -161,15 +187,15 @@ |
1080 | attr['packages'])) |
1081 | return servers |
1082 | |
1083 | - def list_locales(self,serverid): |
1084 | - query={} |
1085 | - query['action']='list_locales' |
1086 | - query['serverid']=serverid |
1087 | - reply=self.do_query(query) |
1088 | + def list_locales(self, serverid): |
1089 | + query = {} |
1090 | + query['action'] = 'list_locales' |
1091 | + query['serverid'] = serverid |
1092 | + reply = self.do_query(query) |
1093 | |
1094 | if type(reply['message']) != type([]): |
1095 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
1096 | - % (type({}),type(reply['message']))) |
1097 | + % (type({}), type(reply['message']))) |
1098 | |
1099 | if not self.as_object: |
1100 | return reply['message'] |
1101 | @@ -177,28 +203,28 @@ |
1102 | return [WebLiveLocale(x[0], x[1]) for x in reply['message']] |
1103 | |
1104 | def list_package_blacklist(self): |
1105 | - query={} |
1106 | - query['action']='list_package_blacklist' |
1107 | - reply=self.do_query(query) |
1108 | + query = {} |
1109 | + query['action'] = 'list_package_blacklist' |
1110 | + reply = self.do_query(query) |
1111 | |
1112 | if type(reply['message']) != type([]): |
1113 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
1114 | - % (type({}),type(reply['message']))) |
1115 | + % (type({}), type(reply['message']))) |
1116 | |
1117 | if not self.as_object: |
1118 | return reply['message'] |
1119 | else: |
1120 | return [WebLivePackage(x, None, None) for x in reply['message']] |
1121 | |
1122 | - def list_packages(self,serverid): |
1123 | - query={} |
1124 | - query['action']='list_packages' |
1125 | - query['serverid']=serverid |
1126 | - reply=self.do_query(query) |
1127 | + def list_packages(self, serverid): |
1128 | + query = {} |
1129 | + query['action'] = 'list_packages' |
1130 | + query['serverid'] = serverid |
1131 | + reply = self.do_query(query) |
1132 | |
1133 | if type(reply['message']) != type([]): |
1134 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
1135 | - % (type({}),type(reply['message']))) |
1136 | + % (type({}), type(reply['message']))) |
1137 | |
1138 | if not self.as_object: |
1139 | return reply['message'] |
1140 | @@ -206,20 +232,20 @@ |
1141 | return [WebLivePackage(x[0], x[1], x[2]) for x in reply['message']] |
1142 | |
1143 | def list_servers(self): |
1144 | - query={} |
1145 | - query['action']='list_servers' |
1146 | - reply=self.do_query(query) |
1147 | + query = {} |
1148 | + query['action'] = 'list_servers' |
1149 | + reply = self.do_query(query) |
1150 | |
1151 | if type(reply['message']) != type({}): |
1152 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
1153 | - % (type({}),type(reply['message']))) |
1154 | + % (type({}), type(reply['message']))) |
1155 | |
1156 | if not self.as_object: |
1157 | return reply['message'] |
1158 | else: |
1159 | - servers=[] |
1160 | + servers = [] |
1161 | for server in reply['message']: |
1162 | - attr=reply['message'][server] |
1163 | + attr = reply['message'][server] |
1164 | servers.append(WebLiveServer( |
1165 | server, |
1166 | attr['title'], |
1167 | |
1168 | === modified file 'softwarecenter/backend/zeitgeist_simple.py' |
1169 | --- softwarecenter/backend/zeitgeist_simple.py 2011-09-15 13:51:15 +0000 |
1170 | +++ softwarecenter/backend/zeitgeist_simple.py 2012-03-19 13:59:07 +0000 |
1171 | @@ -30,6 +30,7 @@ |
1172 | else: |
1173 | ZEITGEIST_AVAILABLE = True |
1174 | |
1175 | + |
1176 | class SoftwareCenterZeitgeist(): |
1177 | """ simple wrapper around zeitgeist """ |
1178 | |
1179 | @@ -39,7 +40,7 @@ |
1180 | except Exception as e: |
1181 | logging.warn("can not get zeitgeist client: '%s'" % e) |
1182 | self.zg_client = None |
1183 | - |
1184 | + |
1185 | def get_usage_counter(self, application, callback, timerange=None): |
1186 | """Request the usage count as integer for the given application. |
1187 | When the request is there, "callback" is called. A optional |
1188 | @@ -54,7 +55,7 @@ |
1189 | callback(0) |
1190 | return |
1191 | # the app we are looking for |
1192 | - application = "application://"+application.split("/")[-1] |
1193 | + application = "application://" + application.split("/")[-1] |
1194 | # the event_templates |
1195 | e1 = Event.new_for_values( |
1196 | actor=application, interpretation=Interpretation.MODIFY_EVENT.uri) |
1197 | @@ -63,11 +64,11 @@ |
1198 | # run it |
1199 | self.zg_client.find_event_ids_for_templates( |
1200 | [e1, e2], _callback, timerange=timerange, num_events=0) |
1201 | - |
1202 | + |
1203 | def get_popular_mimetypes(self, callback, num=3): |
1204 | """ get the "num" (default to 3) most popular mimetypes based |
1205 | on the last 1000 events that zeitgeist recorded and |
1206 | - call "callback" with [(count1, "mime1"), (count2, "mime2"), ...] |
1207 | + call "callback" with [(count1, "mime1"), (count2, "mime2"), ...] |
1208 | as arguement |
1209 | """ |
1210 | def _callback(events): |
1211 | @@ -87,7 +88,7 @@ |
1212 | # convert to result and sort |
1213 | for k, v in mimetypes.items(): |
1214 | results.append([v, k]) |
1215 | - results.sort(reverse = True) |
1216 | + results.sort(reverse=True) |
1217 | # tell the client about it |
1218 | callback(results[:num]) |
1219 | # no zeitgeist |
1220 | @@ -97,12 +98,14 @@ |
1221 | # FIXME: investigate how result_type MostRecentEvents or |
1222 | # MostRecentSubjects would affect the results |
1223 | self.zg_client.find_events_for_templates( |
1224 | - [], _callback, num_events=1000, |
1225 | + [], _callback, num_events=1000, |
1226 | result_type=ResultType.MostRecentEvents) |
1227 | |
1228 | + |
1229 | class SoftwareCenterZeitgeistDummy(): |
1230 | def get_usage_counter(self, application, callback, timerange=None): |
1231 | callback(0) |
1232 | + |
1233 | def get_popular_mimetypes(self, callback): |
1234 | callback([]) |
1235 | |
1236 | @@ -121,15 +124,15 @@ |
1237 | |
1238 | # yesterday gedit |
1239 | end = time.time() |
1240 | - start = end - 24*60*60 |
1241 | + start = end - 24 * 60 * 60 |
1242 | zeitgeist_singleton.get_usage_counter("gedit.desktop", _callback_counter, |
1243 | timerange=[start, end]) |
1244 | - |
1245 | + |
1246 | # most popular |
1247 | def _callback_popular(mimetypes): |
1248 | print("test _callback: ") |
1249 | for tuple in mimetypes: |
1250 | - print(tuple) |
1251 | + print(tuple) |
1252 | zeitgeist_singleton.get_popular_mimetypes(_callback_popular) |
1253 | |
1254 | from gi.repository import Gtk |
1255 | |
1256 | === modified file 'test/test_pep8.py' |
1257 | --- test/test_pep8.py 2012-03-16 20:12:57 +0000 |
1258 | +++ test/test_pep8.py 2012-03-19 13:59:07 +0000 |
1259 | @@ -7,10 +7,7 @@ |
1260 | setup_test_env() |
1261 | |
1262 | # Only test these two packages for now: |
1263 | -import softwarecenter.backend.reviews |
1264 | -import softwarecenter.backend.oneconfhandler |
1265 | -import softwarecenter.backend.piston |
1266 | -import softwarecenter.backend.installbackend_impl |
1267 | +import softwarecenter.backend |
1268 | import softwarecenter.db |
1269 | import softwarecenter.ui |
1270 | import softwarecenter.distro |
1271 | @@ -18,14 +15,13 @@ |
1272 | class PackagePep8TestCase(unittest.TestCase): |
1273 | maxDiff = None |
1274 | packages = [softwarecenter.ui, |
1275 | - softwarecenter.backend.piston, |
1276 | - softwarecenter.backend.installbackend_impl, |
1277 | - softwarecenter.backend.reviews, |
1278 | - softwarecenter.backend.oneconfhandler, |
1279 | + softwarecenter.backend, |
1280 | softwarecenter.db, |
1281 | softwarecenter.distro, |
1282 | ] |
1283 | - exclude = [] |
1284 | + exclude = ['scagent.py', 'recagent.py', 'login_sso.py', 'login.py', |
1285 | + 'launchpad.py', 'installbackend.py', 'fake_review_settings.py', |
1286 | + 'channel.py'] |
1287 | |
1288 | def message(self, text): |
1289 | self.errors.append(text) |