def _get_safelint_counts(filename):
 report_contents = _get_report_contents(filename)
 rule_count_regex = re.compile('^(?P<rule_id>[a-z-]+):\\s+(?P<count>\\d+) violations', re.MULTILINE)
 total_count_regex = re.compile('^(?P<count>\\d+) violations total', re.MULTILINE)
 violations = {'rules': {}}
 for violation_match in rule_count_regex.finditer(report_contents):
  try:
   violations['rules'][violation_match.group('rule_id')] = int(violation_match.group('count'))
  except ValueError:
   violations['rules'][violation_match.group('rule_id')] = None
 try:
  violations['total'] = int(total_count_regex.search(report_contents).group('count'))
 except (AttributeError, ValueError):
  violations['total'] = None
 return violations

def _get_safelint_counts ( filename ) : report_contents = _get_report_contents ( filename ) rule_count_regex = re . compile ( '^(?P<rule_id>[a-z-]+):\\s+(?P<count>\\d+) violations' , re . MULTILINE ) total_count_regex = re . compile ( '^(?P<count>\\d+) violations total' , re . MULTILINE ) violations = { 'rules' : { } } for violation_match in rule_count_regex . finditer ( report_contents ) : try : violations [ 'rules' ] [ violation_match . group ( 'rule_id' ) ] = int ( violation_match . group ( 'count' ) ) except ValueError : violations [ 'rules' ] [ violation_match . group ( 'rule_id' ) ] = None try : violations [ 'total' ] = int ( total_count_regex . search ( report_contents ) . group ( 'count' ) ) except ( AttributeError , ValueError ) : violations [ 'total' ] = None return violations
this returns a dict of violations from the safelint report .