OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """\ | 6 """\ |
7 Wrapper script around Rietveld's upload.py that simplifies working with groups | 7 Wrapper script around Rietveld's upload.py that simplifies working with groups |
8 of files. | 8 of files. |
9 """ | 9 """ |
10 | 10 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 """ | 278 """ |
279 # Kept for unit test support. This is for the old format, it's deprecated. | 279 # Kept for unit test support. This is for the old format, it's deprecated. |
280 SEPARATOR = "\n-----\n" | 280 SEPARATOR = "\n-----\n" |
281 | 281 |
282 def __init__(self, name, issue, patchset, description, files, local_root, | 282 def __init__(self, name, issue, patchset, description, files, local_root, |
283 rietveld_url, needs_upload): | 283 rietveld_url, needs_upload): |
284 self.name = name | 284 self.name = name |
285 self.issue = int(issue) | 285 self.issue = int(issue) |
286 self.patchset = int(patchset) | 286 self.patchset = int(patchset) |
287 self._description = None | 287 self._description = None |
288 self._subject = None | |
289 self._reviewers = None | 288 self._reviewers = None |
290 self._set_description(description) | 289 self._set_description(description) |
291 if files is None: | 290 if files is None: |
292 files = [] | 291 files = [] |
293 self._files = files | 292 self._files = files |
294 self.patch = None | 293 self.patch = None |
295 self._local_root = local_root | 294 self._local_root = local_root |
296 self.needs_upload = needs_upload | 295 self.needs_upload = needs_upload |
297 self.rietveld = gclient_utils.UpgradeToHttps( | 296 self.rietveld = gclient_utils.UpgradeToHttps( |
298 rietveld_url or GetCodeReviewSetting('CODE_REVIEW_SERVER')) | 297 rietveld_url or GetCodeReviewSetting('CODE_REVIEW_SERVER')) |
299 self._rpc_server = None | 298 self._rpc_server = None |
300 | 299 |
301 def _get_description(self): | 300 def _get_description(self): |
302 return self._description | 301 return self._description |
303 | 302 |
304 def _set_description(self, description): | 303 def _set_description(self, description): |
305 # TODO(dpranke): Cloned from git_cl.py. These should be shared. | 304 # TODO(dpranke): Cloned from git_cl.py. These should be shared. |
306 if not description: | 305 if not description: |
307 self._description = description | 306 self._description = description |
308 return | 307 return |
309 | 308 |
310 parsed_lines = [] | 309 parsed_lines = [] |
311 reviewers_re = re.compile(REVIEWERS_REGEX) | 310 reviewers_re = re.compile(REVIEWERS_REGEX) |
312 reviewers = '' | 311 reviewers = '' |
313 subject = '' | |
314 for l in description.splitlines(): | 312 for l in description.splitlines(): |
315 if not subject: | |
316 subject = l | |
317 matched_reviewers = reviewers_re.match(l) | 313 matched_reviewers = reviewers_re.match(l) |
318 if matched_reviewers: | 314 if matched_reviewers: |
319 reviewers = matched_reviewers.group(1).split(',') | 315 reviewers = matched_reviewers.group(1).split(',') |
320 parsed_lines.append(l) | 316 parsed_lines.append(l) |
321 | |
322 if len(subject) > 100: | |
323 subject = subject[:97] + '...' | |
324 | |
325 self._subject = subject | |
326 self._reviewers = reviewers | 317 self._reviewers = reviewers |
327 self._description = '\n'.join(parsed_lines) | 318 self._description = '\n'.join(parsed_lines) |
328 | 319 |
329 description = property(_get_description, _set_description) | 320 description = property(_get_description, _set_description) |
330 | 321 |
331 @property | 322 @property |
332 def reviewers(self): | 323 def reviewers(self): |
333 return self._reviewers | 324 return self._reviewers |
334 | 325 |
335 @property | |
336 def subject(self): | |
337 return self._subject | |
338 | |
339 def NeedsUpload(self): | 326 def NeedsUpload(self): |
340 return self.needs_upload | 327 return self.needs_upload |
341 | 328 |
342 def GetFileNames(self): | 329 def GetFileNames(self): |
343 """Returns the list of file names included in this change.""" | 330 """Returns the list of file names included in this change.""" |
344 return [f[1] for f in self._files] | 331 return [f[1] for f in self._files] |
345 | 332 |
346 def GetFiles(self): | 333 def GetFiles(self): |
347 """Returns the list of files included in this change with their status.""" | 334 """Returns the list of files included in this change with their status.""" |
348 return self._files | 335 return self._files |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 reviewers = change_info.reviewers or output.reviewers | 839 reviewers = change_info.reviewers or output.reviewers |
853 if (reviewers and | 840 if (reviewers and |
854 not any(arg.startswith('-r') or arg.startswith('--reviewer') for | 841 not any(arg.startswith('-r') or arg.startswith('--reviewer') for |
855 arg in args)): | 842 arg in args)): |
856 upload_arg.append('--reviewers=%s' % ','.join(reviewers)) | 843 upload_arg.append('--reviewers=%s' % ','.join(reviewers)) |
857 | 844 |
858 upload_arg.extend(args) | 845 upload_arg.extend(args) |
859 | 846 |
860 desc_file = None | 847 desc_file = None |
861 try: | 848 try: |
862 if change_info.issue: # Uploading a new patchset. | 849 if change_info.issue: |
863 found_message = False | 850 # Uploading a new patchset. |
864 for arg in args: | 851 upload_arg.append("--issue=%d" % change_info.issue) |
865 if arg.startswith("--message") or arg.startswith("-m"): | |
866 found_message = True | |
867 break | |
868 | 852 |
869 if not found_message: | 853 if not any(i.startswith('--message') or i.startswith('-m') for i in args): |
870 upload_arg.append("--message=''") | 854 upload_arg.append('--title= ') |
871 | 855 else: |
872 upload_arg.append("--issue=%d" % change_info.issue) | 856 # First time we upload. |
873 else: # First time we upload. | |
874 handle, desc_file = tempfile.mkstemp(text=True) | 857 handle, desc_file = tempfile.mkstemp(text=True) |
875 os.write(handle, change_info.description) | 858 os.write(handle, change_info.description) |
876 os.close(handle) | 859 os.close(handle) |
877 | 860 |
878 # Watchlist processing -- CC people interested in this changeset | 861 # Watchlist processing -- CC people interested in this changeset |
879 # http://dev.chromium.org/developers/contributing-code/watchlists | 862 # http://dev.chromium.org/developers/contributing-code/watchlists |
880 if not no_watchlists: | 863 if not no_watchlists: |
881 import watchlists | 864 import watchlists |
882 watchlist = watchlists.Watchlists(change_info.GetLocalRoot()) | 865 watchlist = watchlists.Watchlists(change_info.GetLocalRoot()) |
883 watchers = watchlist.GetWatchersForPaths(change_info.GetFileNames()) | 866 watchers = watchlist.GetWatchersForPaths(change_info.GetFileNames()) |
884 | 867 |
885 cc_list = GetCodeReviewSetting("CC_LIST") | 868 cc_list = GetCodeReviewSetting("CC_LIST") |
886 if not no_watchlists and watchers: | 869 if not no_watchlists and watchers: |
887 # Filter out all empty elements and join by ',' | 870 # Filter out all empty elements and join by ',' |
888 cc_list = ','.join(filter(None, [cc_list] + watchers)) | 871 cc_list = ','.join(filter(None, [cc_list] + watchers)) |
889 if cc_list: | 872 if cc_list: |
890 upload_arg.append("--cc=" + cc_list) | 873 upload_arg.append("--cc=" + cc_list) |
891 upload_arg.append("--description_file=%s" % desc_file) | 874 upload_arg.append("--file=%s" % desc_file) |
892 if change_info.subject: | |
893 upload_arg.append("--message=" + change_info.subject) | |
894 | 875 |
895 if GetCodeReviewSetting("PRIVATE") == "True": | 876 if GetCodeReviewSetting("PRIVATE") == "True": |
896 upload_arg.append("--private") | 877 upload_arg.append("--private") |
897 | 878 |
898 # If we have a lot of files with long paths, then we won't be able to fit | 879 # If we have a lot of files with long paths, then we won't be able to fit |
899 # the command to "svn diff". Instead, we generate the diff manually for | 880 # the command to "svn diff". Instead, we generate the diff manually for |
900 # each file and concatenate them before passing it to upload.py. | 881 # each file and concatenate them before passing it to upload.py. |
901 if change_info.patch is None: | 882 if change_info.patch is None: |
902 change_info.patch = GenerateDiff(change_info.GetFileNames()) | 883 change_info.patch = GenerateDiff(change_info.GetFileNames()) |
903 | 884 |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 raise | 1443 raise |
1463 print >> sys.stderr, ( | 1444 print >> sys.stderr, ( |
1464 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1445 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1465 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1446 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1466 return 1 | 1447 return 1 |
1467 | 1448 |
1468 | 1449 |
1469 if __name__ == "__main__": | 1450 if __name__ == "__main__": |
1470 fix_encoding.fix_encoding() | 1451 fix_encoding.fix_encoding() |
1471 sys.exit(main(sys.argv[1:])) | 1452 sys.exit(main(sys.argv[1:])) |
OLD | NEW |