本文整理汇总了Python中model.Task.add_rule方法的典型用法代码示例。如果您正苦于以下问题:Python Task.add_rule方法的具体用法?Python Task.add_rule怎么用?Python Task.add_rule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Task
的用法示例。
在下文中一共展示了Task.add_rule方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_task_process_rule
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import add_rule [as 别名]
def test_task_process_rule(capsys):
task = Task('./tests/music', '.*\.mp3')
rule = Rule(Artist='Metallica')
task.add_rule(rule)
task.process_rules()
out, err = capsys.readouterr()
assert out == 'Update some.mp3. Set Artist to Metallica\n'
示例2: make_task
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import add_rule [as 别名]
def make_task(script):
parsed_script = script_parser.parseString(open(script).read())
data = parsed_script and parsed_script[0] or {}
task = Task(root_dir=data['root_dir'], file_mask=data.get('mask'))
for rule in data['rules']:
task.add_rule(Rule(**rule))
return task
示例3: p_task
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import add_rule [as 别名]
def p_task(self, p):
'''task : with in rule_list
| in rule_list'''
if len(p) == 4:
_, file_mask, root_dir, rules = p
else:
_, root_dir, rules = p
file_mask = None
task = Task(root_dir, file_mask)
for rule in rules:
task.add_rule(rule)
p[0] = task
示例4: parse
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import add_rule [as 别名]
def parse(source):
task = Task()
get_value = lambda x: x.value
value_of = lambda t: some(lambda x: x.type == t) >> get_value
keyword = lambda s: skip(value_of(s))
make_rule = lambda x: task.add_rule(Rule(**{x[0]: x[1][1:-1]}))
set_root = lambda value: task.set_root_dir(value[1:-1])
set_mask = lambda value: task.set_mask(value[1:-1])
root = keyword('In') + value_of('Value') >> set_root
mask = keyword('With') + value_of('Value') >> set_mask
rule = keyword('Set') + \
value_of('Attribute') + \
keyword('Equals') + \
value_of('Value') \
>> make_rule
parser = maybe(mask) + root + many(rule)
parser.parse(source)
return task
示例5: Task
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import add_rule [as 别名]
from model import Task, Rule
ROOT_DIR = '../tests/music'
MASK = '.*\.mp3'
task = Task()
task.set_root_dir(ROOT_DIR)
task.set_mask(MASK)
task.add_rule(Rule(Artist='Metallica'))
task.add_rule(Rule(Genre='Rock'))
task.process_rules()
示例6: test_task_add_rule
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import add_rule [as 别名]
def test_task_add_rule():
task = Task('./')
rule = Rule(Artist='Metallica')
task.add_rule(rule)
assert len(task.rules) == 1
assert task.rules[0] == rule