Merge lp:~elachuni/software-center/pep8-test-part16 into lp:software-center
- pep8-test-part16
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2862 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part16 |
Merge into: | lp:software-center |
Prerequisite: | lp:~elachuni/software-center/pep8-test-part15 |
Diff against target: |
1252 lines (+267/-159) 6 files modified
softwarecenter/db/history_impl/apthistory.py (+22/-19) softwarecenter/db/history_impl/packagekit.py (+11/-7) softwarecenter/db/pkginfo.py (+57/-18) softwarecenter/db/update.py (+164/-104) softwarecenter/db/utils.py (+7/-4) test/test_pep8.py (+6/-7) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part16 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
software-store-developers | Pending | ||
Review via email: mp+97568@code.launchpad.net |
Commit message
Description of the change
Made several files under softwarecenter/db/ pass the pep8 test.
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/db/history_impl/apthistory.py' |
2 | --- softwarecenter/db/history_impl/apthistory.py 2011-12-02 14:30:56 +0000 |
3 | +++ softwarecenter/db/history_impl/apthistory.py 2012-03-15 04:06:19 +0000 |
4 | @@ -33,7 +33,7 @@ |
5 | |
6 | try: |
7 | import cPickle as pickle |
8 | - pickle # pyflakes |
9 | + pickle # pyflakes |
10 | except ImportError: |
11 | import pickle |
12 | |
13 | @@ -43,20 +43,22 @@ |
14 | from softwarecenter.utils import ExecutionTime |
15 | from softwarecenter.db.history import Transaction, PackageHistory |
16 | |
17 | + |
18 | def ascii_lower(key): |
19 | ascii_trans_table = string.maketrans(string.ascii_uppercase, |
20 | string.ascii_lowercase) |
21 | return key.translate(ascii_trans_table) |
22 | |
23 | + |
24 | class AptTransaction(Transaction): |
25 | - PKGACTIONS=["Install", "Upgrade", "Downgrade", "Remove", "Purge"] |
26 | + PKGACTIONS = ["Install", "Upgrade", "Downgrade", "Remove", "Purge"] |
27 | |
28 | def __init__(self, sec): |
29 | self.start_date = datetime.strptime(sec["Start-Date"], |
30 | "%Y-%m-%d %H:%M:%S") |
31 | # set the object attributes "install", "upgrade", "downgrade", |
32 | # "remove", "purge", error |
33 | - for k in self.PKGACTIONS+["Error"]: |
34 | + for k in self.PKGACTIONS + ["Error"]: |
35 | # we use ascii_lower for issues described in LP: #581207 |
36 | attr = ascii_lower(k) |
37 | if k in sec: |
38 | @@ -68,13 +70,14 @@ |
39 | @staticmethod |
40 | def _fixup_history_item(s): |
41 | """ strip history item string and add missing ")" if needed """ |
42 | - s=s.strip() |
43 | + s = s.strip() |
44 | # remove the infomation about the architecture |
45 | s = re.sub(":\w+", "", s) |
46 | if "(" in s and not s.endswith(")"): |
47 | - s+=")" |
48 | + s += ")" |
49 | return s |
50 | |
51 | + |
52 | class AptHistory(PackageHistory): |
53 | |
54 | def __init__(self, use_cache=True): |
55 | @@ -95,6 +98,7 @@ |
56 | @property |
57 | def transactions(self): |
58 | return self._transactions |
59 | + |
60 | @property |
61 | def history_ready(self): |
62 | return self._history_ready |
63 | @@ -114,7 +118,7 @@ |
64 | cachetime = os.path.getmtime(p) |
65 | except: |
66 | LOG.exception("failed to load cache") |
67 | - for history_gz_file in sorted(glob.glob(self.history_file+".*.gz"), |
68 | + for history_gz_file in sorted(glob.glob(self.history_file + ".*.gz"), |
69 | cmp=self._mtime_cmp): |
70 | if os.path.getmtime(history_gz_file) < cachetime: |
71 | LOG.debug("skipping already cached '%s'" % history_gz_file) |
72 | @@ -124,8 +128,8 @@ |
73 | if use_cache: |
74 | pickle.dump(self._transactions, open(p, "w")) |
75 | self._history_ready = True |
76 | - |
77 | - def _scan(self, history_file, rescan = False): |
78 | + |
79 | + def _scan(self, history_file, rescan=False): |
80 | LOG.debug("_scan: '%s' (%s)" % (history_file, rescan)) |
81 | try: |
82 | tagfile = apt_pkg.TagFile(open(history_file)) |
83 | @@ -136,7 +140,7 @@ |
84 | # keep the UI alive |
85 | while self.main_context.pending(): |
86 | self.main_context.iteration() |
87 | - # ignore records with |
88 | + # ignore records with |
89 | try: |
90 | trans = AptTransaction(stanza) |
91 | except (KeyError, ValueError): |
92 | @@ -151,16 +155,16 @@ |
93 | # so we could (and should) do a binary search |
94 | if not trans in self._transactions: |
95 | self._transactions.insert(0, trans) |
96 | - |
97 | + |
98 | def _on_apt_history_changed(self, monitor, afile, other_file, event): |
99 | - if event == Gio.FileMonitorEvent.CHANGES_DONE_HINT: |
100 | - self._scan(self.history_file, rescan = True) |
101 | + if event == Gio.FileMonitorEvent.CHANGES_DONE_HINT: |
102 | + self._scan(self.history_file, rescan=True) |
103 | if self.update_callback: |
104 | self.update_callback() |
105 | - |
106 | - def set_on_update(self,update_callback): |
107 | - self.update_callback=update_callback |
108 | - |
109 | + |
110 | + def set_on_update(self, update_callback): |
111 | + self.update_callback = update_callback |
112 | + |
113 | def get_installed_date(self, pkg_name): |
114 | installed_date = None |
115 | for trans in self._transactions: |
116 | @@ -169,7 +173,7 @@ |
117 | installed_date = trans.start_date |
118 | return installed_date |
119 | return installed_date |
120 | - |
121 | + |
122 | def _find_in_terminal_log(self, date, term_file): |
123 | found = False |
124 | term_lines = [] |
125 | @@ -191,9 +195,8 @@ |
126 | term_lines = self._find_in_terminal_log(date, open(term)) |
127 | # now search the older history |
128 | if not term_lines: |
129 | - for f in glob.glob(term+".*.gz"): |
130 | + for f in glob.glob(term + ".*.gz"): |
131 | term_lines = self._find_in_terminal_log(date, gzip.open(f)) |
132 | if term_lines: |
133 | return term_lines |
134 | return term_lines |
135 | - |
136 | |
137 | === modified file 'softwarecenter/db/history_impl/packagekit.py' |
138 | --- softwarecenter/db/history_impl/packagekit.py 2011-12-02 14:30:56 +0000 |
139 | +++ softwarecenter/db/history_impl/packagekit.py 2012-03-15 04:06:19 +0000 |
140 | @@ -22,6 +22,7 @@ |
141 | |
142 | LOG = logging.getLogger(__name__) |
143 | |
144 | + |
145 | class PackagekitTransaction(Transaction): |
146 | def __init__(self, pktrans): |
147 | self.start_date = datetime.strptime(pktrans.props.timespec, |
148 | @@ -31,7 +32,8 @@ |
149 | self.upgrade = [] |
150 | self.downgrade = [] |
151 | self.remove = [] |
152 | - self.purge = [] # can't happen with a Packagekit backend (is mapped to remove) |
153 | + self.purge = [] # can't happen with a Packagekit backend (is mapped |
154 | + # to remove) |
155 | |
156 | # parse transaction data |
157 | lines = pktrans.props.data.split('\n') |
158 | @@ -51,13 +53,15 @@ |
159 | elif action == 'removing': |
160 | self.remove.append(package_name) |
161 | else: |
162 | - # ignore other actions (include cleanup, downloading and untrusted) |
163 | + # ignore other actions (include cleanup, downloading and |
164 | + # untrusted) |
165 | continue |
166 | except: |
167 | LOG.warn("malformed line emitted by PackageKit, was %s" % line) |
168 | |
169 | + |
170 | class PackagekitHistory(PackageHistory): |
171 | - """ Represents the history of the transactions """ |
172 | + """ Represents the history of the transactions """ |
173 | |
174 | def __init__(self, use_cache=True): |
175 | self._use_cache = use_cache |
176 | @@ -66,9 +70,9 @@ |
177 | |
178 | self._client = PackageKitGlib.Client() |
179 | self._client.get_old_transactions_async(0, |
180 | - None, # cancellable |
181 | - lambda *args, **kwargs: None, None, # progress callback |
182 | - self._transactions_received, None) |
183 | + None, # cancellable |
184 | + lambda *args, **kwargs: None, None, # progress callback |
185 | + self._transactions_received, None) |
186 | |
187 | @property |
188 | def history_ready(self): |
189 | @@ -86,7 +90,7 @@ |
190 | |
191 | def get_installed_date(self, pkg_name): |
192 | """Return the date that the given package name got instaled """ |
193 | - return None |
194 | + pass |
195 | |
196 | def _transactions_received(self, client, async_result, user_data): |
197 | try: |
198 | |
199 | === modified file 'softwarecenter/db/pkginfo.py' |
200 | --- softwarecenter/db/pkginfo.py 2012-02-14 09:51:45 +0000 |
201 | +++ softwarecenter/db/pkginfo.py 2012-03-15 04:06:19 +0000 |
202 | @@ -18,28 +18,36 @@ |
203 | |
204 | from gi.repository import GObject |
205 | |
206 | + |
207 | class _Version: |
208 | @property |
209 | def description(self): |
210 | pass |
211 | + |
212 | @property |
213 | def downloadable(self): |
214 | pass |
215 | + |
216 | @property |
217 | def summary(self): |
218 | pass |
219 | + |
220 | @property |
221 | def size(self): |
222 | return self.pkginfo.get_size(self.name) |
223 | + |
224 | @property |
225 | def installed_size(self): |
226 | return 0 |
227 | + |
228 | @property |
229 | def version(self): |
230 | pass |
231 | + |
232 | @property |
233 | def origins(self): |
234 | return [] |
235 | + |
236 | @property |
237 | def not_automatic(self): |
238 | """ should not be installed/upgraded automatically, the user needs |
239 | @@ -47,22 +55,26 @@ |
240 | """ |
241 | return False |
242 | |
243 | + |
244 | class _Package: |
245 | def __init__(self, name, pkginfo): |
246 | self.name = name |
247 | self.pkginfo = pkginfo |
248 | + |
249 | def __str__(self): |
250 | - return repr(self).replace('<', '<pkgname=%s ' % self.name) |
251 | + return repr(self).replace('<', '<pkgname=%s ' % self.name) |
252 | + |
253 | @property |
254 | def installed(self): |
255 | """ returns a _Version object """ |
256 | - if not self.pkginfo.is_installed(self.name): |
257 | - return None |
258 | - return self.pkginfo.get_installed(self.name) |
259 | + if self.pkginfo.is_installed(self.name): |
260 | + return self.pkginfo.get_installed(self.name) |
261 | + |
262 | @property |
263 | def candidate(self): |
264 | """ returns a _Version object """ |
265 | return self.pkginfo.get_candidate(self.name) |
266 | + |
267 | @property |
268 | def versions(self): |
269 | """ a list of available versions (as _Version) to install """ |
270 | @@ -71,18 +83,23 @@ |
271 | @property |
272 | def is_installed(self): |
273 | return self.pkginfo.is_installed(self.name) |
274 | + |
275 | @property |
276 | def is_upgradable(self): |
277 | return self.pkginfo.is_upgradable(self.name) |
278 | + |
279 | @property |
280 | def section(self): |
281 | return self.pkginfo.get_section(self.name) |
282 | + |
283 | @property |
284 | def website(self): |
285 | return self.pkginfo.get_website(self.name) |
286 | + |
287 | @property |
288 | def installed_files(self): |
289 | return self.pkginfo.get_installed_files(self.name) |
290 | + |
291 | @property |
292 | def description(self): |
293 | return self.pkginfo.get_description(self.name) |
294 | @@ -91,22 +108,24 @@ |
295 | def license(self): |
296 | return self.pkginfo.get_license(self.name) |
297 | |
298 | + |
299 | class PackageInfo(GObject.GObject): |
300 | """ abstract interface for the packageinfo information """ |
301 | |
302 | - __gsignals__ = {'cache-ready': (GObject.SIGNAL_RUN_FIRST, |
303 | - GObject.TYPE_NONE, |
304 | - ()), |
305 | - 'cache-invalid':(GObject.SIGNAL_RUN_FIRST, |
306 | - GObject.TYPE_NONE, |
307 | - ()), |
308 | - 'cache-broken':(GObject.SIGNAL_RUN_FIRST, |
309 | - GObject.TYPE_NONE, |
310 | - ()), |
311 | + __gsignals__ = {'cache-ready': (GObject.SIGNAL_RUN_FIRST, |
312 | + GObject.TYPE_NONE, |
313 | + ()), |
314 | + 'cache-invalid': (GObject.SIGNAL_RUN_FIRST, |
315 | + GObject.TYPE_NONE, |
316 | + ()), |
317 | + 'cache-broken': (GObject.SIGNAL_RUN_FIRST, |
318 | + GObject.TYPE_NONE, |
319 | + ()), |
320 | } |
321 | |
322 | def __getitem__(self, k): |
323 | return _Package(k, self) |
324 | + |
325 | def __contains__(self, pkgname): |
326 | return False |
327 | |
328 | @@ -114,10 +133,12 @@ |
329 | def version_compare(v1, v2): |
330 | """ compare two versions """ |
331 | return cmp(v1, v2) |
332 | + |
333 | @staticmethod |
334 | def upstream_version_compare(v1, v2): |
335 | """ compare two versions, but ignore the distro specific revisions """ |
336 | return cmp(v1, v2) |
337 | + |
338 | @staticmethod |
339 | def upstream_version(v): |
340 | """ Return the "upstream" version number of the given version """ |
341 | @@ -125,34 +146,47 @@ |
342 | |
343 | def is_installed(self, pkgname): |
344 | pass |
345 | + |
346 | def is_available(self, pkgname): |
347 | pass |
348 | + |
349 | def get_installed(self, pkgname): |
350 | pass |
351 | + |
352 | def get_candidate(self, pkgname): |
353 | pass |
354 | + |
355 | def get_versions(self, pkgname): |
356 | return [] |
357 | |
358 | def get_section(self, pkgname): |
359 | pass |
360 | + |
361 | def get_summary(self, pkgname): |
362 | pass |
363 | + |
364 | def get_description(self, pkgname): |
365 | pass |
366 | + |
367 | def get_website(self, pkgname): |
368 | pass |
369 | + |
370 | def get_installed_files(self, pkgname): |
371 | return [] |
372 | + |
373 | def get_size(self, pkgname): |
374 | return -1 |
375 | + |
376 | def get_installed_size(self, pkgname): |
377 | return -1 |
378 | + |
379 | def get_origins(self, pkgname): |
380 | return [] |
381 | + |
382 | def get_origin(self, pkgname): |
383 | """ :return: unique origin as string """ |
384 | return '' |
385 | + |
386 | def get_addons(self, pkgname, ignore_installed=False): |
387 | """ :return: a tuple of pkgnames (recommends, suggests) """ |
388 | return ([], []) |
389 | @@ -167,27 +201,30 @@ |
390 | which will be removed if the package is installed.""" |
391 | return [] |
392 | |
393 | - def get_total_size_on_install(self, pkgname, |
394 | + def get_total_size_on_install(self, pkgname, |
395 | addons_install=None, addons_remove=None, |
396 | archive_suite=None): |
397 | """ Returns a tuple (download_size, installed_size) |
398 | with disk size in KB calculated for pkgname installation |
399 | - plus addons change and a (optional) archive_suite that the |
400 | + plus addons change and a (optional) archive_suite that the |
401 | package comes from |
402 | """ |
403 | return (0, 0) |
404 | |
405 | def open(self): |
406 | - """ |
407 | + """ |
408 | (re)open the cache, this sends cache-invalid, cache-ready signals |
409 | """ |
410 | pass |
411 | + |
412 | @property |
413 | def ready(self): |
414 | pass |
415 | |
416 | # singleton |
417 | pkginfo = None |
418 | + |
419 | + |
420 | def get_pkg_info(): |
421 | global pkginfo |
422 | if pkginfo is None: |
423 | @@ -196,6 +233,8 @@ |
424 | from softwarecenter.db.pkginfo_impl.aptcache import AptCache |
425 | pkginfo = AptCache() |
426 | else: |
427 | - from softwarecenter.db.pkginfo_impl.packagekit import PackagekitInfo |
428 | - pkginfo = PackagekitInfo() |
429 | + from softwarecenter.db.pkginfo_impl.packagekit import ( |
430 | + PackagekitInfo, |
431 | + ) |
432 | + pkginfo = PackagekitInfo() |
433 | return pkginfo |
434 | |
435 | === modified file 'softwarecenter/db/update.py' |
436 | --- softwarecenter/db/update.py 2012-02-28 22:35:19 +0000 |
437 | +++ softwarecenter/db/update.py 2012-03-15 04:06:19 +0000 |
438 | @@ -36,15 +36,15 @@ |
439 | # py3 compat |
440 | try: |
441 | from configparser import RawConfigParser, NoOptionError |
442 | - RawConfigParser # pyflakes |
443 | - NoOptionError # pyflakes |
444 | + RawConfigParser # pyflakes |
445 | + NoOptionError # pyflakes |
446 | except ImportError: |
447 | from ConfigParser import RawConfigParser, NoOptionError |
448 | |
449 | # py3 compat |
450 | try: |
451 | import cPickle as pickle |
452 | - pickle # pyflakes |
453 | + pickle # pyflakes |
454 | except ImportError: |
455 | import pickle |
456 | |
457 | @@ -101,6 +101,7 @@ |
458 | # Enable Xapian's CJK tokenizer (see LP: #745243) |
459 | os.environ['XAPIAN_CJK_NGRAM'] = '1' |
460 | |
461 | + |
462 | class AppInfoParserBase(object): |
463 | """ base class for reading AppInfo meta-data """ |
464 | |
465 | @@ -108,8 +109,10 @@ |
466 | |
467 | def get_desktop(self, key, translated=True): |
468 | """ get a AppInfo entry for the given key """ |
469 | + |
470 | def has_option_desktop(self, key): |
471 | """ return True if there is a given AppInfo info """ |
472 | + |
473 | def _get_desktop_list(self, key, split_str=";"): |
474 | result = [] |
475 | try: |
476 | @@ -120,6 +123,7 @@ |
477 | except (NoOptionError, KeyError): |
478 | pass |
479 | return result |
480 | + |
481 | def _apply_mapping(self, key): |
482 | # strip away bogus prefixes |
483 | if key.startswith("X-AppInstall-"): |
484 | @@ -127,12 +131,15 @@ |
485 | if key in self.MAPPING: |
486 | return self.MAPPING[key] |
487 | return key |
488 | + |
489 | def get_desktop_categories(self): |
490 | return self._get_desktop_list("Categories") |
491 | + |
492 | def get_desktop_mimetypes(self): |
493 | if not self.has_option_desktop("MimeType"): |
494 | return [] |
495 | return self._get_desktop_list("MimeType") |
496 | + |
497 | @property |
498 | def desktopf(self): |
499 | """ return the file that the AppInfo comes from """ |
500 | @@ -142,29 +149,29 @@ |
501 | """ map the data we get from the software-center-agent """ |
502 | |
503 | # map from requested key to sca_application attribute |
504 | - MAPPING = { 'Name' : 'name', |
505 | - 'Price' : 'price', |
506 | - 'Package' : 'package_name', |
507 | - 'Categories' : 'categories', |
508 | - 'Channel' : 'channel', |
509 | - 'Signing-Key-Id' : 'signing_key_id', |
510 | - 'License' : 'license', |
511 | - 'Date-Published' : 'date_published', |
512 | - 'PPA' : 'archive_id', |
513 | - 'Screenshot-Url' : 'screenshot_url', |
514 | - 'Thumbnail-Url' : 'thumbnail_url', |
515 | - 'Video-Url' : 'video_embedded_html_url', |
516 | - 'Icon-Url' : 'icon_url', |
517 | - 'Support-Url' : 'support_url', |
518 | - 'Description' : 'Description', |
519 | - 'Comment' : 'Comment', |
520 | - 'Version' : 'version', |
521 | - 'Supported-Distros': 'series', |
522 | - # tags are special, see _apply_exception |
523 | + MAPPING = {'Name': 'name', |
524 | + 'Price': 'price', |
525 | + 'Package': 'package_name', |
526 | + 'Categories': 'categories', |
527 | + 'Channel': 'channel', |
528 | + 'Signing-Key-Id': 'signing_key_id', |
529 | + 'License': 'license', |
530 | + 'Date-Published': 'date_published', |
531 | + 'PPA': 'archive_id', |
532 | + 'Screenshot-Url': 'screenshot_url', |
533 | + 'Thumbnail-Url': 'thumbnail_url', |
534 | + 'Video-Url': 'video_embedded_html_url', |
535 | + 'Icon-Url': 'icon_url', |
536 | + 'Support-Url': 'support_url', |
537 | + 'Description': 'Description', |
538 | + 'Comment': 'Comment', |
539 | + 'Version': 'version', |
540 | + 'Supported-Distros': 'series', |
541 | + # tags are special, see _apply_exception |
542 | } |
543 | |
544 | # map from requested key to a static data element |
545 | - STATIC_DATA = { 'Type' : 'Application', |
546 | + STATIC_DATA = {'Type': 'Application', |
547 | } |
548 | |
549 | def __init__(self, sca_application): |
550 | @@ -179,19 +186,23 @@ |
551 | # we no longer keep thumbnail versions of screenshots on the server |
552 | if (hasattr(self.sca_application, "screenshot_url") and |
553 | not hasattr(self.sca_application, "thumbnail_url")): |
554 | - self.sca_application.thumbnail_url = self.sca_application.screenshot_url |
555 | + self.sca_application.thumbnail_url = \ |
556 | + self.sca_application.screenshot_url |
557 | if hasattr(self.sca_application, "description"): |
558 | - self.sca_application.Comment = self.sca_application.description.split("\n")[0].strip() |
559 | + comment = self.sca_application.description.split("\n")[0].strip() |
560 | + self.sca_application.Comment = comment |
561 | self.sca_application.Description = "\n".join( |
562 | self.sca_application.description.split("\n")[1:]).strip() |
563 | |
564 | # debtags is send as a list, but we need it as a comma seperated string |
565 | - self.sca_application.Tags = ",".join(getattr(self.sca_application, "debtags", [])) |
566 | + self.sca_application.Tags = ",".join(getattr(self.sca_application, |
567 | + "debtags", [])) |
568 | |
569 | # we only support a single video currently :/ |
570 | if hasattr(self.sca_application, "video_embedded_html_urls"): |
571 | if self.sca_application.video_embedded_html_urls: |
572 | - self.sca_application.video_embedded_html_url = self.sca_application.video_embedded_html_urls[0] |
573 | + video_url = self.sca_application.video_embedded_html_urls[0] |
574 | + self.sca_application.video_embedded_html_url = video_url |
575 | |
576 | # XXX 2012-01-16 bug=917109 |
577 | # We can remove these work-arounds once the above bug is fixed on |
578 | @@ -199,7 +210,8 @@ |
579 | # to make the parser happy. Note: available_apps api call includes |
580 | # these already, it's just the apps with subscriptions_for_me which |
581 | # don't currently. |
582 | - self.sca_application.channel = AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME |
583 | + self.sca_application.channel = \ |
584 | + AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME |
585 | if not hasattr(self.sca_application, 'categories'): |
586 | self.sca_application.categories = "" |
587 | |
588 | @@ -207,16 +219,16 @@ |
589 | # attribute appropriately so that the channel-adding magic works |
590 | if hasattr(self.sca_application, "archive_root"): |
591 | u = urlparse(self.sca_application.archive_root) |
592 | - if u.scheme == "http" and u.netloc == "archive.canonical.com": |
593 | + if u.scheme == "http" and u.netloc == "archive.canonical.com": |
594 | distroseries = get_distro().get_codename() |
595 | self.sca_application.channel = "%s-partner" % distroseries |
596 | - if u.scheme == "http" and u.netloc == "extras.ubuntu.com": |
597 | + if u.scheme == "http" and u.netloc == "extras.ubuntu.com": |
598 | self.sca_application.channel = "ubuntu-extras" |
599 | - |
600 | + |
601 | # support multiple screenshots |
602 | if hasattr(self.sca_application, "screenshot_urls"): |
603 | # ensure to html-quote "," as this is also our seperator |
604 | - s = ",".join([url.replace(",", "%2C") |
605 | + s = ",".join([url.replace(",", "%2C") |
606 | for url in self.sca_application.screenshot_urls]) |
607 | self.sca_application.screenshot_url = s |
608 | |
609 | @@ -227,7 +239,8 @@ |
610 | |
611 | def get_desktop_categories(self): |
612 | try: |
613 | - return ['DEPARTMENT:' + self.sca_application.department[-1]] + self._get_desktop_list("Categories") |
614 | + return (['DEPARTMENT:' + self.sca_application.department[-1]] + |
615 | + self._get_desktop_list("Categories")) |
616 | except: |
617 | return self._get_desktop_list("Categories") |
618 | |
619 | @@ -251,17 +264,17 @@ |
620 | PistonResponseObject.from_dict(sca_subscription.application)) |
621 | |
622 | SUBSCRIPTION_MAPPING = { |
623 | - # this key can be used to get the original deb_line that the |
624 | + # this key can be used to get the original deb_line that the |
625 | # server returns, it will be at the distroseries that was current |
626 | # at purchase time |
627 | - 'Deb-Line-Orig' : 'deb_line', |
628 | + 'Deb-Line-Orig': 'deb_line', |
629 | # this is what s-c will always use, the deb_line updated to the |
630 | # current distroseries, note that you should ensure that the app |
631 | # is not in state: PkgStates.PURCHASED_BUT_NOT_AVAILABLE_FOR_SERIES |
632 | - 'Deb-Line' : 'deb_line', |
633 | - 'Purchased-Date' : 'purchase_date', |
634 | - 'License-Key' : 'license_key', |
635 | - 'License-Key-Path' : 'license_key_path', |
636 | + 'Deb-Line': 'deb_line', |
637 | + 'Purchased-Date': 'purchase_date', |
638 | + 'License-Key': 'license_key', |
639 | + 'License-Key-Path': 'license_key_path', |
640 | } |
641 | |
642 | MAPPING = dict( |
643 | @@ -313,47 +326,52 @@ |
644 | |
645 | class JsonTagSectionParser(AppInfoParserBase): |
646 | |
647 | - MAPPING = { 'Name' : 'application_name', |
648 | - 'Comment' : 'description', |
649 | - 'Price' : 'price', |
650 | - 'Package' : 'package_name', |
651 | - 'Categories' : 'categories', |
652 | + MAPPING = {'Name': 'application_name', |
653 | + 'Comment': 'description', |
654 | + 'Price': 'price', |
655 | + 'Package': 'package_name', |
656 | + 'Categories': 'categories', |
657 | } |
658 | |
659 | def __init__(self, tag_section, url): |
660 | self.tag_section = tag_section |
661 | self.url = url |
662 | + |
663 | def get_desktop(self, key, translated=True): |
664 | return self.tag_section[self._apply_mapping(key)] |
665 | + |
666 | def has_option_desktop(self, key): |
667 | return self._apply_mapping(key) in self.tag_section |
668 | + |
669 | @property |
670 | def desktopf(self): |
671 | return self.url |
672 | |
673 | + |
674 | class AppStreamXMLParser(AppInfoParserBase): |
675 | |
676 | - MAPPING = { 'Name' : 'name', |
677 | - 'Comment' : 'summary', |
678 | - 'Package' : 'pkgname', |
679 | - 'Categories' : 'appcategories', |
680 | - 'Keywords' : 'keywords', |
681 | - 'MimeType' : 'mimetypes', |
682 | - 'Icon' : 'icon', |
683 | + MAPPING = {'Name': 'name', |
684 | + 'Comment': 'summary', |
685 | + 'Package': 'pkgname', |
686 | + 'Categories': 'appcategories', |
687 | + 'Keywords': 'keywords', |
688 | + 'MimeType': 'mimetypes', |
689 | + 'Icon': 'icon', |
690 | } |
691 | |
692 | - LISTS = { "appcategories" : "appcategory", |
693 | - "keywords" : "keyword", |
694 | - "mimetypes" : "mimetype", |
695 | + LISTS = {"appcategories": "appcategory", |
696 | + "keywords": "keyword", |
697 | + "mimetypes": "mimetype", |
698 | } |
699 | |
700 | # map from requested key to a static data element |
701 | - STATIC_DATA = { 'Type' : 'Application', |
702 | + STATIC_DATA = {'Type': 'Application', |
703 | } |
704 | |
705 | def __init__(self, appinfo_xml, xmlfile): |
706 | self.appinfo_xml = appinfo_xml |
707 | self.xmlfile = xmlfile |
708 | + |
709 | def get_desktop(self, key, translated=True): |
710 | if key in self.STATIC_DATA: |
711 | return self.STATIC_DATA[key] |
712 | @@ -362,14 +380,18 @@ |
713 | return self._parse_with_lists(key) |
714 | else: |
715 | return self._parse_value(key, translated) |
716 | + |
717 | def get_desktop_categories(self): |
718 | return self._get_desktop_list("Categories", split_str=',') |
719 | + |
720 | def get_desktop_mimetypes(self): |
721 | if not self.has_option_desktop("MimeType"): |
722 | return [] |
723 | return self._get_desktop_list("MimeType", split_str=',') |
724 | + |
725 | def _parse_value(self, key, translated): |
726 | - locale = getdefaultlocale(('LANGUAGE','LANG','LC_CTYPE','LC_ALL'))[0] |
727 | + locale = getdefaultlocale(('LANGUAGE', 'LANG', 'LC_CTYPE', |
728 | + 'LC_ALL'))[0] |
729 | for child in self.appinfo_xml.iter(key): |
730 | if translated: |
731 | if child.get("lang") == locale: |
732 | @@ -381,28 +403,31 @@ |
733 | return child.text |
734 | if translated: |
735 | return self._parse_value(key, False) |
736 | - else: |
737 | - return None |
738 | + |
739 | def _parse_with_lists(self, key): |
740 | - l=[] |
741 | + l = [] |
742 | for listroot in self.appinfo_xml.iter(key): |
743 | for child in listroot.iter(self.LISTS[key]): |
744 | l.append(child.text) |
745 | return ",".join(l) |
746 | + |
747 | def has_option_desktop(self, key): |
748 | if key in self.STATIC_DATA: |
749 | return True |
750 | key = self._apply_mapping(key) |
751 | return not self.appinfo_xml.find(key) is None |
752 | + |
753 | @property |
754 | def desktopf(self): |
755 | subelm = self.appinfo_xml.find("id") |
756 | return subelm.text |
757 | |
758 | + |
759 | class DesktopTagSectionParser(AppInfoParserBase): |
760 | def __init__(self, tag_section, tagfile): |
761 | self.tag_section = tag_section |
762 | self.tagfile = tagfile |
763 | + |
764 | def get_desktop(self, key, translated=True): |
765 | # strip away bogus prefixes |
766 | if key.startswith("X-AppInstall-"): |
767 | @@ -422,7 +447,8 @@ |
768 | # then try the i18n version of the key (in [de_DE] or |
769 | # [de]) but ignore errors and return the untranslated one then |
770 | try: |
771 | - locale = getdefaultlocale(('LANGUAGE','LANG','LC_CTYPE','LC_ALL'))[0] |
772 | + locale = getdefaultlocale(('LANGUAGE', 'LANG', 'LC_CTYPE', |
773 | + 'LC_ALL'))[0] |
774 | if locale: |
775 | if self.has_option_desktop("%s-%s" % (key, locale)): |
776 | return self.tag_section["%s-%s" % (key, locale)] |
777 | @@ -434,18 +460,22 @@ |
778 | pass |
779 | # and then the untranslated field |
780 | return self.tag_section[key] |
781 | + |
782 | def has_option_desktop(self, key): |
783 | # strip away bogus prefixes |
784 | if key.startswith("X-AppInstall-"): |
785 | key = key[len("X-AppInstall-"):] |
786 | return key in self.tag_section |
787 | + |
788 | @property |
789 | def desktopf(self): |
790 | return self.tagfile |
791 | |
792 | + |
793 | class DesktopConfigParser(RawConfigParser, AppInfoParserBase): |
794 | " thin wrapper that is tailored for xdg Desktop files " |
795 | DE = "Desktop Entry" |
796 | + |
797 | def get_desktop(self, key, translated=True): |
798 | " get generic option under 'Desktop Entry'" |
799 | # never translate the pkgname |
800 | @@ -471,28 +501,34 @@ |
801 | # then try the i18n version of the key (in [de_DE] or |
802 | # [de]) but ignore errors and return the untranslated one then |
803 | try: |
804 | - locale = getdefaultlocale(('LANGUAGE','LANG','LC_CTYPE','LC_ALL'))[0] |
805 | + locale = getdefaultlocale(('LANGUAGE', 'LANG', 'LC_CTYPE', |
806 | + 'LC_ALL'))[0] |
807 | if locale: |
808 | if self.has_option_desktop("%s[%s]" % (key, locale)): |
809 | return self.get(self.DE, "%s[%s]" % (key, locale)) |
810 | if "_" in locale: |
811 | locale_short = locale.split("_")[0] |
812 | if self.has_option_desktop("%s[%s]" % (key, locale_short)): |
813 | - return self.get(self.DE, "%s[%s]" % (key, locale_short)) |
814 | + return self.get(self.DE, "%s[%s]" % |
815 | + (key, locale_short)) |
816 | except ValueError: |
817 | pass |
818 | # and then the untranslated field |
819 | return self.get(self.DE, key) |
820 | + |
821 | def has_option_desktop(self, key): |
822 | " test if there is the option under 'Desktop Entry'" |
823 | return self.has_option(self.DE, key) |
824 | + |
825 | def read(self, filename): |
826 | self._filename = filename |
827 | RawConfigParser.read(self, filename) |
828 | + |
829 | @property |
830 | def desktopf(self): |
831 | return self._filename |
832 | |
833 | + |
834 | def ascii_upper(key): |
835 | """Translate an ASCII string to uppercase |
836 | in a locale-independent manner.""" |
837 | @@ -500,13 +536,15 @@ |
838 | string.ascii_uppercase) |
839 | return key.translate(ascii_trans_table) |
840 | |
841 | + |
842 | def index_name(doc, name, term_generator): |
843 | """ index the name of the application """ |
844 | doc.add_value(XapianValues.APPNAME, name) |
845 | - doc.add_term("AA"+name) |
846 | + doc.add_term("AA" + name) |
847 | w = globals()["WEIGHT_DESKTOP_NAME"] |
848 | term_generator.index_text_without_positions(name, w) |
849 | |
850 | + |
851 | def update(db, cache, datadir=None): |
852 | if not datadir: |
853 | datadir = softwarecenter.paths.APP_INSTALL_DESKTOP_PATH |
854 | @@ -514,7 +552,9 @@ |
855 | update_from_var_lib_apt_lists(db, cache) |
856 | # add db global meta-data |
857 | LOG.debug("adding popcon_max_desktop '%s'" % popcon_max) |
858 | - db.set_metadata("popcon_max_desktop", xapian.sortable_serialise(float(popcon_max))) |
859 | + db.set_metadata("popcon_max_desktop", |
860 | + xapian.sortable_serialise(float(popcon_max))) |
861 | + |
862 | |
863 | def update_from_json_string(db, cache, json_string, origin): |
864 | """ index from a json string, should include origin url (free form string) |
865 | @@ -524,6 +564,7 @@ |
866 | index_app_info_from_parser(parser, db, cache) |
867 | return True |
868 | |
869 | + |
870 | def update_from_var_lib_apt_lists(db, cache, listsdir=None): |
871 | """ index the files in /var/lib/apt/lists/*AppInfo """ |
872 | try: |
873 | @@ -544,18 +585,21 @@ |
874 | index_app_info_from_parser(parser, db, cache) |
875 | return True |
876 | |
877 | + |
878 | def update_from_single_appstream_file(db, cache, filename): |
879 | from lxml import etree |
880 | |
881 | tree = etree.parse(open(filename)) |
882 | root = tree.getroot() |
883 | if not root.tag == "applications": |
884 | - LOG.error("failed to read '%s' expected Applications root tag" % filename) |
885 | + LOG.error("failed to read '%s' expected Applications root tag" % |
886 | + filename) |
887 | return |
888 | for appinfo in root.iter("application"): |
889 | parser = AppStreamXMLParser(appinfo, filename) |
890 | index_app_info_from_parser(parser, db, cache) |
891 | |
892 | + |
893 | def update_from_appstream_xml(db, cache, xmldir=None): |
894 | if not xmldir: |
895 | xmldir = softwarecenter.paths.APPSTREAM_XML_PATH |
896 | @@ -573,12 +617,13 @@ |
897 | update_from_single_appstream_file(db, cache, appstream_xml) |
898 | return True |
899 | |
900 | + |
901 | def update_from_app_install_data(db, cache, datadir=None): |
902 | """ index the desktop files in $datadir/desktop/*.desktop """ |
903 | if not datadir: |
904 | datadir = softwarecenter.paths.APP_INSTALL_DESKTOP_PATH |
905 | context = GObject.main_context_default() |
906 | - for desktopf in glob(datadir+"/*.desktop"): |
907 | + for desktopf in glob(datadir + "/*.desktop"): |
908 | LOG.debug("processing %s" % desktopf) |
909 | # process events |
910 | while context.pending(): |
911 | @@ -599,7 +644,9 @@ |
912 | LOG.warning(warning_text) |
913 | return True |
914 | |
915 | -def add_from_purchased_but_needs_reinstall_data(purchased_but_may_need_reinstall_list, db, cache): |
916 | + |
917 | +def add_from_purchased_but_needs_reinstall_data( |
918 | + purchased_but_may_need_reinstall_list, db, cache): |
919 | """Add application that have been purchased but may require a reinstall |
920 | |
921 | This adds a inmemory database to the main db with the special |
922 | @@ -632,9 +679,10 @@ |
923 | # add new in memory db to the main db |
924 | db.add_database(db_purchased) |
925 | # return a query |
926 | - query = xapian.Query("AH"+PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME) |
927 | + query = xapian.Query("AH" + PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME) |
928 | return query |
929 | |
930 | + |
931 | def update_from_software_center_agent(db, cache, ignore_cache=False, |
932 | include_sca_qa=False): |
933 | """ update index based on the software-center-agent data """ |
934 | @@ -644,6 +692,7 @@ |
935 | sca.available = available |
936 | sca.good_data = True |
937 | loop.quit() |
938 | + |
939 | def _error_cb(sca, error): |
940 | LOG.warn("error: %s" % error) |
941 | sca.available = [] |
942 | @@ -690,10 +739,12 @@ |
943 | # app name is the data |
944 | if parser.has_option_desktop("X-Ubuntu-Software-Center-Name"): |
945 | name = parser.get_desktop("X-Ubuntu-Software-Center-Name") |
946 | - untranslated_name = parser.get_desktop("X-Ubuntu-Software-Center-Name", translated=False) |
947 | + untranslated_name = parser.get_desktop("X-Ubuntu-Software-Center-Name", |
948 | + translated=False) |
949 | elif parser.has_option_desktop("X-GNOME-FullName"): |
950 | name = parser.get_desktop("X-GNOME-FullName") |
951 | - untranslated_name = parser.get_desktop("X-GNOME-FullName", translated=False) |
952 | + untranslated_name = parser.get_desktop("X-GNOME-FullName", |
953 | + translated=False) |
954 | else: |
955 | name = parser.get_desktop("Name") |
956 | untranslated_name = parser.get_desktop("Name", translated=False) |
957 | @@ -713,16 +764,18 @@ |
958 | arches = parser.get_desktop("X-AppInstall-Architectures") |
959 | doc.add_value(XapianValues.ARCHIVE_ARCH, arches) |
960 | native_archs = get_current_arch() in arches.split(',') |
961 | - foreign_archs = list(set(arches.split(',')) & set(get_foreign_architectures())) |
962 | - if not (native_archs or foreign_archs): return |
963 | + foreign_archs = list(set(arches.split(',')) & |
964 | + set(get_foreign_architectures())) |
965 | + if not (native_archs or foreign_archs): |
966 | + return |
967 | if not native_archs and foreign_archs: |
968 | pkgname_extension = ':' + foreign_archs[0] |
969 | # package name |
970 | pkgname = parser.get_desktop("X-AppInstall-Package") + pkgname_extension |
971 | - doc.add_term("AP"+pkgname) |
972 | + doc.add_term("AP" + pkgname) |
973 | if '-' in pkgname: |
974 | # we need this to work around xapian oddness |
975 | - doc.add_term(pkgname.replace('-','_')) |
976 | + doc.add_term(pkgname.replace('-', '_')) |
977 | doc.add_value(XapianValues.PKGNAME, pkgname) |
978 | doc.add_value(XapianValues.DESKTOP_FILE, parser.desktopf) |
979 | # display name |
980 | @@ -731,21 +784,21 @@ |
981 | # cataloged_times |
982 | if "catalogedtime" in axi_values: |
983 | if pkgname in cataloged_times: |
984 | - doc.add_value(axi_values["catalogedtime"], |
985 | + doc.add_value(axi_values["catalogedtime"], |
986 | xapian.sortable_serialise(cataloged_times[pkgname])) |
987 | # pocket (main, restricted, ...) |
988 | if parser.has_option_desktop("X-AppInstall-Section"): |
989 | archive_section = parser.get_desktop("X-AppInstall-Section") |
990 | - doc.add_term("AS"+archive_section) |
991 | + doc.add_term("AS" + archive_section) |
992 | doc.add_value(XapianValues.ARCHIVE_SECTION, archive_section) |
993 | # section (mail, base, ..) |
994 | if pkgname in cache and cache[pkgname].candidate: |
995 | section = cache[pkgname].section |
996 | - doc.add_term("AE"+section) |
997 | + doc.add_term("AE" + section) |
998 | # channel (third party stuff) |
999 | if parser.has_option_desktop("X-AppInstall-Channel"): |
1000 | archive_channel = parser.get_desktop("X-AppInstall-Channel") |
1001 | - doc.add_term("AH"+archive_channel) |
1002 | + doc.add_term("AH" + archive_channel) |
1003 | doc.add_value(XapianValues.ARCHIVE_CHANNEL, archive_channel) |
1004 | # signing key (third party) |
1005 | if parser.has_option_desktop("X-AppInstall-Signing-Key-Id"): |
1006 | @@ -758,7 +811,7 @@ |
1007 | # date published |
1008 | if parser.has_option_desktop("X-AppInstall-Date-Published"): |
1009 | date_published = parser.get_desktop("X-AppInstall-Date-Published") |
1010 | - if (date_published and |
1011 | + if (date_published and |
1012 | re.match("\d+-\d+-\d+ \d+:\d+:\d+", date_published)): |
1013 | # strip the subseconds from the end of the published date string |
1014 | date_published = str(date_published).split(".")[0] |
1015 | @@ -772,7 +825,7 @@ |
1016 | date_published_sec = time.mktime( |
1017 | time.strptime(date_published, |
1018 | "%Y-%m-%d %H:%M:%S")) |
1019 | - doc.add_value(axi_values["catalogedtime"], |
1020 | + doc.add_value(axi_values["catalogedtime"], |
1021 | xapian.sortable_serialise(date_published_sec)) |
1022 | # purchased date |
1023 | if parser.has_option_desktop("X-AppInstall-Purchased-Date"): |
1024 | @@ -798,7 +851,7 @@ |
1025 | doc.add_value(XapianValues.ARCHIVE_PPA, archive_ppa) |
1026 | # add archive origin data here so that its available even if |
1027 | # the PPA is not (yet) enabled |
1028 | - doc.add_term("XOO"+"lp-ppa-%s" % archive_ppa.replace("/", "-")) |
1029 | + doc.add_term("XOO" + "lp-ppa-%s" % archive_ppa.replace("/", "-")) |
1030 | # screenshot (for third party) |
1031 | if parser.has_option_desktop("X-AppInstall-Screenshot-Url"): |
1032 | url = parser.get_desktop("X-AppInstall-Screenshot-Url") |
1033 | @@ -836,15 +889,15 @@ |
1034 | doc.add_value(XapianValues.ICON, icon) |
1035 | # write out categories |
1036 | for cat in parser.get_desktop_categories(): |
1037 | - doc.add_term("AC"+cat.lower()) |
1038 | + doc.add_term("AC" + cat.lower()) |
1039 | categories_string = ";".join(parser.get_desktop_categories()) |
1040 | doc.add_value(XapianValues.CATEGORIES, categories_string) |
1041 | for mime in parser.get_desktop_mimetypes(): |
1042 | - doc.add_term("AM"+mime.lower()) |
1043 | + doc.add_term("AM" + mime.lower()) |
1044 | # get type (to distinguish between apps and packages |
1045 | if parser.has_option_desktop("Type"): |
1046 | type = parser.get_desktop("Type") |
1047 | - doc.add_term("AT"+type.lower()) |
1048 | + doc.add_term("AT" + type.lower()) |
1049 | # check gettext domain |
1050 | if parser.has_option_desktop("X-Ubuntu-Gettext-Domain"): |
1051 | domain = parser.get_desktop("X-Ubuntu-Gettext-Domain") |
1052 | @@ -867,14 +920,14 @@ |
1053 | tags = parser.get_desktop("X-AppInstall-Tags") |
1054 | if tags: |
1055 | for tag in tags.split(","): |
1056 | - doc.add_term("XT"+tag.strip()) |
1057 | + doc.add_term("XT" + tag.strip()) |
1058 | # ENFORCE region blacklist by not registering the app at all |
1059 | region = get_region_cached() |
1060 | if region: |
1061 | countrycode = region["countrycode"].lower() |
1062 | if "%s%s" % (REGION_BLACKLIST_TAG, countrycode) in tags: |
1063 | LOG.info("skipping region restricted app: '%s'" % name) |
1064 | - return None |
1065 | + return |
1066 | |
1067 | # popcon |
1068 | # FIXME: popularity not only based on popcon but also |
1069 | @@ -882,7 +935,7 @@ |
1070 | if parser.has_option_desktop("X-AppInstall-Popcon"): |
1071 | popcon = float(parser.get_desktop("X-AppInstall-Popcon")) |
1072 | # sort_by_value uses string compare, so we need to pad here |
1073 | - doc.add_value(XapianValues.POPCON, |
1074 | + doc.add_value(XapianValues.POPCON, |
1075 | xapian.sortable_serialise(popcon)) |
1076 | global popcon_max |
1077 | popcon_max = max(popcon_max, popcon) |
1078 | @@ -922,7 +975,7 @@ |
1079 | doc = make_doc_from_parser(parser, cache) |
1080 | if not doc: |
1081 | LOG.debug("make_doc_from_parser() returned '%s', ignoring" % doc) |
1082 | - return |
1083 | + return |
1084 | term_generator.set_document(doc) |
1085 | name = doc.get_data() |
1086 | |
1087 | @@ -935,10 +988,11 @@ |
1088 | |
1089 | pkgname = doc.get_value(XapianValues.PKGNAME) |
1090 | # add packagename as meta-data too |
1091 | - term_generator.index_text_without_positions(pkgname, WEIGHT_APT_PKGNAME) |
1092 | + term_generator.index_text_without_positions(pkgname, |
1093 | + WEIGHT_APT_PKGNAME) |
1094 | |
1095 | # now add search data from the desktop file |
1096 | - for key in ["GenericName","Comment", "X-AppInstall-Description"]: |
1097 | + for key in ["GenericName", "Comment", "X-AppInstall-Description"]: |
1098 | if not parser.has_option_desktop(key): |
1099 | continue |
1100 | s = parser.get_desktop(key) |
1101 | @@ -954,15 +1008,17 @@ |
1102 | # add data from the apt cache |
1103 | if pkgname in cache and cache[pkgname].candidate: |
1104 | s = cache[pkgname].candidate.summary |
1105 | - term_generator.index_text_without_positions(s, WEIGHT_APT_SUMMARY) |
1106 | + term_generator.index_text_without_positions(s, |
1107 | + WEIGHT_APT_SUMMARY) |
1108 | s = cache[pkgname].candidate.description |
1109 | - term_generator.index_text_without_positions(s, WEIGHT_APT_DESCRIPTION) |
1110 | + term_generator.index_text_without_positions(s, |
1111 | + WEIGHT_APT_DESCRIPTION) |
1112 | for origin in cache[pkgname].candidate.origins: |
1113 | - doc.add_term("XOA"+origin.archive) |
1114 | - doc.add_term("XOC"+origin.component) |
1115 | - doc.add_term("XOL"+origin.label) |
1116 | - doc.add_term("XOO"+origin.origin) |
1117 | - doc.add_term("XOS"+origin.site) |
1118 | + doc.add_term("XOA" + origin.archive) |
1119 | + doc.add_term("XOC" + origin.component) |
1120 | + doc.add_term("XOL" + origin.label) |
1121 | + doc.add_term("XOO" + origin.origin) |
1122 | + doc.add_term("XOS" + origin.site) |
1123 | |
1124 | # add our keywords (with high priority) |
1125 | keywords = None |
1126 | @@ -973,16 +1029,18 @@ |
1127 | if keywords: |
1128 | for s in keywords.split(";"): |
1129 | if s: |
1130 | - term_generator.index_text_without_positions(s, WEIGHT_DESKTOP_KEYWORD) |
1131 | + term_generator.index_text_without_positions(s, |
1132 | + WEIGHT_DESKTOP_KEYWORD) |
1133 | # now add it |
1134 | db.add_document(doc) |
1135 | |
1136 | + |
1137 | def rebuild_database(pathname, debian_sources=True, appstream_sources=False): |
1138 | #cache = apt.Cache(memonly=True) |
1139 | cache = get_pkg_info() |
1140 | cache.open() |
1141 | - old_path = pathname+"_old" |
1142 | - rebuild_path = pathname+"_rb" |
1143 | + old_path = pathname + "_old" |
1144 | + rebuild_path = pathname + "_rb" |
1145 | |
1146 | if not os.path.exists(rebuild_path): |
1147 | try: |
1148 | @@ -1000,7 +1058,8 @@ |
1149 | |
1150 | #check if old unrequired version of db still exists on filesystem |
1151 | if os.path.exists(old_path): |
1152 | - LOG.warn("Existing xapian old db was not previously cleaned: '%s'." % old_path) |
1153 | + LOG.warn("Existing xapian old db was not previously cleaned: '%s'." % |
1154 | + old_path) |
1155 | if os.access(old_path, os.W_OK): |
1156 | #remove old unrequired db before beginning |
1157 | shutil.rmtree(old_path) |
1158 | @@ -1009,7 +1068,6 @@ |
1159 | LOG.warn("Please check you have the relevant permissions.") |
1160 | return False |
1161 | |
1162 | - |
1163 | # write it |
1164 | db = xapian.WritableDatabase(rebuild_path, xapian.DB_CREATE_OR_OVERWRITE) |
1165 | |
1166 | @@ -1017,7 +1075,8 @@ |
1167 | update(db, cache) |
1168 | if appstream_sources: |
1169 | if os.path.exists('./data/app-stream/appdata.xml'): |
1170 | - update_from_appstream_xml(db, cache, './data/app-stream/appdata.xml'); |
1171 | + update_from_appstream_xml(db, cache, |
1172 | + './data/app-stream/appdata.xml') |
1173 | else: |
1174 | update_from_appstream_xml(db, cache) |
1175 | |
1176 | @@ -1038,5 +1097,6 @@ |
1177 | shutil.rmtree(old_path) |
1178 | return True |
1179 | except: |
1180 | - LOG.warn("Cannot copy refreshed database to correct location: '%s'." % pathname) |
1181 | + LOG.warn("Cannot copy refreshed database to correct location: '%s'." % |
1182 | + pathname) |
1183 | return False |
1184 | |
1185 | === modified file 'softwarecenter/db/utils.py' |
1186 | --- softwarecenter/db/utils.py 2012-02-17 14:23:58 +0000 |
1187 | +++ softwarecenter/db/utils.py 2012-03-15 04:06:19 +0000 |
1188 | @@ -18,18 +18,20 @@ |
1189 | |
1190 | import xapian |
1191 | |
1192 | + |
1193 | def get_query_for_pkgnames(pkgnames): |
1194 | """ return a xapian query that matches exactly the list of pkgnames """ |
1195 | query = xapian.Query() |
1196 | for pkgname in pkgnames: |
1197 | query = xapian.Query(xapian.Query.OP_OR, |
1198 | query, |
1199 | - xapian.Query("XP"+pkgname)) |
1200 | + xapian.Query("XP" + pkgname)) |
1201 | query = xapian.Query(xapian.Query.OP_OR, |
1202 | query, |
1203 | - xapian.Query("AP"+pkgname)) |
1204 | + xapian.Query("AP" + pkgname)) |
1205 | return query |
1206 | - |
1207 | + |
1208 | + |
1209 | def get_installed_apps_list(db): |
1210 | """ return a list of installed applications """ |
1211 | apps = set() |
1212 | @@ -41,11 +43,12 @@ |
1213 | apps.add(db.get_application(doc)) |
1214 | return apps |
1215 | |
1216 | + |
1217 | def get_installed_package_list(): |
1218 | """ return a set of all of the currently installed packages """ |
1219 | from softwarecenter.db.pkginfo import get_pkg_info |
1220 | installed_pkgs = set() |
1221 | - cache=get_pkg_info() |
1222 | + cache = get_pkg_info() |
1223 | for pkg in cache: |
1224 | if pkg.is_installed: |
1225 | installed_pkgs.add(pkg.name) |
1226 | |
1227 | === modified file 'test/test_pep8.py' |
1228 | --- test/test_pep8.py 2012-03-15 04:06:19 +0000 |
1229 | +++ test/test_pep8.py 2012-03-15 04:06:19 +0000 |
1230 | @@ -7,16 +7,15 @@ |
1231 | setup_test_env() |
1232 | |
1233 | # Only test these two packages for now: |
1234 | -import softwarecenter.db.pkginfo_impl |
1235 | -import softwarecenter.ui.gtk3 |
1236 | -import softwarecenter.ui.qml |
1237 | +import softwarecenter.db |
1238 | +import softwarecenter.ui |
1239 | |
1240 | class PackagePep8TestCase(unittest.TestCase): |
1241 | maxDiff = None |
1242 | - packages = [softwarecenter.ui.qml, |
1243 | - softwarecenter.ui.gtk3, |
1244 | - softwarecenter.db.pkginfo_impl] |
1245 | - exclude = [] |
1246 | + packages = [softwarecenter.ui, |
1247 | + softwarecenter.db] |
1248 | + exclude = ['history.py', 'enquire.py', 'debfile.py', 'database.py', |
1249 | + 'categories.py', 'application.py', 'appfilter.py', '__init__.py'] |
1250 | |
1251 | def message(self, text): |
1252 | self.errors.append(text) |