 Chromium Code Reviews
 Chromium Code Reviews Issue 543012:
  Add the capability to filter out files on try job with regexp.  (Closed)
    
  
    Issue 543012:
  Add the capability to filter out files on try job with regexp.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python | 
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 """Client-side script to send a try job to the try server. It communicates to | 5 """Client-side script to send a try job to the try server. It communicates to | 
| 6 the try server by either writting to a svn repository or by directly connecting | 6 the try server by either writting to a svn repository or by directly connecting | 
| 7 to the server by HTTP. | 7 to the server by HTTP. | 
| 8 """ | 8 """ | 
| 9 | 9 | 
| 10 import datetime | 10 import datetime | 
| 11 import errno | 11 import errno | 
| 12 import getpass | 12 import getpass | 
| 13 import logging | 13 import logging | 
| 14 import optparse | 14 import optparse | 
| 15 import os | 15 import os | 
| 16 import posixpath | 16 import posixpath | 
| 17 import re | |
| 17 import shutil | 18 import shutil | 
| 18 import sys | 19 import sys | 
| 19 import tempfile | 20 import tempfile | 
| 20 import urllib | 21 import urllib | 
| 21 | 22 | 
| 22 try: | 23 try: | 
| 23 import breakpad | 24 import breakpad | 
| 24 except ImportError: | 25 except ImportError: | 
| 25 pass | 26 pass | 
| 26 | 27 | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 168 | 
| 168 def GenerateDiff(self): | 169 def GenerateDiff(self): | 
| 169 """Returns a string containing the diff for the given file list. | 170 """Returns a string containing the diff for the given file list. | 
| 170 | 171 | 
| 171 The files in the list should either be absolute paths or relative to the | 172 The files in the list should either be absolute paths or relative to the | 
| 172 given root. | 173 given root. | 
| 173 """ | 174 """ | 
| 174 if not self.files: | 175 if not self.files: | 
| 175 previous_cwd = os.getcwd() | 176 previous_cwd = os.getcwd() | 
| 176 os.chdir(self.checkout_root) | 177 os.chdir(self.checkout_root) | 
| 178 | |
| 177 excluded = ['!', '?', 'X', ' ', '~'] | 179 excluded = ['!', '?', 'X', ' ', '~'] | 
| 180 def Excluded(f): | |
| 181 if f[0][0] in excluded: | |
| 182 return True | |
| 183 for r in self.options.exclude: | |
| 184 if re.search(r, f[1]): | |
| 185 logging.info('Ignoring "%s"' % f[1]) | |
| 186 return True | |
| 187 return False | |
| 188 | |
| 178 self.files = [ | 189 self.files = [ | 
| 
bradn
2010/01/12 04:39:12
I think the style guide wants the braces tighter:
 | |
| 179 f[1] for f in scm.SVN.CaptureStatus(self.checkout_root) | 190 f[1] for f in scm.SVN.CaptureStatus(self.checkout_root) | 
| 180 if f[0][0] not in excluded | 191 if not Excluded(f) | 
| 181 ] | 192 ] | 
| 182 os.chdir(previous_cwd) | 193 os.chdir(previous_cwd) | 
| 183 return scm.SVN.GenerateDiff(self.files, self.checkout_root, full_move=True, | 194 return scm.SVN.GenerateDiff(self.files, self.checkout_root, full_move=True, | 
| 184 revision=self.diff_against) | 195 revision=self.diff_against) | 
| 185 | 196 | 
| 186 | 197 | 
| 187 class GIT(SCM): | 198 class GIT(SCM): | 
| 188 """Gathers the options and diff for a git checkout.""" | 199 """Gathers the options and diff for a git checkout.""" | 
| 189 def __init__(self, *args, **kwargs): | 200 def __init__(self, *args, **kwargs): | 
| 190 SCM.__init__(self, *args, **kwargs) | 201 SCM.__init__(self, *args, **kwargs) | 
| 191 self.checkout_root = scm.GIT.GetCheckoutRoot(self.checkout_root) | 202 self.checkout_root = scm.GIT.GetCheckoutRoot(self.checkout_root) | 
| 192 if not self.options.name: | 203 if not self.options.name: | 
| 193 self.options.name = scm.GIT.GetPatchName(self.checkout_root) | 204 self.options.name = scm.GIT.GetPatchName(self.checkout_root) | 
| 194 if not self.options.email: | 205 if not self.options.email: | 
| 195 self.options.email = scm.GIT.GetEmail(self.checkout_root) | 206 self.options.email = scm.GIT.GetEmail(self.checkout_root) | 
| 196 logging.info("GIT(%s)" % self.checkout_root) | 207 logging.info("GIT(%s)" % self.checkout_root) | 
| 197 | 208 | 
| 198 def ReadRootFile(self, filename): | 209 def ReadRootFile(self, filename): | 
| 199 try: | 210 try: | 
| 200 # A git checkout is always a full checkout. | 211 # A git checkout is always a full checkout. | 
| 201 data = gclient_utils.FileRead(os.path.join(self.checkout_root, filename)) | 212 data = gclient_utils.FileRead(os.path.join(self.checkout_root, filename)) | 
| 202 logging.debug('%s:\n%s' % (filename, data)) | 213 logging.debug('%s:\n%s' % (filename, data)) | 
| 203 return data | 214 return data | 
| 204 except (IOError, OSError): | 215 except (IOError, OSError): | 
| 205 logging.debug('%s:\nNone' % filename) | 216 logging.debug('%s:\nNone' % filename) | 
| 206 return None | 217 return None | 
| 207 | 218 | 
| 208 def GenerateDiff(self): | 219 def GenerateDiff(self): | 
| 209 # For now, ignores self.files | 220 if not self.files: | 
| 210 return scm.GIT.GenerateDiff(self.checkout_root, full_move=True, | 221 self.files = scm.GIT.GetDifferentFiles(self.checkout_root, | 
| 222 branch=self.diff_against) | |
| 223 | |
| 224 def NotExcluded(f): | |
| 225 for r in self.options.exclude: | |
| 226 if re.search(r, f): | |
| 227 logging.info('Ignoring "%s"' % f) | |
| 228 return False | |
| 229 return True | |
| 230 | |
| 231 self.files = filter(NotExcluded, self.files) | |
| 232 return scm.GIT.GenerateDiff(self.checkout_root, files=self.files, | |
| 233 full_move=True, | |
| 211 branch=self.diff_against) | 234 branch=self.diff_against) | 
| 212 | 235 | 
| 213 | 236 | 
| 214 def _ParseSendChangeOptions(options): | 237 def _ParseSendChangeOptions(options): | 
| 215 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" | 238 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" | 
| 216 values = {} | 239 values = {} | 
| 217 if options.email: | 240 if options.email: | 
| 218 values['email'] = options.email | 241 values['email'] = options.email | 
| 219 values['user'] = options.user | 242 values['user'] = options.user | 
| 220 values['name'] = options.name | 243 values['name'] = options.name | 
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 help="Used as -pN parameter to patch") | 505 help="Used as -pN parameter to patch") | 
| 483 group.add_option("-s", "--sub_rep", action="append", default=[], | 506 group.add_option("-s", "--sub_rep", action="append", default=[], | 
| 484 help="Subcheckout to use in addition. This is mainly " | 507 help="Subcheckout to use in addition. This is mainly " | 
| 485 "useful for gclient-style checkouts. Use @rev or " | 508 "useful for gclient-style checkouts. Use @rev or " | 
| 486 "@branch or @branch1..branch2 to specify the " | 509 "@branch or @branch1..branch2 to specify the " | 
| 487 "revision/branch to diff against.") | 510 "revision/branch to diff against.") | 
| 488 # Mostly chromium-specific | 511 # Mostly chromium-specific | 
| 489 try: | 512 try: | 
| 490 group.add_option("--webkit", action="append_const", | 513 group.add_option("--webkit", action="append_const", | 
| 491 const="third_party/WebKit", | 514 const="third_party/WebKit", | 
| 492 dest="sub_rep", | 515 dest="PATH", | 
| 493 help="Shorthand for -s third_party/WebKit") | 516 help="Shorthand for -s third_party/WebKit") | 
| 494 except optparse.OptionError: | 517 except optparse.OptionError: | 
| 495 # append_const is not supported on 2.4. Too bad. | 518 # append_const is not supported on 2.4. Too bad. | 
| 496 pass | 519 pass | 
| 497 group.add_option("--no_gclient", action="store_true", | 520 group.add_option("--no_gclient", action="store_true", | 
| 498 help="Disable automatic search for gclient checkout.") | 521 help="Disable automatic search for gclient checkout.") | 
| 522 group.add_option("-E", "--exclude", action="append", | |
| 523 default=['ChangeLog'], metavar='REGEXP', | |
| 524 help="Regexp patterns to exclude files. Default: %default") | |
| 499 parser.add_option_group(group) | 525 parser.add_option_group(group) | 
| 500 | 526 | 
| 501 group = optparse.OptionGroup(parser, "Access the try server by HTTP") | 527 group = optparse.OptionGroup(parser, "Access the try server by HTTP") | 
| 502 group.add_option("--use_http", | 528 group.add_option("--use_http", | 
| 503 action="store_const", | 529 action="store_const", | 
| 504 const=_SendChangeHTTP, | 530 const=_SendChangeHTTP, | 
| 505 dest="send_patch", | 531 dest="send_patch", | 
| 506 help="Use HTTP to talk to the try server [default]") | 532 help="Use HTTP to talk to the try server [default]") | 
| 507 group.add_option("-H", "--host", | 533 group.add_option("-H", "--host", | 
| 508 help="Host address") | 534 help="Host address") | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 except (InvalidScript, NoTryServerAccess), e: | 668 except (InvalidScript, NoTryServerAccess), e: | 
| 643 if swallow_exception: | 669 if swallow_exception: | 
| 644 return 1 | 670 return 1 | 
| 645 print e | 671 print e | 
| 646 return 1 | 672 return 1 | 
| 647 return 0 | 673 return 0 | 
| 648 | 674 | 
| 649 | 675 | 
| 650 if __name__ == "__main__": | 676 if __name__ == "__main__": | 
| 651 sys.exit(TryChange(None, [], False)) | 677 sys.exit(TryChange(None, [], False)) | 
| OLD | NEW |