[Android] Remove more uses of android_commands from build/android/pylib.
[chromium-blink-merge.git] / mojo / tools / utils.py
blob740b363330c85ea64946186062fcaaa472d90b60
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.
6 import fnmatch
7 import os
8 import subprocess
10 chromium_root_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
11 os.pardir, os.pardir)
13 def commit(message, cwd=None):
14 subprocess.call(['git', 'commit', '-a', '-m', message], cwd=cwd)
16 def system(command, cwd=None):
17 return subprocess.check_output(command, cwd=cwd)
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
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))