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