1#!/usr/bin/env python 2# Copyright 2013 The Flutter 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 6import fnmatch 7import os 8import subprocess 9 10def commit(message, cwd=None): 11 subprocess.call(['git', 'commit', '-a', '-m', message], cwd=cwd) 12 13def system(command, cwd=None): 14 return subprocess.check_output(command, cwd=cwd) 15 16def find(patterns, start='.'): 17 for path, dirs, files in os.walk(start): 18 for basename in files + dirs: 19 if any([fnmatch.fnmatch(basename, pattern) for pattern in patterns]): 20 filename = os.path.join(path, basename) 21 yield filename 22 23def filter_file(path, predicate): 24 with open(path, 'r+') as f: 25 lines = f.readlines() 26 new_lines = [line for line in lines if predicate(line)] 27 f.seek(0) 28 f.truncate() 29 f.write(''.join(new_lines)) 30