Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: scripts/slave/apply_svn_patch.py

Issue 27575002: Patch path filtering script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Addressed comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | scripts/slave/patch_path_filter.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import optparse 6 import optparse
7 import subprocess 7 import subprocess
8 import sys 8 import sys
9 9
10 10
11 def main(): 11 def main():
12 parser = optparse.OptionParser() 12 parser = optparse.OptionParser()
13 parser.add_option('-p', '--patch-url', 13 parser.add_option('-p', '--patch-url',
14 help='The SVN URL to download the patch from.') 14 help='The SVN URL to download the patch from.')
15 parser.add_option('-r', '--root-dir', 15 parser.add_option('-r', '--root-dir',
16 help='The root dir in which to apply patch.') 16 help='The root dir in which to apply patch.')
17 parser.add_option('', '--filter-script',
18 help=('Path to a Python script to be used to manipulate '
19 'the contents of the patch. One example could be to '
20 'remove parts of the patch matching certain file '
21 'paths. The script must use stdin for input and '
22 'stdout for output. The script will get the '
23 '--root-dir flag passed on to it. To pass additional '
24 'flags; use: -- --flag1 --flag2'))
25 parser.add_option('', '--strip-level', type='int', default=0,
26 help=('The number of path components to be stripped from '
27 'the filenames in the patch. Default: %default.'))
17 28
18 options, args = parser.parse_args() 29 options, args = parser.parse_args()
19 if args: 30 if args and not options.filter_script:
20 parser.error('Unused args: %s' % args) 31 parser.error('Unused args: %s' % args)
32
21 if not (options.patch_url and options.root_dir): 33 if not (options.patch_url and options.root_dir):
22 parser.error('A patch URL and root directory should be specified.') 34 parser.error('A patch URL and root directory should be specified.')
23 35
24 svn_cat = subprocess.Popen(['svn', 'cat', options.patch_url], 36 svn_cat = subprocess.Popen(['svn', 'cat', options.patch_url],
25 stdout=subprocess.PIPE) 37 stdout=subprocess.PIPE)
26 patch = subprocess.Popen(['patch', '-t', '-p', '0', '-d', options.root_dir], 38 patch_input = svn_cat.stdout
27 stdin=svn_cat.stdout) 39 if options.filter_script:
40 extra_args = args or []
41 filtering = subprocess.Popen([sys.executable, options.filter_script,
42 '--root-dir', options.root_dir] + extra_args,
43 stdin=svn_cat.stdout, stdout=subprocess.PIPE,
44 stderr=sys.stdout)
45 patch_input = filtering.stdout
46 patch = subprocess.Popen(['patch', '-t', '-p', str(options.strip_level),
47 '-d', options.root_dir],
48 stdin=patch_input)
28 49
29 _, err = patch.communicate() 50 _, err = patch.communicate()
30 return err or None 51 return err or None
31 52
32 53
33 if __name__ == '__main__': 54 if __name__ == '__main__':
34 sys.exit(main()) 55 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/patch_path_filter.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698