mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8
This commit is contained in:
parent
d0b8e4248f
commit
b1d558a92a
@ -118,7 +118,7 @@ class MetadataBackup(Thread): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
### Global utility function for get_match here and in gui2/library.py
|
# Global utility function for get_match here and in gui2/library.py
|
||||||
# This is a global for performance
|
# This is a global for performance
|
||||||
pref_use_primary_find_in_search = False
|
pref_use_primary_find_in_search = False
|
||||||
|
|
||||||
@ -228,7 +228,6 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
self.db_prefs = self.all_search_locations = None
|
self.db_prefs = self.all_search_locations = None
|
||||||
self.sqp_change_locations([])
|
self.sqp_change_locations([])
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self, row):
|
def __getitem__(self, row):
|
||||||
return self._data[self._map_filtered[row]]
|
return self._data[self._map_filtered[row]]
|
||||||
|
|
||||||
@ -331,7 +330,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if query == 'false':
|
if query == 'false':
|
||||||
for id_ in candidates:
|
for id_ in candidates:
|
||||||
item = self._data[id_]
|
item = self._data[id_]
|
||||||
if item is None: continue
|
if item is None:
|
||||||
|
continue
|
||||||
v = item[loc]
|
v = item[loc]
|
||||||
if isinstance(v, (str, unicode)):
|
if isinstance(v, (str, unicode)):
|
||||||
v = parse_date(v)
|
v = parse_date(v)
|
||||||
@ -341,7 +341,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if query == 'true':
|
if query == 'true':
|
||||||
for id_ in candidates:
|
for id_ in candidates:
|
||||||
item = self._data[id_]
|
item = self._data[id_]
|
||||||
if item is None: continue
|
if item is None:
|
||||||
|
continue
|
||||||
v = item[loc]
|
v = item[loc]
|
||||||
if isinstance(v, (str, unicode)):
|
if isinstance(v, (str, unicode)):
|
||||||
v = parse_date(v)
|
v = parse_date(v)
|
||||||
@ -384,7 +385,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
field_count = query.count('/') + 1
|
field_count = query.count('/') + 1
|
||||||
for id_ in candidates:
|
for id_ in candidates:
|
||||||
item = self._data[id_]
|
item = self._data[id_]
|
||||||
if item is None or item[loc] is None: continue
|
if item is None or item[loc] is None:
|
||||||
|
continue
|
||||||
v = item[loc]
|
v = item[loc]
|
||||||
if isinstance(v, (str, unicode)):
|
if isinstance(v, (str, unicode)):
|
||||||
v = parse_date(v)
|
v = parse_date(v)
|
||||||
@ -402,7 +404,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
'<=':[2, lambda r, q: r is not None and r <= q]
|
'<=':[2, lambda r, q: r is not None and r <= q]
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_numeric_matches(self, location, query, candidates, val_func = None):
|
def get_numeric_matches(self, location, query, candidates, val_func=None):
|
||||||
matches = set([])
|
matches = set([])
|
||||||
if len(query) == 0:
|
if len(query) == 0:
|
||||||
return matches
|
return matches
|
||||||
@ -434,14 +436,14 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
(p, relop) = self.numeric_search_relops['=']
|
(p, relop) = self.numeric_search_relops['=']
|
||||||
|
|
||||||
if dt == 'int':
|
if dt == 'int':
|
||||||
cast = lambda x: int (x)
|
cast = lambda x: int(x)
|
||||||
elif dt == 'rating':
|
elif dt == 'rating':
|
||||||
cast = lambda x: 0 if x is None else int (x)
|
cast = lambda x: 0 if x is None else int(x)
|
||||||
adjust = lambda x: x/2
|
adjust = lambda x: x/2
|
||||||
elif dt in ('float', 'composite'):
|
elif dt in ('float', 'composite'):
|
||||||
cast = lambda x : float (x)
|
cast = lambda x : float(x)
|
||||||
else: # count operation
|
else: # count operation
|
||||||
cast = (lambda x: int (x))
|
cast = (lambda x: int(x))
|
||||||
|
|
||||||
if len(query) > 1:
|
if len(query) > 1:
|
||||||
mult = query[-1:].lower()
|
mult = query[-1:].lower()
|
||||||
@ -746,7 +748,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
current_candidates = candidates.copy()
|
current_candidates = candidates.copy()
|
||||||
for loc in location: # location is now an array of field indices
|
for loc in location: # location is now an array of field indices
|
||||||
if loc == db_col['authors']:
|
if loc == db_col['authors']:
|
||||||
### DB stores authors with commas changed to bars, so change query
|
# DB stores authors with commas changed to bars, so change query
|
||||||
if matchkind == REGEXP_MATCH:
|
if matchkind == REGEXP_MATCH:
|
||||||
q = query.replace(',', r'\|')
|
q = query.replace(',', r'\|')
|
||||||
else:
|
else:
|
||||||
@ -762,7 +764,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
|
|
||||||
for id_ in current_candidates:
|
for id_ in current_candidates:
|
||||||
item = self._data[id_]
|
item = self._data[id_]
|
||||||
if item is None: continue
|
if item is None:
|
||||||
|
continue
|
||||||
|
|
||||||
if not item[loc]:
|
if not item[loc]:
|
||||||
if q == 'false' and matchkind == CONTAINS_MATCH:
|
if q == 'false' and matchkind == CONTAINS_MATCH:
|
||||||
@ -803,7 +806,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if is_multiple_cols[loc] is not None:
|
if is_multiple_cols[loc] is not None:
|
||||||
vals = [v.strip() for v in item[loc].split(is_multiple_cols[loc])]
|
vals = [v.strip() for v in item[loc].split(is_multiple_cols[loc])]
|
||||||
else:
|
else:
|
||||||
vals = [item[loc]] ### make into list to make _match happy
|
vals = [item[loc]] # make into list to make _match happy
|
||||||
if _match(q, vals, matchkind,
|
if _match(q, vals, matchkind,
|
||||||
use_primary_find_in_search=pref_use_primary_find_in_search):
|
use_primary_find_in_search=pref_use_primary_find_in_search):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
@ -1035,8 +1038,10 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
def sanitize_sort_field_name(self, field):
|
def sanitize_sort_field_name(self, field):
|
||||||
field = self.field_metadata.search_term_to_field_key(field.lower().strip())
|
field = self.field_metadata.search_term_to_field_key(field.lower().strip())
|
||||||
# translate some fields to their hidden equivalent
|
# translate some fields to their hidden equivalent
|
||||||
if field == 'title': field = 'sort'
|
if field == 'title':
|
||||||
elif field == 'authors': field = 'author_sort'
|
field = 'sort'
|
||||||
|
elif field == 'authors':
|
||||||
|
field = 'author_sort'
|
||||||
return field
|
return field
|
||||||
|
|
||||||
def sort(self, field, ascending, subsort=False):
|
def sort(self, field, ascending, subsort=False):
|
||||||
@ -1181,3 +1186,4 @@ class SortKeyGenerator(object):
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user