| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Protocol Buffers - Google's data interchange format | |
| 3 # Copyright 2008 Google Inc. All rights reserved. | |
| 4 # https://developers.google.com/protocol-buffers/ | |
| 5 # | |
| 6 # Redistribution and use in source and binary forms, with or without | |
| 7 # modification, are permitted provided that the following conditions are | |
| 8 # met: | |
| 9 # | |
| 10 # * Redistributions of source code must retain the above copyright | |
| 11 # notice, this list of conditions and the following disclaimer. | |
| 12 # * Redistributions in binary form must reproduce the above | |
| 13 # copyright notice, this list of conditions and the following disclaimer | |
| 14 # in the documentation and/or other materials provided with the | |
| 15 # distribution. | |
| 16 # * Neither the name of Google Inc. nor the names of its | |
| 17 # contributors may be used to endorse or promote products derived from | |
| 18 # this software without specific prior written permission. | |
| 19 # | |
| 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 31 | |
| 32 """Script to update a failure list file to add/remove failures. | |
| 33 | |
| 34 This is sort of like comm(1), except it recognizes comments and ignores them. | |
| 35 """ | |
| 36 | |
| 37 import argparse | |
| 38 import fileinput | |
| 39 | |
| 40 parser = argparse.ArgumentParser( | |
| 41 description='Adds/removes failures from the failure list.') | |
| 42 parser.add_argument('filename', type=str, help='failure list file to update') | |
| 43 parser.add_argument('--add', dest='add_list', action='append') | |
| 44 parser.add_argument('--remove', dest='remove_list', action='append') | |
| 45 | |
| 46 args = parser.parse_args() | |
| 47 | |
| 48 add_set = set() | |
| 49 remove_set = set() | |
| 50 | |
| 51 for add_file in (args.add_list or []): | |
| 52 with open(add_file) as f: | |
| 53 for line in f: | |
| 54 add_set.add(line) | |
| 55 | |
| 56 for remove_file in (args.remove_list or []): | |
| 57 with open(remove_file) as f: | |
| 58 for line in f: | |
| 59 if line in add_set: | |
| 60 raise "Asked to both add and remove test: " + line | |
| 61 remove_set.add(line.strip()) | |
| 62 | |
| 63 add_list = sorted(add_set, reverse=True) | |
| 64 | |
| 65 existing_list = file(args.filename).read() | |
| 66 | |
| 67 with open(args.filename, "w") as f: | |
| 68 for line in existing_list.splitlines(True): | |
| 69 test = line.split("#")[0].strip() | |
| 70 while len(add_list) > 0 and test > add_list[-1]: | |
| 71 f.write(add_list.pop()) | |
| 72 if test not in remove_set: | |
| 73 f.write(line) | |
| OLD | NEW |