Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2015 The PDFium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import os |
| 7 | |
| 8 | import common |
| 9 | |
| 10 | class Suppressor: |
Tom Sepez | 5c1efd4 | 2016-01-19 15:05:36 -0800 | [diff] [blame^] | 11 | def __init__(self, finder, feature_string): |
| 12 | feature_vector = feature_string.strip().split(",") |
| 13 | v8_option = ["nov8", "v8"]["V8" in feature_vector] |
| 14 | xfa_option = ["noxfa", "xfa"]["XFA" in feature_vector] |
Tom Sepez | acfe9a7 | 2016-01-19 11:28:59 -0800 | [diff] [blame] | 15 | with open(os.path.join(finder.TestingDir(), 'SUPPRESSIONS')) as f: |
| 16 | self.suppression_set = set(self._FilterSuppressions( |
Tom Sepez | 5c1efd4 | 2016-01-19 15:05:36 -0800 | [diff] [blame^] | 17 | common.os_name(), v8_option, xfa_option, self._ExtractSuppressions(f))) |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 18 | |
Tom Sepez | acfe9a7 | 2016-01-19 11:28:59 -0800 | [diff] [blame] | 19 | def _ExtractSuppressions(self, f): |
| 20 | return [y.split(' ') for y in |
| 21 | [x.split('#')[0].strip() for x in |
| 22 | f.readlines()] if y] |
| 23 | |
| 24 | def _FilterSuppressions(self, os, js, xfa, unfiltered_list): |
| 25 | return [x[0] for x in unfiltered_list |
| 26 | if self._MatchSuppression(x, os, js, xfa)] |
| 27 | |
| 28 | def _MatchSuppression(self, item, os, js, xfa): |
| 29 | os_column = item[1].split(","); |
| 30 | js_column = item[2].split(","); |
| 31 | xfa_column = item[3].split(","); |
| 32 | return (('*' in os_column or os in os_column) and |
| 33 | ('*' in js_column or js in js_column) and |
| 34 | ('*' in xfa_column or xfa in xfa_column)) |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 35 | |
| 36 | def IsSuppressed(self, input_filename): |
Tom Sepez | acfe9a7 | 2016-01-19 11:28:59 -0800 | [diff] [blame] | 37 | if input_filename in self.suppression_set: |
| 38 | print "%s is suppressed" % input_filename |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 39 | return True |
| 40 | return False |