andrew@webrtc.org | 306e331 | 2013-06-07 02:04:12 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
| 9 | |
| 10 | """ Adds extra patterns to the root .gitignore file. |
| 11 | |
| 12 | Reads the contents of the filename given as the first argument and appends |
| 13 | them to the root .gitignore file. The new entires are intended to be additional |
| 14 | ignoring patterns, or negating patterns to override existing entries (man |
| 15 | gitignore for more details). |
| 16 | """ |
| 17 | |
| 18 | import os |
| 19 | import sys |
| 20 | |
| 21 | MODIFY_STRING = '# The following added by %s\n' |
| 22 | |
andrew@webrtc.org | 9c49814 | 2013-06-07 15:43:04 +0000 | [diff] [blame] | 23 | |
andrew@webrtc.org | 306e331 | 2013-06-07 02:04:12 +0000 | [diff] [blame] | 24 | def main(argv): |
| 25 | if not argv[1]: |
| 26 | # Special case; do nothing. |
| 27 | return 0 |
| 28 | |
andrew@webrtc.org | 9c49814 | 2013-06-07 15:43:04 +0000 | [diff] [blame] | 29 | modify_string = MODIFY_STRING % argv[0] |
| 30 | gitignore_file = os.path.dirname(argv[0]) + '/../../.gitignore' |
andrew@webrtc.org | 306e331 | 2013-06-07 02:04:12 +0000 | [diff] [blame] | 31 | lines = open(gitignore_file, 'r').readlines() |
| 32 | for i, line in enumerate(lines): |
andrew@webrtc.org | 9c49814 | 2013-06-07 15:43:04 +0000 | [diff] [blame] | 33 | # Look for modify_string in the file to ensure we don't append the extra |
| 34 | # patterns more than once. |
andrew@webrtc.org | 306e331 | 2013-06-07 02:04:12 +0000 | [diff] [blame] | 35 | if line == modify_string: |
| 36 | lines = lines[:i] |
| 37 | break |
| 38 | lines.append(modify_string) |
| 39 | |
| 40 | f = open(gitignore_file, 'w') |
| 41 | f.write(''.join(lines)) |
| 42 | f.write(open(argv[1], 'r').read()) |
| 43 | f.close() |
| 44 | |
| 45 | if __name__ == '__main__': |
| 46 | sys.exit(main(sys.argv)) |