Merge lp:~elachuni/software-center/pep8-test-part17 into lp:software-center
- pep8-test-part17
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2863 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part17 |
Merge into: | lp:software-center |
Prerequisite: | lp:~elachuni/software-center/pep8-test-part16 |
Diff against target: |
1194 lines (+242/-185) 7 files modified
softwarecenter/db/__init__.py (+3/-2) softwarecenter/db/categories.py (+77/-63) softwarecenter/db/database.py (+79/-60) softwarecenter/db/debfile.py (+31/-16) softwarecenter/db/enquire.py (+34/-34) softwarecenter/db/history.py (+17/-8) test/test_pep8.py (+1/-2) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part17 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
software-store-developers | Pending | ||
Review via email: mp+97571@code.launchpad.net |
Commit message
Description of the change
Most files under softwarecenter.db now 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/__init__.py' |
2 | --- softwarecenter/db/__init__.py 2012-02-16 09:52:24 +0000 |
3 | +++ softwarecenter/db/__init__.py 2012-03-15 04:36:21 +0000 |
4 | @@ -1,8 +1,9 @@ |
5 | import logging |
6 | try: |
7 | from debfile import DebFileApplication |
8 | - DebFileApplication # pyflakes |
9 | + DebFileApplication # pyflakes |
10 | except: |
11 | logging.exception("DebFileApplication import") |
12 | - class DebFileApplication(): |
13 | + |
14 | + class DebFileApplication(): |
15 | pass |
16 | |
17 | === modified file 'softwarecenter/db/categories.py' |
18 | --- softwarecenter/db/categories.py 2012-02-29 20:56:24 +0000 |
19 | +++ softwarecenter/db/categories.py 2012-03-15 04:36:21 +0000 |
20 | @@ -43,13 +43,15 @@ |
21 | # not possible not use local logger |
22 | LOG = logging.getLogger(__name__) |
23 | |
24 | + |
25 | def get_category_by_name(categories, untrans_name): |
26 | # find a specific category |
27 | cat = [cat for cat in categories if cat.untranslated_name == untrans_name] |
28 | - if cat: |
29 | + if cat: |
30 | return cat[0] |
31 | return None |
32 | |
33 | + |
34 | def categories_sorted_by_name(categories): |
35 | # sort categories by name |
36 | sorted_catnames = [] |
37 | @@ -66,7 +68,8 @@ |
38 | sorted_cats.append(cat) |
39 | break |
40 | return sorted_cats |
41 | - |
42 | + |
43 | + |
44 | def get_query_for_category(db, untranslated_category_name): |
45 | cat_parser = CategoriesParser(db) |
46 | categories = cat_parser.parse_applications_menu(APP_INSTALL_PATH) |
47 | @@ -80,7 +83,7 @@ |
48 | class Category(GObject.GObject): |
49 | """represents a menu category""" |
50 | def __init__(self, untranslated_name, name, iconname, query, |
51 | - only_unallocated=True, dont_display=False, flags=[], |
52 | + only_unallocated=True, dont_display=False, flags=[], |
53 | subcategories=[], sortmode=SortMethods.BY_ALPHABET, |
54 | item_limit=0): |
55 | GObject.GObject.__init__(self) |
56 | @@ -129,20 +132,20 @@ |
57 | class RecommendedForYouCategory(Category): |
58 | |
59 | __gsignals__ = { |
60 | - "needs-refresh" : (GObject.SIGNAL_RUN_LAST, |
61 | - GObject.TYPE_NONE, |
62 | - (), |
63 | - ), |
64 | - "recommender-agent-error" : (GObject.SIGNAL_RUN_LAST, |
65 | - GObject.TYPE_NONE, |
66 | - (GObject.TYPE_STRING,), |
67 | - ), |
68 | + "needs-refresh": (GObject.SIGNAL_RUN_LAST, |
69 | + GObject.TYPE_NONE, |
70 | + (), |
71 | + ), |
72 | + "recommender-agent-error": (GObject.SIGNAL_RUN_LAST, |
73 | + GObject.TYPE_NONE, |
74 | + (GObject.TYPE_STRING,), |
75 | + ), |
76 | } |
77 | |
78 | def __init__(self): |
79 | super(RecommendedForYouCategory, self).__init__( |
80 | - u"Recommended for You", _("Recommended for You"), None, |
81 | - xapian.Query(),flags=['available-only', 'not-installed-only'], |
82 | + u"Recommended for You", _("Recommended for You"), None, |
83 | + xapian.Query(), flags=['available-only', 'not-installed-only'], |
84 | item_limit=60) |
85 | self.recommender_agent = RecommenderAgent() |
86 | self.recommender_agent.connect( |
87 | @@ -159,27 +162,28 @@ |
88 | self.emit("needs-refresh") |
89 | |
90 | def _recommender_agent_error(self, recommender_agent, msg): |
91 | - LOG.warn("Error while accessing the recommender service: %s" |
92 | + LOG.warn("Error while accessing the recommender service: %s" |
93 | % msg) |
94 | self.emit("recommender-agent-error", msg) |
95 | - |
96 | + |
97 | + |
98 | class AppRecommendationsCategory(Category): |
99 | |
100 | __gsignals__ = { |
101 | - "needs-refresh" : (GObject.SIGNAL_RUN_LAST, |
102 | - GObject.TYPE_NONE, |
103 | - (), |
104 | - ), |
105 | - "recommender-agent-error" : (GObject.SIGNAL_RUN_LAST, |
106 | - GObject.TYPE_NONE, |
107 | - (GObject.TYPE_STRING,), |
108 | - ), |
109 | + "needs-refresh": (GObject.SIGNAL_RUN_LAST, |
110 | + GObject.TYPE_NONE, |
111 | + (), |
112 | + ), |
113 | + "recommender-agent-error": (GObject.SIGNAL_RUN_LAST, |
114 | + GObject.TYPE_NONE, |
115 | + (GObject.TYPE_STRING,), |
116 | + ), |
117 | } |
118 | |
119 | def __init__(self, pkgname): |
120 | super(AppRecommendationsCategory, self).__init__( |
121 | - u"People Also Installed", _("People Also Installed"), None, |
122 | - xapian.Query(),flags=['available-only', 'not-installed-only'], |
123 | + u"People Also Installed", _("People Also Installed"), None, |
124 | + xapian.Query(), flags=['available-only', 'not-installed-only'], |
125 | item_limit=4) |
126 | self.recommender_agent = RecommenderAgent() |
127 | self.recommender_agent.connect( |
128 | @@ -196,12 +200,13 @@ |
129 | self.emit("needs-refresh") |
130 | |
131 | def _recommender_agent_error(self, recommender_agent, msg): |
132 | - LOG.warn("Error while accessing the recommender service: %s" |
133 | + LOG.warn("Error while accessing the recommender service: %s" |
134 | % msg) |
135 | self.emit("recommender-agent-error", msg) |
136 | |
137 | + |
138 | class CategoriesParser(object): |
139 | - """ |
140 | + """ |
141 | Parser that is able to read the categories from a menu file |
142 | """ |
143 | |
144 | @@ -214,8 +219,8 @@ |
145 | """ parse a application menu and return a list of Category objects """ |
146 | categories = [] |
147 | # we support multiple menu files and menu drop ins |
148 | - menu_files = [ datadir+"/desktop/software-center.menu" ] |
149 | - menu_files += glob.glob(datadir+"/menu.d/*.menu") |
150 | + menu_files = [datadir + "/desktop/software-center.menu"] |
151 | + menu_files += glob.glob(datadir + "/menu.d/*.menu") |
152 | for f in menu_files: |
153 | if not os.path.exists(f): |
154 | continue |
155 | @@ -230,7 +235,7 @@ |
156 | # post processing for <OnlyUnallocated> |
157 | # now build the unallocated queries, once for top-level, |
158 | # and for the subcategories. this means that subcategories |
159 | - # can have a "OnlyUnallocated/" that applies only to |
160 | + # can have a "OnlyUnallocated/" that applies only to |
161 | # unallocated entries in their sublevel |
162 | for cat in categories: |
163 | self._build_unallocated_queries(cat.subcategories) |
164 | @@ -246,15 +251,14 @@ |
165 | currently used for the CURRENT_REGION |
166 | """ |
167 | region = "%s" % get_region_cached()["countrycode"] |
168 | - self._template_dict = { 'CURRENT_REGION' : region, |
169 | - } |
170 | + self._template_dict = {'CURRENT_REGION': region} |
171 | |
172 | def _substitute_string_if_needed(self, t): |
173 | """ substitute the given string with the current supported dynamic |
174 | menu keys |
175 | """ |
176 | return string.Template(t).substitute(self._template_dict) |
177 | - |
178 | + |
179 | def _cat_sort_cmp(self, a, b): |
180 | """sort helper for the categories sorting""" |
181 | #print "cmp: ", a.name, b.name |
182 | @@ -277,7 +281,7 @@ |
183 | LOG.debug("reading '%s'" % fname) |
184 | cp.read(fname) |
185 | try: |
186 | - untranslated_name = name = cp.get("Desktop Entry","Name") |
187 | + untranslated_name = name = cp.get("Desktop Entry", "Name") |
188 | except Exception: |
189 | LOG.warn("'%s' has no name" % fname) |
190 | return None |
191 | @@ -286,7 +290,7 @@ |
192 | except: |
193 | gettext_domain = None |
194 | try: |
195 | - icon = cp.get("Desktop Entry","Icon") |
196 | + icon = cp.get("Desktop Entry", "Icon") |
197 | except Exception: |
198 | icon = "applications-other" |
199 | name = cp.get_desktop("Name", translated=True) |
200 | @@ -303,7 +307,8 @@ |
201 | for operator_elem in element.getchildren(): |
202 | # get the query-text |
203 | if operator_elem.text: |
204 | - qtext = self._substitute_string_if_needed(operator_elem.text).lower() |
205 | + qtext = self._substitute_string_if_needed( |
206 | + operator_elem.text).lower() |
207 | # parse the indivdual element |
208 | if operator_elem.tag == "Not": |
209 | query = self._parse_and_or_not_tag( |
210 | @@ -314,7 +319,7 @@ |
211 | query = xapian.Query(xapian.Query.OP_AND, or_elem, query) |
212 | elif operator_elem.tag == "Category": |
213 | LOG.debug("adding: %s" % operator_elem.text) |
214 | - q = xapian.Query("AC"+qtext) |
215 | + q = xapian.Query("AC" + qtext) |
216 | query = xapian.Query(xapian_op, query, q) |
217 | elif operator_elem.tag == "SCSection": |
218 | LOG.debug("adding section: %s" % operator_elem.text) |
219 | @@ -323,54 +328,58 @@ |
220 | # FIXME: ponder if it makes sense to simply write |
221 | # out XS in update-software-center instead of AE? |
222 | q = xapian.Query(xapian.Query.OP_OR, |
223 | - xapian.Query("XS"+qtext), |
224 | - xapian.Query("AE"+qtext)) |
225 | + xapian.Query("XS" + qtext), |
226 | + xapian.Query("AE" + qtext)) |
227 | query = xapian.Query(xapian_op, query, q) |
228 | elif operator_elem.tag == "SCType": |
229 | LOG.debug("adding type: %s" % operator_elem.text) |
230 | - q = xapian.Query("AT"+qtext) |
231 | + q = xapian.Query("AT" + qtext) |
232 | query = xapian.Query(xapian_op, query, q) |
233 | elif operator_elem.tag == "SCDebtag": |
234 | LOG.debug("adding debtag: %s" % operator_elem.text) |
235 | - q = xapian.Query("XT"+qtext) |
236 | + q = xapian.Query("XT" + qtext) |
237 | query = xapian.Query(xapian_op, query, q) |
238 | elif operator_elem.tag == "SCChannel": |
239 | LOG.debug("adding channel: %s" % operator_elem.text) |
240 | - q = xapian.Query("AH"+qtext) |
241 | + q = xapian.Query("AH" + qtext) |
242 | query = xapian.Query(xapian_op, query, q) |
243 | elif operator_elem.tag == "SCOrigin": |
244 | LOG.debug("adding origin: %s" % operator_elem.text) |
245 | # FIXME: origin is currently case-sensitive?!? |
246 | - q = xapian.Query("XOO"+operator_elem.text) |
247 | + q = xapian.Query("XOO" + operator_elem.text) |
248 | query = xapian.Query(xapian_op, query, q) |
249 | elif operator_elem.tag == "SCPkgname": |
250 | LOG.debug("adding tag: %s" % operator_elem.text) |
251 | # query both axi and s-c |
252 | - q1 = xapian.Query("AP"+qtext) |
253 | + q1 = xapian.Query("AP" + qtext) |
254 | q = xapian.Query(xapian.Query.OP_OR, q1, |
255 | - xapian.Query("XP"+qtext)) |
256 | + xapian.Query("XP" + qtext)) |
257 | query = xapian.Query(xapian_op, query, q) |
258 | elif operator_elem.tag == "SCPkgnameWildcard": |
259 | LOG.debug("adding tag: %s" % operator_elem.text) |
260 | # query both axi and s-c |
261 | s = "pkg_wildcard:%s" % qtext |
262 | - q = self.db.xapian_parser.parse_query(s, xapian.QueryParser.FLAG_WILDCARD) |
263 | + q = self.db.xapian_parser.parse_query(s, |
264 | + xapian.QueryParser.FLAG_WILDCARD) |
265 | query = xapian.Query(xapian_op, query, q) |
266 | - else: |
267 | - LOG.warn("UNHANDLED: %s %s" % (operator_elem.tag, operator_elem.text)) |
268 | + else: |
269 | + LOG.warn("UNHANDLED: %s %s" % (operator_elem.tag, |
270 | + operator_elem.text)) |
271 | return query |
272 | |
273 | def _parse_include_tag(self, element): |
274 | for include in element.getchildren(): |
275 | if include.tag == "Or": |
276 | query = xapian.Query() |
277 | - return self._parse_and_or_not_tag(include, query, xapian.Query.OP_OR) |
278 | + return self._parse_and_or_not_tag(include, query, |
279 | + xapian.Query.OP_OR) |
280 | if include.tag == "And": |
281 | query = xapian.Query("") |
282 | - return self._parse_and_or_not_tag(include, query, xapian.Query.OP_AND) |
283 | + return self._parse_and_or_not_tag(include, query, |
284 | + xapian.Query.OP_AND) |
285 | # without "and" tag we take the first entry |
286 | elif include.tag == "Category": |
287 | - return xapian.Query("AC"+include.text.lower()) |
288 | + return xapian.Query("AC" + include.text.lower()) |
289 | else: |
290 | LOG.warn("UNHANDLED: _parse_include_tag: %s" % include.tag) |
291 | # empty query matches all |
292 | @@ -389,8 +398,9 @@ |
293 | item_limit = 0 |
294 | for element in item.getchildren(): |
295 | # ignore inline translations, we use gettext for this |
296 | - if (element.tag == "Name" and |
297 | - '{http://www.w3.org/XML/1998/namespace}lang' in element.attrib): |
298 | + if (element.tag == "Name" and |
299 | + '{http://www.w3.org/XML/1998/namespace}lang' in |
300 | + element.attrib): |
301 | continue |
302 | if element.tag == "Name": |
303 | untranslated_name = element.text |
304 | @@ -425,22 +435,24 @@ |
305 | subcategories.append(subcat) |
306 | else: |
307 | LOG.warn("UNHANDLED tag in _parse_menu_tag: %s" % element.tag) |
308 | - |
309 | + |
310 | if untranslated_name and query: |
311 | - return Category(untranslated_name, name, icon, query, only_unallocated, dont_display, flags, subcategories, sortmode, item_limit) |
312 | + return Category(untranslated_name, name, icon, query, |
313 | + only_unallocated, dont_display, flags, subcategories, |
314 | + sortmode, item_limit) |
315 | else: |
316 | - LOG.warn("UNHANDLED entry: %s %s %s %s" % (name, |
317 | - untranslated_name, |
318 | - icon, |
319 | + LOG.warn("UNHANDLED entry: %s %s %s %s" % (name, |
320 | + untranslated_name, |
321 | + icon, |
322 | query)) |
323 | return None |
324 | |
325 | def _verify_supported_sort_mode(self, sortmode): |
326 | """ verify that we use a sortmode that we know and can handle """ |
327 | # always supported |
328 | - if sortmode in (SortMethods.UNSORTED, |
329 | - SortMethods.BY_ALPHABET, |
330 | - SortMethods.BY_TOP_RATED, |
331 | + if sortmode in (SortMethods.UNSORTED, |
332 | + SortMethods.BY_ALPHABET, |
333 | + SortMethods.BY_TOP_RATED, |
334 | SortMethods.BY_SEARCH_RANKING): |
335 | return True |
336 | # only supported with a apt-xapian-index version that has the |
337 | @@ -462,7 +474,8 @@ |
338 | continue |
339 | for cat in categories: |
340 | if cat.name != cat_unalloc.name: |
341 | - cat_unalloc.query = xapian.Query(xapian.Query.OP_AND_NOT, cat_unalloc.query, cat.query) |
342 | + cat_unalloc.query = xapian.Query(xapian.Query.OP_AND_NOT, |
343 | + cat_unalloc.query, cat.query) |
344 | #print cat_unalloc.name, cat_unalloc.query |
345 | return |
346 | |
347 | @@ -530,4 +543,5 @@ |
348 | 'Translation': 'Developer Tools;Localization', |
349 | 'Profiling': 'Developer Tools;Profiling', |
350 | 'RevisionControl': 'Developer Tools;Version Control', |
351 | -'WebDevelopment': 'Developer Tools;Web Development',} |
352 | +'WebDevelopment': 'Developer Tools;Web Development', |
353 | +} |
354 | |
355 | === modified file 'softwarecenter/db/database.py' |
356 | --- softwarecenter/db/database.py 2012-02-16 13:59:46 +0000 |
357 | +++ softwarecenter/db/database.py 2012-03-15 04:36:21 +0000 |
358 | @@ -40,8 +40,9 @@ |
359 | from softwarecenter.paths import XAPIAN_BASE_PATH_SOFTWARE_CENTER_AGENT |
360 | from gettext import gettext as _ |
361 | |
362 | + |
363 | def parse_axi_values_file(filename="/var/lib/apt-xapian-index/values"): |
364 | - """ parse the apt-xapian-index "values" file and provide the |
365 | + """ parse the apt-xapian-index "values" file and provide the |
366 | information in the self._axi_values dict |
367 | """ |
368 | axi_values = {} |
369 | @@ -55,6 +56,7 @@ |
370 | axi_values[key] = int(value) |
371 | return axi_values |
372 | |
373 | + |
374 | class SearchQuery(list): |
375 | """ a list wrapper for a search query. it can take a search string |
376 | or a list of search strings |
377 | @@ -69,6 +71,7 @@ |
378 | self.append(query_string_or_list) |
379 | else: |
380 | self.extend(query_string_or_list) |
381 | + |
382 | def __eq__(self, other): |
383 | # turn single querries into a single item list |
384 | if isinstance(other, xapian.Query): |
385 | @@ -76,26 +79,32 @@ |
386 | q1 = [str(q) for q in self] |
387 | q2 = [str(q) for q in other] |
388 | return q1 == q2 |
389 | + |
390 | def __ne__(self, other): |
391 | return not self.__eq__(other) |
392 | + |
393 | def __repr__(self): |
394 | return "[%s]" % ",".join([str(q) for q in self]) |
395 | |
396 | + |
397 | class LocaleSorter(xapian.KeyMaker): |
398 | """ Sort in a locale friendly way by using locale.xtrxfrm """ |
399 | def __init__(self, db): |
400 | super(LocaleSorter, self).__init__() |
401 | self.db = db |
402 | + |
403 | def __call__(self, doc): |
404 | return locale.strxfrm( |
405 | doc.get_value(self.db._axi_values["display_name"])) |
406 | |
407 | + |
408 | class TopRatedSorter(xapian.KeyMaker): |
409 | """ Sort using the top rated data """ |
410 | def __init__(self, db, review_loader): |
411 | super(TopRatedSorter, self).__init__() |
412 | self.db = db |
413 | self.review_loader = review_loader |
414 | + |
415 | def __call__(self, doc): |
416 | app = Application(self.db.get_appname(doc), |
417 | self.db.get_pkgname(doc)) |
418 | @@ -105,6 +114,7 @@ |
419 | return xapian.sortable_serialise(stats.dampened_rating) |
420 | return xapian.sortable_serialise(0) |
421 | |
422 | + |
423 | class StoreDatabase(GObject.GObject): |
424 | """thin abstraction for the xapian database with convenient functions""" |
425 | |
426 | @@ -117,13 +127,14 @@ |
427 | "suite;tool") |
428 | |
429 | # signal emited |
430 | - __gsignals__ = {"reopen" : (GObject.SIGNAL_RUN_FIRST, |
431 | - GObject.TYPE_NONE, |
432 | - ()), |
433 | - "open" : (GObject.SIGNAL_RUN_FIRST, |
434 | - GObject.TYPE_NONE, |
435 | - (GObject.TYPE_STRING,)), |
436 | + __gsignals__ = {"reopen": (GObject.SIGNAL_RUN_FIRST, |
437 | + GObject.TYPE_NONE, |
438 | + ()), |
439 | + "open": (GObject.SIGNAL_RUN_FIRST, |
440 | + GObject.TYPE_NONE, |
441 | + (GObject.TYPE_STRING,)), |
442 | } |
443 | + |
444 | def __init__(self, pathname=None, cache=None): |
445 | GObject.GObject.__init__(self) |
446 | if pathname is None: |
447 | @@ -138,8 +149,8 @@ |
448 | self._logger = logging.getLogger("softwarecenter.db") |
449 | # we open one db per thread, thread names are reused eventually |
450 | # so no memory leak |
451 | - self._db_per_thread = {} |
452 | - self._parser_per_thread = {} |
453 | + self._db_per_thread = {} |
454 | + self._parser_per_thread = {} |
455 | |
456 | @property |
457 | def xapiandb(self): |
458 | @@ -154,7 +165,8 @@ |
459 | """ returns a per thread query parser """ |
460 | thread_name = threading.current_thread().name |
461 | if not thread_name in self._parser_per_thread: |
462 | - self._parser_per_thread[thread_name] = self._get_new_xapian_parser() |
463 | + xapian_parser = self._get_new_xapian_parser() |
464 | + self._parser_per_thread[thread_name] = xapian_parser |
465 | return self._parser_per_thread[thread_name] |
466 | |
467 | def _get_new_xapiandb(self): |
468 | @@ -165,7 +177,7 @@ |
469 | xapiandb.add_database(axi) |
470 | except: |
471 | self._logger.exception("failed to add apt-xapian-index") |
472 | - if (self._use_agent and |
473 | + if (self._use_agent and |
474 | os.path.exists(XAPIAN_BASE_PATH_SOFTWARE_CENTER_AGENT)): |
475 | try: |
476 | sca = xapian.Database(XAPIAN_BASE_PATH_SOFTWARE_CENTER_AGENT) |
477 | @@ -188,14 +200,14 @@ |
478 | xapian_parser.add_prefix("pkg_wildcard", "AP") |
479 | xapian_parser.set_default_op(xapian.Query.OP_AND) |
480 | return xapian_parser |
481 | - |
482 | + |
483 | def open(self, pathname=None, use_axi=True, use_agent=True): |
484 | """ open the database """ |
485 | if pathname: |
486 | self._db_pathname = pathname |
487 | # clean existing DBs on open |
488 | - self._db_per_thread = {} |
489 | - self._parser_per_thread = {} |
490 | + self._db_per_thread = {} |
491 | + self._parser_per_thread = {} |
492 | # add the apt-xapian-database for here (we don't do this |
493 | # for now as we do not have a good way to integrate non-apps |
494 | # with the UI) |
495 | @@ -223,7 +235,7 @@ |
496 | |
497 | def schema_version(self): |
498 | """Return the version of the database layout |
499 | - |
500 | + |
501 | This is useful to ensure we force a rebuild if its |
502 | older than what we expect |
503 | """ |
504 | @@ -236,11 +248,13 @@ |
505 | |
506 | @property |
507 | def popcon_max(self): |
508 | - popcon_max = xapian.sortable_unserialise(self.xapiandb.get_metadata("popcon_max_desktop")) |
509 | + popcon_max = xapian.sortable_unserialise(self.xapiandb.get_metadata( |
510 | + "popcon_max_desktop")) |
511 | assert popcon_max > 0 |
512 | return popcon_max |
513 | |
514 | - def get_query_list_from_search_entry(self, search_term, category_query=None): |
515 | + def get_query_list_from_search_entry(self, search_term, |
516 | + category_query=None): |
517 | """ get xapian.Query from a search term string and a limit the |
518 | search to the given category |
519 | """ |
520 | @@ -248,7 +262,7 @@ |
521 | """ helper that adds the current category to the query""" |
522 | if not category_query: |
523 | return query |
524 | - return xapian.Query(xapian.Query.OP_AND, |
525 | + return xapian.Query(xapian.Query.OP_AND, |
526 | category_query, |
527 | query) |
528 | # empty query returns a query that matches nothing (for performance |
529 | @@ -268,8 +282,9 @@ |
530 | orig_search_term = search_term |
531 | for item in self.SEARCH_GREYLIST_STR.split(";"): |
532 | (search_term, n) = re.subn('\\b%s\\b' % item, '', search_term) |
533 | - if n: |
534 | - self._logger.debug("greylist changed search term: '%s'" % search_term) |
535 | + if n: |
536 | + self._logger.debug("greylist changed search term: '%s'" % |
537 | + search_term) |
538 | # restore query if it was just greylist words |
539 | if search_term == '': |
540 | self._logger.debug("grey-list replaced all terms, restoring") |
541 | @@ -284,25 +299,25 @@ |
542 | pkg_query = xapian.Query() |
543 | for term in search_term.split(): |
544 | pkg_query = xapian.Query(xapian.Query.OP_OR, |
545 | - xapian.Query("XP"+term), |
546 | + xapian.Query("XP" + term), |
547 | pkg_query) |
548 | pkg_query = _add_category_to_query(pkg_query) |
549 | |
550 | # get a search query |
551 | - if not ':' in search_term: # ie, not a mimetype query |
552 | + if not ':' in search_term: # ie, not a mimetype query |
553 | # we need this to work around xapian oddness |
554 | - search_term = search_term.replace('-','_') |
555 | - fuzzy_query = self.xapian_parser.parse_query(search_term, |
556 | - xapian.QueryParser.FLAG_PARTIAL| |
557 | - xapian.QueryParser.FLAG_BOOLEAN) |
558 | + search_term = search_term.replace('-', '_') |
559 | + fuzzy_query = self.xapian_parser.parse_query(search_term, |
560 | + xapian.QueryParser.FLAG_PARTIAL | |
561 | + xapian.QueryParser.FLAG_BOOLEAN) |
562 | # if the query size goes out of hand, omit the FLAG_PARTIAL |
563 | # (LP: #634449) |
564 | if fuzzy_query.get_length() > 1000: |
565 | - fuzzy_query = self.xapian_parser.parse_query(search_term, |
566 | + fuzzy_query = self.xapian_parser.parse_query(search_term, |
567 | xapian.QueryParser.FLAG_BOOLEAN) |
568 | # now add categories |
569 | fuzzy_query = _add_category_to_query(fuzzy_query) |
570 | - return SearchQuery([pkg_query,fuzzy_query]) |
571 | + return SearchQuery([pkg_query, fuzzy_query]) |
572 | |
573 | def get_matches_from_query(self, query, start=0, end=-1, category=None): |
574 | enquire = xapian.Enquire(self.xapiandb) |
575 | @@ -314,7 +329,7 @@ |
576 | if category: |
577 | query = xapian.Query(xapian.Query.OP_AND, category.query, query) |
578 | enquire.set_query(query) |
579 | - if end == -1: |
580 | + if end == -1: |
581 | end = len(self) |
582 | return enquire.get_mset(start, end) |
583 | |
584 | @@ -324,30 +339,30 @@ |
585 | |
586 | def get_spelling_correction(self, search_term): |
587 | # get a search query |
588 | - if not ':' in search_term: # ie, not a mimetype query |
589 | + if not ':' in search_term: # ie, not a mimetype query |
590 | # we need this to work around xapian oddness |
591 | - search_term = search_term.replace('-','_') |
592 | + search_term = search_term.replace('-', '_') |
593 | self.xapian_parser.parse_query( |
594 | search_term, xapian.QueryParser.FLAG_SPELLING_CORRECTION) |
595 | return self.xapian_parser.get_corrected_query_string() |
596 | |
597 | - def get_most_popular_applications_for_mimetype(self, mimetype, |
598 | - only_uninstalled=True, num=3): |
599 | + def get_most_popular_applications_for_mimetype(self, mimetype, |
600 | + only_uninstalled=True, num=3): |
601 | """ return a list of the most popular applications for the given |
602 | - mimetype |
603 | + mimetype |
604 | """ |
605 | # sort by popularity by default |
606 | enquire = xapian.Enquire(self.xapiandb) |
607 | enquire.set_sort_by_value_then_relevance(XapianValues.POPCON) |
608 | # query mimetype |
609 | - query = xapian.Query("AM%s"%mimetype) |
610 | + query = xapian.Query("AM%s" % mimetype) |
611 | enquire.set_query(query) |
612 | # mset just needs to be "big enough"" |
613 | matches = enquire.get_mset(0, 100) |
614 | apps = [] |
615 | for match in matches: |
616 | doc = match.document |
617 | - app = Application(self.get_appname(doc),self.get_pkgname(doc), |
618 | + app = Application(self.get_appname(doc), self.get_pkgname(doc), |
619 | popcon=self.get_popcon(doc)) |
620 | if only_uninstalled: |
621 | if app.get_details(self).pkg_state == PkgStates.UNINSTALLED: |
622 | @@ -364,9 +379,9 @@ |
623 | channel = doc.get_value(XapianValues.ARCHIVE_CHANNEL) |
624 | # if we do not have the summary in the xapian db, get it |
625 | # from the apt cache |
626 | - if not summary and self._aptcache.ready: |
627 | + if not summary and self._aptcache.ready: |
628 | pkgname = self.get_pkgname(doc) |
629 | - if (pkgname in self._aptcache and |
630 | + if (pkgname in self._aptcache and |
631 | self._aptcache[pkgname].candidate): |
632 | return self._aptcache[pkgname].candidate.summary |
633 | elif channel: |
634 | @@ -384,7 +399,7 @@ |
635 | def get_pkgname(self, doc): |
636 | """ Return a packagename from a xapian document """ |
637 | pkgname = doc.get_value(XapianValues.PKGNAME) |
638 | - # if there is no value it means we use the apt-xapian-index |
639 | + # if there is no value it means we use the apt-xapian-index |
640 | # that stores the pkgname in the data field or as a value |
641 | if not pkgname: |
642 | # the doc says that get_value() is quicker than get_data() |
643 | @@ -409,10 +424,11 @@ |
644 | |
645 | def pkg_in_category(self, pkgname, cat_query): |
646 | """ Return True if the given pkg is in the given category """ |
647 | - pkg_query1 = xapian.Query("AP"+pkgname) |
648 | - pkg_query2 = xapian.Query("XP"+pkgname) |
649 | + pkg_query1 = xapian.Query("AP" + pkgname) |
650 | + pkg_query2 = xapian.Query("XP" + pkgname) |
651 | pkg_query = xapian.Query(xapian.Query.OP_OR, pkg_query1, pkg_query2) |
652 | - pkg_and_cat_query = xapian.Query(xapian.Query.OP_AND, pkg_query, cat_query) |
653 | + pkg_and_cat_query = xapian.Query(xapian.Query.OP_AND, pkg_query, |
654 | + cat_query) |
655 | enquire = xapian.Enquire(self.xapiandb) |
656 | enquire.set_query(pkg_and_cat_query) |
657 | matches = enquire.get_mset(0, len(self)) |
658 | @@ -424,10 +440,10 @@ |
659 | """ Return set of docids with the matching applications for the |
660 | given pkgname """ |
661 | result = set() |
662 | - for m in self.xapiandb.postlist("AP"+pkgname): |
663 | + for m in self.xapiandb.postlist("AP" + pkgname): |
664 | result.add(m.docid) |
665 | return result |
666 | - |
667 | + |
668 | def get_icon_download_url(self, doc): |
669 | """ Return the url of the icon or None """ |
670 | url = doc.get_value(XapianValues.ICON_URL) |
671 | @@ -444,39 +460,41 @@ |
672 | |
673 | def get_xapian_document(self, appname, pkgname): |
674 | """ Get the machting xapian document for appname, pkgname |
675 | - |
676 | + |
677 | If no document is found, raise a IndexError |
678 | """ |
679 | - #self._logger.debug("get_xapian_document app='%s' pkg='%s'" % (appname,pkgname)) |
680 | + #self._logger.debug("get_xapian_document app='%s' pkg='%s'" % (appname, |
681 | + # pkgname)) |
682 | # first search for appname in the app-install-data namespace |
683 | - for m in self.xapiandb.postlist("AA"+appname): |
684 | + for m in self.xapiandb.postlist("AA" + appname): |
685 | doc = self.xapiandb.get_document(m.docid) |
686 | if doc.get_value(XapianValues.PKGNAME) == pkgname: |
687 | return doc |
688 | # then search for pkgname in the app-install-data namespace |
689 | - for m in self.xapiandb.postlist("AP"+pkgname): |
690 | + for m in self.xapiandb.postlist("AP" + pkgname): |
691 | doc = self.xapiandb.get_document(m.docid) |
692 | if doc.get_value(XapianValues.PKGNAME) == pkgname: |
693 | return doc |
694 | # then look for matching packages from a-x-i |
695 | - for m in self.xapiandb.postlist("XP"+pkgname): |
696 | + for m in self.xapiandb.postlist("XP" + pkgname): |
697 | doc = self.xapiandb.get_document(m.docid) |
698 | return doc |
699 | # no matching document found |
700 | - raise IndexError("No app '%s' for '%s' in database" % (appname,pkgname)) |
701 | + raise IndexError("No app '%s' for '%s' in database" % (appname, |
702 | + pkgname)) |
703 | |
704 | def is_appname_duplicated(self, appname): |
705 | """Check if the given appname is stored multiple times in the db |
706 | This can happen for generic names like "Terminal" |
707 | """ |
708 | - for (i, m) in enumerate(self.xapiandb.postlist("AA"+appname)): |
709 | + for (i, m) in enumerate(self.xapiandb.postlist("AA" + appname)): |
710 | if i > 0: |
711 | return True |
712 | return False |
713 | |
714 | def get_installed_purchased_packages(self): |
715 | """ return a set() of packagenames of purchased apps that are |
716 | - currently installed |
717 | + currently installed |
718 | """ |
719 | for_purchase_query = xapian.Query( |
720 | "AH" + AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME) |
721 | @@ -500,21 +518,22 @@ |
722 | return list(origins) |
723 | |
724 | def get_exact_matches(self, pkgnames=[]): |
725 | - """ Returns a list of fake MSetItems. If the pkgname is available, then |
726 | - MSetItem.document is pkgnames proper xapian document. If the pkgname |
727 | - is not available, then MSetItem is actually an Application. """ |
728 | + """Returns a list of fake MSetItems. If the pkgname is available, then |
729 | + MSetItem.document is pkgnames proper xapian document. If the pkgname |
730 | + is not available, then MSetItem is actually an Application. |
731 | + """ |
732 | matches = [] |
733 | for pkgname in pkgnames: |
734 | app = Application('', pkgname.split('?')[0]) |
735 | if '?' in pkgname: |
736 | app.request = pkgname.split('?')[1] |
737 | match = app |
738 | - for m in self.xapiandb.postlist("XP"+app.pkgname): |
739 | + for m in self.xapiandb.postlist("XP" + app.pkgname): |
740 | match = self.xapiandb.get_document(m.docid) |
741 | - for m in self.xapiandb.postlist("AP"+app.pkgname): |
742 | + for m in self.xapiandb.postlist("AP" + app.pkgname): |
743 | match = self.xapiandb.get_document(m.docid) |
744 | matches.append(FakeMSetItem(match)) |
745 | - return matches |
746 | + return matches |
747 | |
748 | def __len__(self): |
749 | """return the doc count of the database""" |
750 | @@ -526,6 +545,7 @@ |
751 | doc = self.xapiandb.get_document(it.docid) |
752 | yield doc |
753 | |
754 | + |
755 | class FakeMSetItem(): |
756 | def __init__(self, doc): |
757 | self.document = doc |
758 | @@ -551,9 +571,8 @@ |
759 | print(doc.get_data()) |
760 | |
761 | # test origin |
762 | - query = xapian.Query("XOL"+"Ubuntu") |
763 | + query = xapian.Query("XOL" + "Ubuntu") |
764 | enquire = xapian.Enquire(db.xapiandb) |
765 | enquire.set_query(query) |
766 | matches = enquire.get_mset(0, len(db)) |
767 | print("Ubuntu origin: %s" % len(matches)) |
768 | - |
769 | |
770 | === modified file 'softwarecenter/db/debfile.py' |
771 | --- softwarecenter/db/debfile.py 2012-02-23 16:41:18 +0000 |
772 | +++ softwarecenter/db/debfile.py 2012-03-15 04:36:21 +0000 |
773 | @@ -26,6 +26,7 @@ |
774 | from softwarecenter.enums import PkgStates |
775 | from softwarecenter.utils import ExecutionTime, utf8 |
776 | |
777 | + |
778 | class DebFileApplication(Application): |
779 | |
780 | def __init__(self, debfile): |
781 | @@ -37,13 +38,15 @@ |
782 | pkgname = debname.split('_')[0].lower() |
783 | # call the constructor |
784 | Application.__init__(self, pkgname=pkgname, request=debfile) |
785 | + |
786 | def get_details(self, db): |
787 | with ExecutionTime("get_details for DebFileApplication"): |
788 | details = AppDetailsDebFile(db, application=self) |
789 | return details |
790 | |
791 | + |
792 | class AppDetailsDebFile(AppDetails): |
793 | - |
794 | + |
795 | def __init__(self, db, doc=None, application=None): |
796 | super(AppDetailsDebFile, self).__init__(db, doc, application) |
797 | if doc: |
798 | @@ -59,16 +62,20 @@ |
799 | self._pkg = None |
800 | if not os.path.exists(self._app.request): |
801 | self._error = _("Not found") |
802 | - self._error_not_found = utf8(_(u"The file \u201c%s\u201d does not exist.")) % utf8(self._app.request) |
803 | + self._error_not_found = utf8(_(u"The file \u201c%s\u201d " |
804 | + "does not exist.")) % utf8(self._app.request) |
805 | else: |
806 | mimetype = guess_type(self._app.request) |
807 | if mimetype[0] != "application/x-debian-package": |
808 | - self._error = _("Not found") |
809 | - self._error_not_found = utf8(_(u"The file \u201c%s\u201d is not a software package.")) % utf8(self._app.request) |
810 | + self._error = _("Not found") |
811 | + self._error_not_found = utf8(_(u"The file \u201c%s\u201d " |
812 | + "is not a software package.")) % utf8( |
813 | + self._app.request) |
814 | else: |
815 | # deb files which are corrupt |
816 | - self._error = _("Internal Error") |
817 | - self._error_not_found = utf8(_(u"The file \u201c%s\u201d could not be opened.")) % utf8(self._app.request) |
818 | + self._error = _("Internal Error") |
819 | + self._error_not_found = utf8(_(u"The file \u201c%s\u201d " |
820 | + "could not be opened.")) % utf8(self._app.request) |
821 | return |
822 | |
823 | if self.pkgname and self.pkgname != self._app.pkgname: |
824 | @@ -77,7 +84,7 @@ |
825 | |
826 | # load pkg cache |
827 | self._pkg = None |
828 | - if (self._app.pkgname in self._cache and |
829 | + if (self._app.pkgname in self._cache and |
830 | self._cache[self._app.pkgname].candidate): |
831 | self._pkg = self._cache[self._app.pkgname] |
832 | # load xapian document |
833 | @@ -102,7 +109,7 @@ |
834 | |
835 | @property |
836 | def maintenance_status(self): |
837 | - return None |
838 | + pass |
839 | |
840 | @property |
841 | def pkgname(self): |
842 | @@ -132,7 +139,7 @@ |
843 | return PkgStates.UPGRADABLE |
844 | else: |
845 | return PkgStates.UNINSTALLED |
846 | - |
847 | + |
848 | @property |
849 | def summary(self): |
850 | if self._deb: |
851 | @@ -155,7 +162,7 @@ |
852 | def version(self): |
853 | if self._deb: |
854 | return self._deb._sections["Version"] |
855 | - |
856 | + |
857 | @property |
858 | def installed_size(self): |
859 | installed_size = 0 |
860 | @@ -170,18 +177,26 @@ |
861 | def warning(self): |
862 | # FIXME: use more concise warnings |
863 | if self._deb: |
864 | - deb_state = self._deb.compare_to_version_in_cache(use_installed=False) |
865 | + deb_state = self._deb.compare_to_version_in_cache( |
866 | + use_installed=False) |
867 | if deb_state == DebPackage.VERSION_NONE: |
868 | - return utf8(_("Only install this file if you trust the origin.")) |
869 | + return utf8( |
870 | + _("Only install this file if you trust the origin.")) |
871 | elif (not self._cache[self.pkgname].installed and |
872 | self._cache[self.pkgname].candidate and |
873 | - self._cache[self.pkgname].candidate.downloadable): |
874 | + self._cache[self.pkgname].candidate.downloadable): |
875 | if deb_state == DebPackage.VERSION_OUTDATED: |
876 | - return utf8(_("Please install \"%s\" via your normal software channels. Only install this file if you trust the origin.")) % utf8(self.name) |
877 | + return utf8(_("Please install \"%s\" via your normal " |
878 | + "software channels. Only install this file if you " |
879 | + "trust the origin.")) % utf8(self.name) |
880 | elif deb_state == DebPackage.VERSION_SAME: |
881 | - return utf8(_("Please install \"%s\" via your normal software channels. Only install this file if you trust the origin.")) % utf8(self.name) |
882 | + return utf8(_("Please install \"%s\" via your normal " |
883 | + "software channels. Only install this file if you " |
884 | + "trust the origin.")) % utf8(self.name) |
885 | elif deb_state == DebPackage.VERSION_NEWER: |
886 | - return utf8(_("An older version of \"%s\" is available in your normal software channels. Only install this file if you trust the origin.")) % utf8(self.name) |
887 | + return utf8(_("An older version of \"%s\" is available in " |
888 | + "your normal software channels. Only install this " |
889 | + "file if you trust the origin.")) % utf8(self.name) |
890 | |
891 | @property |
892 | def website(self): |
893 | |
894 | === modified file 'softwarecenter/db/enquire.py' |
895 | --- softwarecenter/db/enquire.py 2012-02-01 08:48:51 +0000 |
896 | +++ softwarecenter/db/enquire.py 2012-03-15 04:36:21 +0000 |
897 | @@ -25,7 +25,7 @@ |
898 | from gi.repository import GObject |
899 | |
900 | from softwarecenter.enums import (SortMethods, |
901 | - XapianValues, |
902 | + XapianValues, |
903 | NonAppVisibility, |
904 | DEFAULT_SEARCH_LIMIT) |
905 | from softwarecenter.db.database import ( |
906 | @@ -33,21 +33,21 @@ |
907 | from softwarecenter.distro import get_distro |
908 | from softwarecenter.utils import ExecutionTime |
909 | |
910 | -LOG=logging.getLogger(__name__) |
911 | +LOG = logging.getLogger(__name__) |
912 | |
913 | |
914 | class AppEnquire(GObject.GObject): |
915 | """ |
916 | - A interface to enquire data from a xapian database. |
917 | + A interface to enquire data from a xapian database. |
918 | It can combined with any xapian querry and with |
919 | a generic filter function (that can filter on data not |
920 | available in xapian) |
921 | """ |
922 | |
923 | # signal emited |
924 | - __gsignals__ = {"query-complete" : (GObject.SIGNAL_RUN_FIRST, |
925 | - GObject.TYPE_NONE, |
926 | - ()), |
927 | + __gsignals__ = {"query-complete": (GObject.SIGNAL_RUN_FIRST, |
928 | + GObject.TYPE_NONE, |
929 | + ()), |
930 | } |
931 | |
932 | def __init__(self, cache, db): |
933 | @@ -87,7 +87,7 @@ |
934 | # generate a name and ensure we never have two threads |
935 | # with the same name |
936 | names = [thread.name for thread in threading.enumerate()] |
937 | - for i in range(threading.active_count()+1, 0, -1): |
938 | + for i in range(threading.active_count() + 1, 0, -1): |
939 | thread_name = 'ThreadedQuery-%s' % i |
940 | if not thread_name in names: |
941 | break |
942 | @@ -98,7 +98,7 @@ |
943 | # don't block the UI while the thread is running |
944 | context = GObject.main_context_default() |
945 | while not self._perform_search_complete: |
946 | - time.sleep(0.02) # 50 fps |
947 | + time.sleep(0.02) # 50 fps |
948 | while context.pending(): |
949 | context.iteration() |
950 | t.join() |
951 | @@ -108,7 +108,7 @@ |
952 | |
953 | def _get_estimate_nr_apps_and_nr_pkgs(self, enquire, q, xfilter): |
954 | # filter out docs of pkgs of which there exists a doc of the app |
955 | - enquire.set_query(xapian.Query(xapian.Query.OP_AND, |
956 | + enquire.set_query(xapian.Query(xapian.Query.OP_AND, |
957 | q, xapian.Query("ATapplication"))) |
958 | |
959 | try: |
960 | @@ -118,17 +118,17 @@ |
961 | return (0, 0) |
962 | |
963 | nr_apps = tmp_matches.get_matches_estimated() |
964 | - enquire.set_query(xapian.Query(xapian.Query.OP_AND_NOT, |
965 | + enquire.set_query(xapian.Query(xapian.Query.OP_AND_NOT, |
966 | q, xapian.Query("XD"))) |
967 | tmp_matches = enquire.get_mset(0, len(self.db), None, xfilter) |
968 | nr_pkgs = tmp_matches.get_matches_estimated() - nr_apps |
969 | return (nr_apps, nr_pkgs) |
970 | |
971 | def _blocking_perform_search(self): |
972 | - # WARNING this call may run in a thread, so its *not* |
973 | + # WARNING this call may run in a thread, so its *not* |
974 | # allowed to touch gtk, otherwise hell breaks loose |
975 | |
976 | - # performance only: this is only needed to avoid the |
977 | + # performance only: this is only needed to avoid the |
978 | # python __call__ overhead for each item if we can avoid it |
979 | |
980 | # use a unique instance of both enquire and xapian database |
981 | @@ -152,18 +152,19 @@ |
982 | |
983 | # for searches we may want to disable show/hide |
984 | terms = [term for term in q] |
985 | - exact_pkgname_query = (len(terms) == 1 and |
986 | + exact_pkgname_query = (len(terms) == 1 and |
987 | terms[0].startswith("XP")) |
988 | |
989 | with ExecutionTime("calculate nr_apps and nr_pkgs: "): |
990 | - nr_apps, nr_pkgs = self._get_estimate_nr_apps_and_nr_pkgs(enquire, q, xfilter) |
991 | + nr_apps, nr_pkgs = self._get_estimate_nr_apps_and_nr_pkgs( |
992 | + enquire, q, xfilter) |
993 | self.nr_apps += nr_apps |
994 | self.nr_pkgs += nr_pkgs |
995 | |
996 | # only show apps by default (unless in always visible mode) |
997 | if self.nonapps_visible != NonAppVisibility.ALWAYS_VISIBLE: |
998 | if not exact_pkgname_query: |
999 | - q = xapian.Query(xapian.Query.OP_AND, |
1000 | + q = xapian.Query(xapian.Query.OP_AND, |
1001 | xapian.Query("ATapplication"), |
1002 | q) |
1003 | |
1004 | @@ -171,14 +172,14 @@ |
1005 | |
1006 | # filter out docs of pkgs of which there exists a doc of the app |
1007 | # FIXME: make this configurable again? |
1008 | - enquire.set_query(xapian.Query(xapian.Query.OP_AND_NOT, |
1009 | + enquire.set_query(xapian.Query(xapian.Query.OP_AND_NOT, |
1010 | q, xapian.Query("XD"))) |
1011 | |
1012 | # sort results |
1013 | |
1014 | # cataloged time - what's new category |
1015 | if self.sortmode == SortMethods.BY_CATALOGED_TIME: |
1016 | - if (self.db._axi_values and |
1017 | + if (self.db._axi_values and |
1018 | "catalogedtime" in self.db._axi_values): |
1019 | enquire.set_sort_by_value( |
1020 | self.db._axi_values["catalogedtime"], reverse=True) |
1021 | @@ -195,7 +196,7 @@ |
1022 | # use the default enquire.set_sort_by_relevance() |
1023 | pass |
1024 | # display name - all categories / channels |
1025 | - elif (self.db._axi_values and |
1026 | + elif (self.db._axi_values and |
1027 | "display_name" in self.db._axi_values): |
1028 | enquire.set_sort_by_key(LocaleSorter(self.db), reverse=False) |
1029 | # fallback to pkgname - if needed? |
1030 | @@ -203,7 +204,7 @@ |
1031 | else: |
1032 | enquire.set_sort_by_value_then_relevance( |
1033 | XapianValues.PKGNAME, False) |
1034 | - |
1035 | + |
1036 | #~ try: |
1037 | if self.limit == 0: |
1038 | matches = enquire.get_mset(0, len(self.db), None, xfilter) |
1039 | @@ -213,8 +214,8 @@ |
1040 | #~ except: |
1041 | #~ logging.exception("get_mset") |
1042 | #~ matches = [] |
1043 | - |
1044 | - # promote exact matches to a "app", this will make the |
1045 | + |
1046 | + # promote exact matches to a "app", this will make the |
1047 | # show/hide technical items work correctly |
1048 | if exact_pkgname_query and len(matches) == 1: |
1049 | self.nr_apps += 1 |
1050 | @@ -237,7 +238,6 @@ |
1051 | |
1052 | # wake up the UI if run in a search thread |
1053 | self._perform_search_complete = True |
1054 | - return |
1055 | |
1056 | def get_estimated_matches_count(self, query): |
1057 | with ExecutionTime("estimate item count for query: '%s'" % query): |
1058 | @@ -250,9 +250,9 @@ |
1059 | nr_pkgs = len(tmp_matches) |
1060 | return nr_pkgs |
1061 | |
1062 | - def set_query(self, search_query, |
1063 | + def set_query(self, search_query, |
1064 | limit=DEFAULT_SEARCH_LIMIT, |
1065 | - sortmode=SortMethods.UNSORTED, |
1066 | + sortmode=SortMethods.UNSORTED, |
1067 | filter=None, |
1068 | exact=False, |
1069 | nonapps_visible=NonAppVisibility.MAYBE_VISIBLE, |
1070 | @@ -270,14 +270,15 @@ |
1071 | - `exact`: If true, indexes of queries without matches will be |
1072 | maintained in the store (useful to show e.g. a row |
1073 | with "??? not found") |
1074 | - - `nonapps_visible`: decide whether adding non apps in the model or not. |
1075 | - Can be NonAppVisibility.ALWAYS_VISIBLE/NonAppVisibility.MAYBE_VISIBLE |
1076 | + - `nonapps_visible`: decide whether adding non apps in the model or |
1077 | + not. Can be NonAppVisibility.ALWAYS_VISIBLE |
1078 | + /NonAppVisibility.MAYBE_VISIBLE |
1079 | /NonAppVisibility.NEVER_VISIBLE |
1080 | - (NonAppVisibility.MAYBE_VISIBLE will return non apps result |
1081 | - if no matching apps is found) |
1082 | - - `nonblocking_load`: set to False to execute the query inside the current |
1083 | - thread. Defaults to True to allow the search to be |
1084 | - performed without blocking the UI. |
1085 | + (NonAppVisibility.MAYBE_VISIBLE will return non |
1086 | + apps result if no matching apps is found) |
1087 | + - `nonblocking_load`: set to False to execute the query inside the |
1088 | + current thread. Defaults to True to allow the |
1089 | + search to be performed without blocking the UI. |
1090 | - 'persistent_duplicate_filter': if True allows filtering of duplicate |
1091 | matches across multiple queries |
1092 | """ |
1093 | @@ -321,7 +322,8 @@ |
1094 | # pkgnames = [] |
1095 | # for m in self.matches: |
1096 | # doc = xdb.get_document(m.docid) |
1097 | -# pkgnames.append(doc.get_value(XapianValues.PKGNAME) or doc.get_data()) |
1098 | +# pkgnames.append(doc.get_value(XapianValues.PKGNAME) or |
1099 | +# doc.get_data()) |
1100 | # return pkgnames |
1101 | |
1102 | # def get_applications(self): |
1103 | @@ -339,5 +341,3 @@ |
1104 | """ get the xapian.Document objects of the current matches """ |
1105 | xdb = self.db.xapiandb |
1106 | return [xdb.get_document(m.docid) for m in self._matches] |
1107 | - |
1108 | - |
1109 | |
1110 | === modified file 'softwarecenter/db/history.py' |
1111 | --- softwarecenter/db/history.py 2011-12-12 17:08:34 +0000 |
1112 | +++ softwarecenter/db/history.py 2012-03-15 04:36:21 +0000 |
1113 | @@ -20,8 +20,9 @@ |
1114 | |
1115 | LOG = logging.getLogger(__name__) |
1116 | |
1117 | + |
1118 | class Transaction(object): |
1119 | - """ Represents an pkg transaction |
1120 | + """ Represents an pkg transaction |
1121 | |
1122 | o Attributes: |
1123 | - 'start_date': the start date/time of the transaction as datetime |
1124 | @@ -29,23 +30,29 @@ |
1125 | contain the list of packagenames affected by this action |
1126 | """ |
1127 | |
1128 | - PKGACTIONS=["Install", "Upgrade", "Downgrade", "Remove", "Purge"] |
1129 | + PKGACTIONS = ["Install", "Upgrade", "Downgrade", "Remove", "Purge"] |
1130 | |
1131 | def __init__(self): |
1132 | pass |
1133 | |
1134 | def __len__(self): |
1135 | - count=0 |
1136 | + count = 0 |
1137 | for k in self.PKGACTIONS: |
1138 | count += len(getattr(self, k.lower())) |
1139 | return count |
1140 | + |
1141 | def __repr__(self): |
1142 | - return ('<Transaction: start_date:%s install:%s upgrade:%s downgrade:%s remove:%s purge:%s' % (self.start_date, self.install, self.upgrade, self.downgrade, self.remove, self.purge)) |
1143 | + return ('<Transaction: start_date:%s install:%s upgrade:%s ' |
1144 | + 'downgrade:%s remove:%s purge:%s' % (self.start_date, |
1145 | + self.install, self.upgrade, self.downgrade, self.remove, |
1146 | + self.purge)) |
1147 | + |
1148 | def __cmp__(self, other): |
1149 | return cmp(self.start_date, other.start_date) |
1150 | - |
1151 | + |
1152 | + |
1153 | class PackageHistory(object): |
1154 | - """ Represents the history of the transactions """ |
1155 | + """ Represents the history of the transactions """ |
1156 | |
1157 | def __init__(self, use_cache=True): |
1158 | pass |
1159 | @@ -62,17 +69,19 @@ |
1160 | return [] |
1161 | |
1162 | # FIXME: this should be a gobect signal |
1163 | - def set_on_update(self,update_callback): |
1164 | + def set_on_update(self, update_callback): |
1165 | """ callback when a update is ready """ |
1166 | pass |
1167 | |
1168 | def get_installed_date(self, pkg_name): |
1169 | """Return the date that the given package name got instaled """ |
1170 | - return None |
1171 | + pass |
1172 | |
1173 | |
1174 | # make it a singleton |
1175 | pkg_history = None |
1176 | + |
1177 | + |
1178 | def get_pkg_history(): |
1179 | """ get the global PackageHistory() singleton object """ |
1180 | global pkg_history |
1181 | |
1182 | === modified file 'test/test_pep8.py' |
1183 | --- test/test_pep8.py 2012-03-15 04:36:21 +0000 |
1184 | +++ test/test_pep8.py 2012-03-15 04:36:21 +0000 |
1185 | @@ -14,8 +14,7 @@ |
1186 | maxDiff = None |
1187 | packages = [softwarecenter.ui, |
1188 | softwarecenter.db] |
1189 | - exclude = ['history.py', 'enquire.py', 'debfile.py', 'database.py', |
1190 | - 'categories.py', 'application.py', 'appfilter.py', '__init__.py'] |
1191 | + exclude = ['application.py', 'appfilter.py'] |
1192 | |
1193 | def message(self, text): |
1194 | self.errors.append(text) |