OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 'rietveld': self.rietveld, | 336 'rietveld': self.rietveld, |
337 }, sort_keys=True, indent=2) | 337 }, sort_keys=True, indent=2) |
338 gclient_utils.FileWrite(GetChangelistInfoFile(self.name), data) | 338 gclient_utils.FileWrite(GetChangelistInfoFile(self.name), data) |
339 | 339 |
340 def Delete(self): | 340 def Delete(self): |
341 """Removes the changelist information from disk.""" | 341 """Removes the changelist information from disk.""" |
342 os.remove(GetChangelistInfoFile(self.name)) | 342 os.remove(GetChangelistInfoFile(self.name)) |
343 | 343 |
344 def CloseIssue(self): | 344 def CloseIssue(self): |
345 """Closes the Rietveld issue for this changelist.""" | 345 """Closes the Rietveld issue for this changelist.""" |
346 data = [("description", self.description),] | 346 # Newer versions of Rietveld require us to pass an XSRF token to POST, so |
| 347 # we fetch it from the server. |
| 348 xsrf_token = self.SendToRietveld( |
| 349 '/xsrf_token', |
| 350 extra_headers={'X-Requesting-XSRF-Token': '1'}) |
| 351 |
| 352 # You cannot close an issue with a GET. |
| 353 # We pass an empty string for the data so it is a POST rather than a GET. |
| 354 data = [("description", self.description), |
| 355 ("xsrf_token", xsrf_token)] |
347 ctype, body = upload.EncodeMultipartFormData(data, []) | 356 ctype, body = upload.EncodeMultipartFormData(data, []) |
348 self.SendToRietveld('/%d/close' % self.issue, body, ctype) | 357 self.SendToRietveld('/%d/close' % self.issue, payload=body, |
| 358 content_type=ctype) |
349 | 359 |
350 def UpdateRietveldDescription(self): | 360 def UpdateRietveldDescription(self): |
351 """Sets the description for an issue on Rietveld.""" | 361 """Sets the description for an issue on Rietveld.""" |
352 data = [("description", self.description),] | 362 data = [("description", self.description),] |
353 ctype, body = upload.EncodeMultipartFormData(data, []) | 363 ctype, body = upload.EncodeMultipartFormData(data, []) |
354 self.SendToRietveld('/%d/description' % self.issue, body, ctype) | 364 self.SendToRietveld('/%d/description' % self.issue, payload=body, |
| 365 content_type=ctype) |
355 | 366 |
356 def GetIssueDescription(self): | 367 def GetIssueDescription(self): |
357 """Returns the issue description from Rietveld.""" | 368 """Returns the issue description from Rietveld.""" |
358 return self.SendToRietveld('/%d/description' % self.issue) | 369 return self.SendToRietveld('/%d/description' % self.issue) |
359 | 370 |
360 def PrimeLint(self): | 371 def PrimeLint(self): |
361 """Do background work on Rietveld to lint the file so that the results are | 372 """Do background work on Rietveld to lint the file so that the results are |
362 ready when the issue is viewed.""" | 373 ready when the issue is viewed.""" |
363 if self.issue and self.patchset: | 374 if self.issue and self.patchset: |
364 self.SendToRietveld('/lint/issue%s_%s' % (self.issue, self.patchset), | 375 self.SendToRietveld('/lint/issue%s_%s' % (self.issue, self.patchset), |
365 timeout=1) | 376 timeout=1) |
366 | 377 |
367 def SendToRietveld(self, request_path, payload=None, | 378 def SendToRietveld(self, request_path, timeout=None, **kwargs): |
368 content_type="application/octet-stream", timeout=None): | |
369 """Send a POST/GET to Rietveld. Returns the response body.""" | 379 """Send a POST/GET to Rietveld. Returns the response body.""" |
370 if not self.rietveld: | 380 if not self.rietveld: |
371 ErrorExit(CODEREVIEW_SETTINGS_FILE_NOT_FOUND) | 381 ErrorExit(CODEREVIEW_SETTINGS_FILE_NOT_FOUND) |
372 def GetUserCredentials(): | 382 def GetUserCredentials(): |
373 """Prompts the user for a username and password.""" | 383 """Prompts the user for a username and password.""" |
374 email = upload.GetEmail('Email (login for uploading to %s)' % | 384 email = upload.GetEmail('Email (login for uploading to %s)' % |
375 self.rietveld) | 385 self.rietveld) |
376 password = getpass.getpass('Password for %s: ' % email) | 386 password = getpass.getpass('Password for %s: ' % email) |
377 return email, password | 387 return email, password |
378 rpc_server = upload.HttpRpcServer(self.rietveld, | 388 rpc_server = upload.HttpRpcServer(self.rietveld, |
379 GetUserCredentials, | 389 GetUserCredentials, |
380 save_cookies=True) | 390 save_cookies=True) |
381 try: | 391 try: |
382 return rpc_server.Send(request_path, payload, content_type, timeout) | 392 return rpc_server.Send(request_path, timeout=timeout, **kwargs) |
383 except urllib2.URLError: | 393 except urllib2.URLError: |
384 if timeout is None: | 394 if timeout is None: |
385 ErrorExit('Error accessing url %s' % request_path) | 395 ErrorExit('Error accessing url %s' % request_path) |
386 else: | 396 else: |
387 return None | 397 return None |
388 | 398 |
389 def MissingTests(self): | 399 def MissingTests(self): |
390 """Returns True if the change looks like it needs unit tests but has none. | 400 """Returns True if the change looks like it needs unit tests but has none. |
391 | 401 |
392 A change needs unit tests if it contains any new source files or methods. | 402 A change needs unit tests if it contains any new source files or methods. |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 if e.code != 500: | 1389 if e.code != 500: |
1380 raise | 1390 raise |
1381 print >> sys.stderr, ( | 1391 print >> sys.stderr, ( |
1382 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1392 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1383 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1393 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1384 return 1 | 1394 return 1 |
1385 | 1395 |
1386 | 1396 |
1387 if __name__ == "__main__": | 1397 if __name__ == "__main__": |
1388 sys.exit(main(sys.argv[1:])) | 1398 sys.exit(main(sys.argv[1:])) |
OLD | NEW |