update_failure_list.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. """Script to update a failure list file to add/remove failures.
  32. This is sort of like comm(1), except it recognizes comments and ignores them.
  33. """
  34. import argparse
  35. parser = argparse.ArgumentParser(
  36. description='Adds/removes failures from the failure list.')
  37. parser.add_argument('filename', type=str, help='failure list file to update')
  38. parser.add_argument('--add', dest='add_list', action='append')
  39. parser.add_argument('--remove', dest='remove_list', action='append')
  40. args = parser.parse_args()
  41. add_set = set()
  42. remove_set = set()
  43. for add_file in (args.add_list or []):
  44. with open(add_file) as f:
  45. for line in f:
  46. add_set.add(line)
  47. for remove_file in (args.remove_list or []):
  48. with open(remove_file) as f:
  49. for line in f:
  50. if line in add_set:
  51. raise Exception("Asked to both add and remove test: " + line)
  52. remove_set.add(line.strip())
  53. add_list = sorted(add_set, reverse=True)
  54. with open(args.filename) as in_file:
  55. existing_list = in_file.read()
  56. with open(args.filename, "w") as f:
  57. for line in existing_list.splitlines(True):
  58. test = line.split("#")[0].strip()
  59. while len(add_list) > 0 and test > add_list[-1]:
  60. f.write(add_list.pop())
  61. if test not in remove_set:
  62. f.write(line)