| 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 |
|
| 39 |
parser = argparse.ArgumentParser( |
| 40 |
description='Adds/removes failures from the failure list.') |
| 41 |
parser.add_argument('filename', type=str, help='failure list file to update') |
| 42 |
parser.add_argument('--add', dest='add_list', action='append') |
| 43 |
parser.add_argument('--remove', dest='remove_list', action='append') |
| 44 |
|
| 45 |
args = parser.parse_args() |
| 46 |
|
| 47 |
add_set = set() |
| 48 |
remove_set = set() |
| 49 |
|
| 50 |
for add_file in (args.add_list or []): |
| 51 |
with open(add_file) as f: |
| 52 |
for line in f: |
| 53 |
add_set.add(line) |
| 54 |
|
| 55 |
for remove_file in (args.remove_list or []): |
| 56 |
with open(remove_file) as f: |
| 57 |
for line in f: |
| 58 |
if line in add_set: |
| 59 |
raise Exception("Asked to both add and remove test: " + line) |
| 60 |
remove_set.add(line.strip()) |
| 61 |
|
| 62 |
add_list = sorted(add_set, reverse=True) |
| 63 |
|
| 64 |
with open(args.filename) as in_file: |
| 65 |
existing_list = in_file.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) |