blob: f8496686bbe82b631ceb747274ad75577286cbe9 [file] [log] [blame]
andrew@webrtc.org306e3312013-06-07 02:04:12 +00001#!/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
12Reads the contents of the filename given as the first argument and appends
13them to the root .gitignore file. The new entires are intended to be additional
14ignoring patterns, or negating patterns to override existing entries (man
15gitignore for more details).
16"""
17
18import os
19import sys
20
21MODIFY_STRING = '# The following added by %s\n'
22
andrew@webrtc.org9c498142013-06-07 15:43:04 +000023
andrew@webrtc.org306e3312013-06-07 02:04:12 +000024def main(argv):
25 if not argv[1]:
26 # Special case; do nothing.
27 return 0
28
andrew@webrtc.org9c498142013-06-07 15:43:04 +000029 modify_string = MODIFY_STRING % argv[0]
30 gitignore_file = os.path.dirname(argv[0]) + '/../../.gitignore'
andrew@webrtc.org306e3312013-06-07 02:04:12 +000031 lines = open(gitignore_file, 'r').readlines()
32 for i, line in enumerate(lines):
andrew@webrtc.org9c498142013-06-07 15:43:04 +000033 # Look for modify_string in the file to ensure we don't append the extra
34 # patterns more than once.
andrew@webrtc.org306e3312013-06-07 02:04:12 +000035 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
45if __name__ == '__main__':
46 sys.exit(main(sys.argv))