本文整理汇总了Python中quodlibet.util.tagsfrompath.TagsFromPattern.match方法的典型用法代码示例。如果您正苦于以下问题:Python TagsFromPattern.match方法的具体用法?Python TagsFromPattern.match怎么用?Python TagsFromPattern.match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quodlibet.util.tagsfrompath.TagsFromPattern
的用法示例。
在下文中一共展示了TagsFromPattern.match方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_skip
# 需要导入模块: from quodlibet.util.tagsfrompath import TagsFromPattern [as 别名]
# 或者: from quodlibet.util.tagsfrompath.TagsFromPattern import match [as 别名]
def test_skip(self):
if os.name == "nt":
pat = TagsFromPattern('<path>\\<~>\\<~>\\<tracknumber> - <title>')
else:
pat = TagsFromPattern('<path>/<~>/<~>/<tracknumber> - <title>')
self.failUnlessEqual(len(pat.headers), 3)
song = pat.match({"~filename": self.f1})
self.failUnlessEqual(song.get("path"), "path")
self.failUnlessEqual(song.get("title"), "Title")
self.failIf(song.get("album"))
self.failIf(song.get("artist"))
示例2: test_songtypes
# 需要导入模块: from quodlibet.util.tagsfrompath import TagsFromPattern [as 别名]
# 或者: from quodlibet.util.tagsfrompath.TagsFromPattern import match [as 别名]
def test_songtypes(self):
from quodlibet import formats
pat = TagsFromPattern('<tracknumber>. <title>')
tracktitle = {'tracknumber': '01', 'title': 'Title'}
for ext, kind in formats._infos.iteritems():
f = formats._audio.AudioFile()
if not isinstance(kind, type):
continue
f.__class__ = kind
if os.name == "nt":
f["~filename"] = u'C:\\path\\Artist - Album\\01. Title' + ext
else:
f["~filename"] = '/path/Artist - Album/01. Title' + ext
self.assertEquals(pat.match(f), tracktitle, ext)
示例3: __preview
# 需要导入模块: from quodlibet.util.tagsfrompath import TagsFromPattern [as 别名]
# 或者: from quodlibet.util.tagsfrompath.TagsFromPattern import match [as 别名]
def __preview(self, songs):
if songs is None:
songs = [row[0].song for row in (self.view.get_model() or [])]
if songs:
pattern_text = gdecode(self.combo.get_child().get_text())
else:
pattern_text = ""
try:
pattern = TagsFromPattern(pattern_text)
except re.error:
qltk.ErrorMessage(
self, _("Invalid pattern"),
_("The pattern\n\t<b>%s</b>\nis invalid. "
"Possibly it contains the same tag twice or "
"it has unbalanced brackets (< / >).") % (
util.escape(pattern_text))).run()
return
else:
if pattern_text:
self.combo.prepend_text(pattern_text)
self.combo.write(TBP)
invalid = []
for header in pattern.headers:
if not min([song.can_change(header) for song in songs]):
invalid.append(header)
if len(invalid) and songs:
if len(invalid) == 1:
title = _("Invalid tag")
msg = _("Invalid tag <b>%s</b>\n\nThe files currently"
" selected do not support editing this tag.")
else:
title = _("Invalid tags")
msg = _("Invalid tags <b>%s</b>\n\nThe files currently"
" selected do not support editing these tags.")
qltk.ErrorMessage(
self, title, msg % ", ".join(invalid)).run()
pattern = TagsFromPattern("")
self.view.set_model(None)
model = ObjectStore()
for col in self.view.get_columns():
self.view.remove_column(col)
render = Gtk.CellRendererText()
col = TreeViewColumn(title=_('File'))
col.pack_start(render, True)
col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
def cell_data_file(column, cell, model, iter_, data):
entry = model.get_value(iter_)
cell.set_property("text", entry.name)
col.set_cell_data_func(render, cell_data_file)
def cell_data_header(column, cell, model, iter_, header):
entry = model.get_value(iter_)
cell.set_property("text", entry.get_match(header))
self.view.append_column(col)
for i, header in enumerate(pattern.headers):
render = Gtk.CellRendererText()
render.set_property('editable', True)
render.connect('edited', self.__row_edited, model, header)
escaped_title = header.replace("_", "__")
col = Gtk.TreeViewColumn(escaped_title, render)
col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
col.set_cell_data_func(render, cell_data_header, header)
self.view.append_column(col)
for song in songs:
entry = ListEntry(song)
match = pattern.match(song)
for h in pattern.headers:
text = match.get(h, '')
for f in self.filter_box.filters:
if f.active:
text = f.filter(h, text)
if not song.can_multiple_values(h):
text = u", ".join(text.split("\n"))
entry.matches[h] = text
model.append([entry])
# save for last to potentially save time
if songs:
self.view.set_model(model)
self.preview.set_sensitive(False)
self.save.set_sensitive(len(pattern.headers) > 0)
示例4: test_dict
# 需要导入模块: from quodlibet.util.tagsfrompath import TagsFromPattern [as 别名]
# 或者: from quodlibet.util.tagsfrompath.TagsFromPattern import match [as 别名]
def test_dict(self):
tracktitle = {'tracknumber': '01', 'title': 'Title'}
pat = TagsFromPattern('<tracknumber> - <title>')
self.assertEquals(pat.match({"~filename": self.f1}), tracktitle)