OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import fnmatch | |
7 import os | |
8 import subprocess | |
9 | |
10 chromium_root_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), | |
11 os.pardir, os.pardir) | |
12 | |
13 def commit(message, cwd=None): | |
14 subprocess.call(['git', 'commit', '-a', '-m', message], cwd=cwd) | |
15 | |
16 def system(command, cwd=None): | |
17 return subprocess.check_output(command, cwd=cwd) | |
18 | |
19 def find(patterns, start='.'): | |
20 for path, dirs, files in os.walk(start): | |
21 for basename in files + dirs: | |
22 if any([fnmatch.fnmatch(basename, pattern) for pattern in patterns]): | |
23 filename = os.path.join(path, basename) | |
24 yield filename | |
25 | |
26 def filter_file(path, predicate): | |
27 with open(path, 'r+') as f: | |
28 lines = f.readlines() | |
29 new_lines = [line for line in lines if predicate(line)] | |
30 f.seek(0) | |
31 f.truncate() | |
32 f.write(''.join(new_lines)) | |
OLD | NEW |