mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Remove duplicate tags when running tag mapper
This commit is contained in:
parent
f01a5ce349
commit
47e8cc3ff3
@ -40,9 +40,18 @@ def apply_rules(tag, rules):
|
|||||||
if ac == 'keep':
|
if ac == 'keep':
|
||||||
return tag
|
return tag
|
||||||
if ac == 'replace':
|
if ac == 'replace':
|
||||||
tag = regex.sub(rule['query'], rule['replace'], flags=REGEX_FLAGS)
|
tag = regex.sub(rule['query'], rule['replace'], tag, flags=REGEX_FLAGS)
|
||||||
return tag
|
return tag
|
||||||
|
|
||||||
|
def uniq(vals, kmap=icu_lower):
|
||||||
|
''' Remove all duplicates from vals, while preserving order. kmap must be a
|
||||||
|
callable that returns a hashable value for every item in vals '''
|
||||||
|
vals = vals or ()
|
||||||
|
lvals = (kmap(x) for x in vals)
|
||||||
|
seen = set()
|
||||||
|
seen_add = seen.add
|
||||||
|
return list(x for x, k in zip(vals, lvals) if k not in seen and not seen_add(k))
|
||||||
|
|
||||||
|
|
||||||
def map_tags(tags, rules=()):
|
def map_tags(tags, rules=()):
|
||||||
if not tags:
|
if not tags:
|
||||||
@ -50,4 +59,4 @@ def map_tags(tags, rules=()):
|
|||||||
if not rules:
|
if not rules:
|
||||||
return list(tags)
|
return list(tags)
|
||||||
rules = [(r, matcher(r)) for r in rules]
|
rules = [(r, matcher(r)) for r in rules]
|
||||||
return [x for x in (apply_rules(t, rules) for t in tags) if x]
|
return uniq([x for x in (apply_rules(t, rules) for t in tags) if x])
|
||||||
|
@ -225,7 +225,7 @@ class Rules(QWidget):
|
|||||||
d = RuleEditDialog(self)
|
d = RuleEditDialog(self)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
i = RuleItem(d.edit_widget.rule, self.rule_list)
|
i = RuleItem(d.edit_widget.rule, self.rule_list)
|
||||||
self.rule_list.scrollTo(i)
|
self.rule_list.scrollToItem(i)
|
||||||
|
|
||||||
def edit_rule(self):
|
def edit_rule(self):
|
||||||
i = self.rule_list.currentItem()
|
i = self.rule_list.currentItem()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user