def apply_rules(ruletype, gcpobjects, descfield, outfile, project):
rules = loadrules(ruletype)
for obj in gcpobjects:
for rule in rules:
if 'filtercondition' in rule:
res = apply_rule_filters(obj, rule['filters'],
rule['filtercondition'])
else:
res = apply_rule_filters(obj, rule['filters'])
if res:
print colored('MATCH:', 'red'), \
"object '%s' matches rule '%s'" \
% (obj[descfield], rule['name'])
with open(outfile, 'a') as f:
f.write(datetime.datetime.now().ctime()
+ ": Project: " + project
+ " | Object: " + obj[descfield]
+ " | Matches rule: " + rule['name']
+ "\n" + json.dumps(obj) + "\n\n")
评论列表
文章目录