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

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: Now using patch.py and its test data 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') | scripts/slave/patch_path_filter.py » ('J')
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('', '--path-filter-script',
18 help=('A script that filter out contents of a patch. The '
iannucci 2013/12/05 21:40:57 s/filter/filters/ Should also mention that the sc
kjellander_chromium 2013/12/10 20:46:02 I rephrased so it shouldn't be needed now. I also
19 'script must use stdin for input and stdout for '
20 'output.'))
21 parser.add_option('', '--path-filter',
22 help=('The paths that shall be allowed (must specify the '
23 'path filter script to use this).'))
iannucci 2013/12/05 21:40:57 What about: apply_svn_patch.py ... --path-filter-
kjellander_chromium 2013/12/10 20:46:02 I guess this makes perfect sense for --path-filter
24 parser.add_option('', '--strip-level', type='int', default=0,
25 help=('The number of components to be stripped from the '
26 'filenames in the patch. Default: %default.'))
17 27
18 options, args = parser.parse_args() 28 options, args = parser.parse_args()
19 if args: 29 if args:
20 parser.error('Unused args: %s' % args) 30 parser.error('Unused args: %s' % args)
21 if not (options.patch_url and options.root_dir): 31 if not (options.patch_url and options.root_dir):
22 parser.error('A patch URL and root directory should be specified.') 32 parser.error('A patch URL and root directory should be specified.')
33 if ((options.path_filter_script and not options.path_filter) or
34 (options.path_filter and not options.path_filter_script)):
35 parser.error('You must specify both path filter and a path filter script '
36 'in order to use path filtering for patches.')
23 37
24 svn_cat = subprocess.Popen(['svn', 'cat', options.patch_url], 38 svn_cat = subprocess.Popen(['svn', 'cat', options.patch_url],
25 stdout=subprocess.PIPE) 39 stdout=subprocess.PIPE)
26 patch = subprocess.Popen(['patch', '-t', '-p', '0', '-d', options.root_dir], 40 patch_input = svn_cat.stdout
27 stdin=svn_cat.stdout) 41 if options.path_filter_script:
42 filtering = subprocess.Popen([sys.executable, options.path_filter_script,
43 '-f', options.path_filter,
44 '-r', options.root_dir],
45 stdin=svn_cat.stdout, stdout=subprocess.PIPE)
46 patch_input = filtering.stdout
47 patch = subprocess.Popen(['patch', '-t', '-p', str(options.strip_level),
48 '-d', options.root_dir],
49 stdin=patch_input)
28 50
29 _, err = patch.communicate() 51 _, err = patch.communicate()
30 return err or None 52 return err or None
31 53
32 54
33 if __name__ == '__main__': 55 if __name__ == '__main__':
34 sys.exit(main()) 56 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/patch_path_filter.py » ('j') | scripts/slave/patch_path_filter.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698