Tag Mapper: Allow specifying a space as the split character when creating a split tags rule

This commit is contained in:
Kovid Goyal 2016-07-07 08:50:31 +05:30
parent b0318eed7a
commit d9f30ffb89
2 changed files with 14 additions and 5 deletions

View File

@ -161,6 +161,7 @@ def find_tests():
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__':

View File

@ -24,6 +24,12 @@ from calibre.utils.localization import localize_user_manual_link
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 @@ class RuleEdit(QWidget):
@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 @@ class RuleEdit(QWidget):
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