Catalogs: Fix regression that broke use of prefix rules. Fixes #1070086 (Generate catalog (AZW3) fails with added prefix rule)

This commit is contained in:
Kovid Goyal 2012-10-23 19:06:42 +05:30
parent b0100977bd
commit 0c1cadeb89

View File

@ -569,12 +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, field_contents): def _log_prefix_rule_match_info(rule, record, matched):
self.opts.log.info(" %s '%s' by %s (%s: '%s' contains '%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'], self.db.metadata_for_field(rule['field'])['name'],
field_contents)) matched))
# 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:
@ -582,7 +582,7 @@ class CatalogBuilder(object):
if rule['field'].lower() == 'tags': if rule['field'].lower() == 'tags':
if rule['pattern'].lower() in map(unicode.lower,record['tags']): if rule['pattern'].lower() in map(unicode.lower,record['tags']):
if self.opts.verbose: if self.opts.verbose:
_log_prefix_rule_match_info(rule, record) _log_prefix_rule_match_info(rule, record, rule['pattern'])
return rule['prefix'] return rule['prefix']
# Regex match for custom field # Regex match for custom field
@ -649,7 +649,6 @@ class CatalogBuilder(object):
cl_list = [None] * len(item_list) cl_list = [None] * len(item_list)
last_ordnum = 0 last_ordnum = 0
last_c = u''
for idx, item in enumerate(item_list): for idx, item in enumerate(item_list):
if key: if key:
@ -659,9 +658,10 @@ class CatalogBuilder(object):
ordnum, ordlen = collation_order(c) ordnum, ordlen = collation_order(c)
if isosx and platform.mac_ver()[0] < '10.8': if isosx and platform.mac_ver()[0] < '10.8':
# Hackhackhackhackhack
# icu returns bogus results with curly apostrophes, maybe others under OS X 10.6.x # icu returns bogus results with curly apostrophes, maybe others under OS X 10.6.x
# When we see the magic combo of 0/-1 for ordnum/ordlen, special case the logic # When we see the magic combo of 0/-1 for ordnum/ordlen, special case the logic
last_c = u''
if ordnum == 0 and ordlen == -1: if ordnum == 0 and ordlen == -1:
if icu_upper(c[0]) != last_c: if icu_upper(c[0]) != last_c:
last_c = icu_upper(c[0]) last_c = icu_upper(c[0])