Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 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 """Defines class Rietveld to easily access a rietveld instance. | 5 """Defines class Rietveld to easily access a rietveld instance. |
| 6 | 6 |
| 7 Security implications: | 7 Security implications: |
| 8 | 8 |
| 9 The following hypothesis are made: | 9 The following hypothesis are made: |
| 10 - Rietveld enforces: | 10 - Rietveld enforces: |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 if not messages: | 438 if not messages: |
| 439 # Assumes self._lookup uses deepcopy. | 439 # Assumes self._lookup uses deepcopy. |
| 440 del data['messages'] | 440 del data['messages'] |
| 441 return data | 441 return data |
| 442 | 442 |
| 443 def get_patchset_properties(self, issue, patchset): | 443 def get_patchset_properties(self, issue, patchset): |
| 444 return self._lookup( | 444 return self._lookup( |
| 445 'get_patchset_properties', | 445 'get_patchset_properties', |
| 446 (issue, patchset), | 446 (issue, patchset), |
| 447 super(CachingRietveld, self).get_patchset_properties) | 447 super(CachingRietveld, self).get_patchset_properties) |
| 448 | |
| 449 | |
| 450 # Intentionally do not inherit from Rietveld to avoid any write-issuing | |
| 451 # logic to be invoked accidentally. | |
|
M-A Ruel
2013/09/19 22:20:27
put that in the docstring
Paweł Hajdan Jr.
2013/09/20 19:30:29
Done.
| |
| 452 class ReadOnlyRietveld(object): | |
| 453 """Only provides read operations, and simulates writes locally.""" | |
| 454 | |
| 455 # Dictionary of local changes, indexed by issue number as int. | |
| 456 _local_changes = {} | |
| 457 | |
| 458 def __init__(self, *args, **kwargs): | |
| 459 # We still need an actual Rietveld instance to issue reads, just keep | |
| 460 # it hidden. | |
| 461 self._rietveld = Rietveld(*args, **kwargs) | |
| 462 | |
| 463 @classmethod | |
| 464 def _get_local_changes(cls, issue): | |
| 465 """Returns dictionary of local changes for |issue|, if any.""" | |
| 466 return cls._local_changes.get(issue, {}) | |
| 467 | |
| 468 @property | |
| 469 def url(self): | |
| 470 return self._rietveld.url | |
| 471 | |
| 472 @property | |
| 473 def email(self): | |
| 474 return self._rietveld.email | |
| 475 | |
| 476 def get_pending_issues(self): | |
| 477 pending_issues = self._rietveld.get_pending_issues() | |
| 478 | |
| 479 # Filter out issues we've closed or unchecked the commit checkbox. | |
| 480 return [issue for issue in pending_issues | |
| 481 if not self._get_local_changes(issue).get('closed', False) and | |
| 482 self._get_local_changes(issue).get('commit', True)] | |
| 483 | |
| 484 def close_issue(self, issue): # pylint:disable=R0201 | |
| 485 logging.info('ReadOnlyRietveld: closing issue %d' % issue) | |
| 486 ReadOnlyRietveld._local_changes.setdefault(issue, {})['closed'] = True | |
| 487 | |
| 488 def get_issue_properties(self, issue, messages): | |
| 489 data = self._rietveld.get_issue_properties(issue, messages) | |
| 490 data.update(self._get_local_changes(issue)) | |
| 491 return data | |
| 492 | |
| 493 def get_patchset_properties(self, issue, patchset): | |
| 494 return self._rietveld.get_patchset_properties(issue, patchset) | |
| 495 | |
| 496 def get_patch(self, issue, patchset): | |
| 497 return self._rietveld.get_patch(issue, patchset) | |
| 498 | |
| 499 def update_description(self, issue, description): # pylint:disable=R0201 | |
| 500 logging.info('ReadOnlyRietveld: new description for issue %d: %s' % | |
| 501 (issue, description)) | |
| 502 | |
| 503 def add_comment(self, # pylint:disable=R0201 | |
| 504 issue, | |
| 505 message, | |
| 506 add_as_reviewer=False): | |
| 507 logging.info('ReadOnlyRietveld: posting comment "%s" to issue %d' % | |
| 508 (message, issue)) | |
| 509 | |
| 510 def set_flag(self, issue, patchset, flag, value): # pylint:disable=R0201 | |
| 511 logging.info('ReadOnlyRietveld: setting flag "%s" to "%s" for issue %d' % | |
| 512 (flag, value, issue)) | |
| 513 ReadOnlyRietveld._local_changes.setdefault(issue, {})[flag] = value | |
| 514 | |
| 515 def trigger_try_jobs( # pylint:disable=R0201 | |
| 516 self, issue, patchset, reason, clobber, revision, builders_and_tests): | |
| 517 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | |
| 518 (builders_and_tests, issue)) | |
| OLD | NEW |