本文整理汇总了Python中picard.script.ScriptParser.replace方法的典型用法代码示例。如果您正苦于以下问题:Python ScriptParser.replace方法的具体用法?Python ScriptParser.replace怎么用?Python ScriptParser.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类picard.script.ScriptParser
的用法示例。
在下文中一共展示了ScriptParser.replace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _script_to_filename
# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import replace [as 别名]
def _script_to_filename(self, format, file_metadata, settings=None):
if settings is None:
settings = config.setting
metadata = Metadata()
if config.setting["clear_existing_tags"]:
metadata.copy(file_metadata)
else:
metadata.copy(self.orig_metadata)
metadata.update(file_metadata)
# make sure every metadata can safely be used in a path name
for name in metadata.keys():
if isinstance(metadata[name], basestring):
metadata[name] = sanitize_filename(metadata[name])
format = format.replace("\t", "").replace("\n", "")
filename = ScriptParser().eval(format, metadata, self)
if settings["ascii_filenames"]:
if isinstance(filename, unicode):
filename = unaccent(filename)
filename = replace_non_ascii(filename)
# replace incompatible characters
if settings["windows_compatibility"] or sys.platform == "win32":
filename = replace_win32_incompat(filename)
# remove null characters
filename = filename.replace("\x00", "")
return filename
示例2: _make_image_filename
# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import replace [as 别名]
def _make_image_filename(self, filename, dirname, metadata):
filename = ScriptParser().eval(filename, metadata)
if config.setting["ascii_filenames"]:
if isinstance(filename, unicode):
filename = unaccent(filename)
filename = replace_non_ascii(filename)
if not filename:
filename = "cover"
if not os.path.isabs(filename):
filename = os.path.join(dirname, filename)
# replace incompatible characters
if config.setting["windows_compatibility"] or sys.platform == "win32":
filename = replace_win32_incompat(filename)
# remove null characters
filename = filename.replace("\x00", "")
return encode_filename(filename)
示例3: script_to_filename
# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import replace [as 别名]
def script_to_filename(naming_format, metadata, file=None, settings=None):
if settings is None:
settings = config.setting
# make sure every metadata can safely be used in a path name
for name in metadata:
values = [sanitize_filename(str(v)) for v in metadata.getall(name)]
metadata.set(name, values)
naming_format = naming_format.replace("\t", "").replace("\n", "")
filename = ScriptParser().eval(naming_format, metadata, file)
if settings["ascii_filenames"]:
filename = replace_non_ascii(filename, pathsave=True)
# replace incompatible characters
if settings["windows_compatibility"] or sys.platform == "win32":
filename = replace_win32_incompat(filename)
# remove null characters
filename = filename.replace("\x00", "")
return filename