mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-26 17:04:26 +01:00
Tag Mapper: Allow specifying a space as the split character when creating a split tags rule
This commit is contained in:
parent
b0318eed7a
commit
d9f30ffb89
2 changed files with 14 additions and 5 deletions
|
|
@ -161,6 +161,7 @@ def run(rules, tags, expected):
|
|||
run(rule('split', '/', '/', 'has'), '/,d', 'd')
|
||||
run(rule('split', '/', '/', 'has'), '/a/', 'a')
|
||||
run(rule('split', 'a,b', '/'), 'a,b', 'a,b')
|
||||
run(rule('split', 'a b', ' ', 'has'), 'a b', 'a,b')
|
||||
return unittest.defaultTestLoader.loadTestsFromTestCase(TestTagMapper)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@
|
|||
|
||||
tag_maps = JSONConfig('tag-map-rules')
|
||||
|
||||
def intelligent_strip(action, val):
|
||||
ans = val.strip()
|
||||
if not ans and action == 'split':
|
||||
ans = ' '
|
||||
return ans
|
||||
|
||||
class QueryEdit(QLineEdit):
|
||||
|
||||
def contextMenuEvent(self, ev):
|
||||
|
|
@ -151,11 +157,12 @@ def edit_tags(self):
|
|||
|
||||
@property
|
||||
def rule(self):
|
||||
ac = self.action.currentData()
|
||||
return {
|
||||
'action': self.action.currentData(),
|
||||
'action': ac,
|
||||
'match_type': self.match_type.currentData(),
|
||||
'query': self.query.text().strip(),
|
||||
'replace': self.replace.text().strip(),
|
||||
'query': intelligent_strip(ac, self.query.text()),
|
||||
'replace': intelligent_strip(ac, self.replace.text()),
|
||||
}
|
||||
|
||||
@rule.setter
|
||||
|
|
@ -167,8 +174,9 @@ def sc(name):
|
|||
idx = 0
|
||||
c.setCurrentIndex(idx)
|
||||
sc('action'), sc('match_type')
|
||||
self.query.setText(unicode(rule.get('query', '')).strip())
|
||||
self.replace.setText(unicode(rule.get('replace', '')).strip())
|
||||
ac = self.action.currentData()
|
||||
self.query.setText(intelligent_strip(ac, unicode(rule.get('query', ''))))
|
||||
self.replace.setText(intelligent_strip(ac, unicode(rule.get('replace', ''))))
|
||||
|
||||
def validate(self):
|
||||
rule = self.rule
|
||||
|
|
|
|||
Loading…
Reference in a new issue