mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fixed bug in catalog builder occurring when locale is other than EN and specified prefix source field is a Yes/No column. True/False needed to be translated before testing.
This commit is contained in:
parent
9f42386718
commit
2ed98182ca
@ -16,6 +16,7 @@ from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
|||||||
from calibre.ebooks import calibre_cover
|
from calibre.ebooks import calibre_cover
|
||||||
from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
|
from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
|
from calibre.utils.localization import get_lang
|
||||||
|
|
||||||
Option = namedtuple('Option', 'option, default, dest, action, help')
|
Option = namedtuple('Option', 'option, default, dest, action, help')
|
||||||
|
|
||||||
@ -202,9 +203,12 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
|
|
||||||
build_log = []
|
build_log = []
|
||||||
|
|
||||||
build_log.append(u"%s(): Generating %s %sin %s environment" %
|
build_log.append(u"%s(): Generating %s %sin %s environment, locale: '%s'" %
|
||||||
(self.name,self.fmt,'for %s ' % opts.output_profile if opts.output_profile else '',
|
(self.name,
|
||||||
'CLI' if opts.cli_environment else 'GUI'))
|
self.fmt,
|
||||||
|
'for %s ' % opts.output_profile if opts.output_profile else '',
|
||||||
|
'CLI' if opts.cli_environment else 'GUI',
|
||||||
|
get_lang()))
|
||||||
|
|
||||||
# If exclude_genre is blank, assume user wants all tags as genres
|
# If exclude_genre is blank, assume user wants all tags as genres
|
||||||
if opts.exclude_genre.strip() == '':
|
if opts.exclude_genre.strip() == '':
|
||||||
|
@ -569,10 +569,12 @@ class CatalogBuilder(object):
|
|||||||
prefix (str): matched a prefix_rule
|
prefix (str): matched a prefix_rule
|
||||||
None: no match
|
None: no match
|
||||||
"""
|
"""
|
||||||
def _log_prefix_rule_match_info(rule, record):
|
def _log_prefix_rule_match_info(rule, record, field_contents):
|
||||||
self.opts.log.info(" %s '%s' by %s (Prefix rule '%s')" %
|
self.opts.log.info(" %s '%s' by %s (%s: '%s' contains '%s')" %
|
||||||
(rule['prefix'],record['title'],
|
(rule['prefix'],record['title'],
|
||||||
record['authors'][0], rule['name']))
|
record['authors'][0], rule['name'],
|
||||||
|
self.db.metadata_for_field(rule['field'])['name'],
|
||||||
|
field_contents))
|
||||||
|
|
||||||
# Compare the record to each rule looking for a match
|
# Compare the record to each rule looking for a match
|
||||||
for rule in self.prefix_rules:
|
for rule in self.prefix_rules:
|
||||||
@ -592,11 +594,15 @@ class CatalogBuilder(object):
|
|||||||
field_contents = None
|
field_contents = None
|
||||||
|
|
||||||
if field_contents is not None:
|
if field_contents is not None:
|
||||||
|
if self.db.metadata_for_field(rule['field'])['datatype'] == 'bool':
|
||||||
|
# For Yes/No fields, need to translate field_contents to
|
||||||
|
# locale version
|
||||||
|
field_contents = _(repr(field_contents))
|
||||||
try:
|
try:
|
||||||
if re.search(rule['pattern'], unicode(field_contents),
|
if re.search(rule['pattern'], unicode(field_contents),
|
||||||
re.IGNORECASE) is not None:
|
re.IGNORECASE) is not None:
|
||||||
if self.opts.verbose:
|
if self.opts.verbose:
|
||||||
_log_prefix_rule_match_info(rule, record)
|
_log_prefix_rule_match_info(rule, record, field_contents)
|
||||||
return rule['prefix']
|
return rule['prefix']
|
||||||
except:
|
except:
|
||||||
if self.opts.verbose:
|
if self.opts.verbose:
|
||||||
@ -604,7 +610,7 @@ class CatalogBuilder(object):
|
|||||||
pass
|
pass
|
||||||
elif field_contents is None and rule['pattern'] == 'None':
|
elif field_contents is None and rule['pattern'] == 'None':
|
||||||
if self.opts.verbose:
|
if self.opts.verbose:
|
||||||
_log_prefix_rule_match_info(rule, record)
|
_log_prefix_rule_match_info(rule, record, field_contents)
|
||||||
return rule['prefix']
|
return rule['prefix']
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -4340,7 +4346,7 @@ class CatalogBuilder(object):
|
|||||||
""" Convert opts.prefix_rules to dict.
|
""" Convert opts.prefix_rules to dict.
|
||||||
|
|
||||||
Convert opts.prefix_rules to dict format. The model for a prefix rule is
|
Convert opts.prefix_rules to dict format. The model for a prefix rule is
|
||||||
('<rule name>','<source field>','<pattern>','<prefix>')
|
('<rule name>','<#source_field_lookup>','<pattern>','<prefix>')
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
opts.prefix_rules (tuples): (name, field, pattern, prefix)
|
opts.prefix_rules (tuples): (name, field, pattern, prefix)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user