Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import re | 7 import re |
| 8 import subprocess | 8 import subprocess |
| 9 import urllib2 | 9 import urllib2 |
| 10 | 10 |
| 11 from common import cache_decorator | |
| 12 | |
| 11 CODE_REVIEW_URL_PATTERN = re.compile( | 13 CODE_REVIEW_URL_PATTERN = re.compile( |
| 12 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) | 14 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) |
| 13 COMMIT_POSITION_PATTERN = re.compile( | 15 COMMIT_POSITION_PATTERN = re.compile( |
| 14 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) | 16 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) |
| 15 REVERTED_REVISION_PATTERN = re.compile( | 17 REVERTED_REVISION_PATTERN = re.compile( |
| 16 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE) | 18 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE) |
| 17 COMMIT_POSITION_CODE_REVIEW_URL_PARSING_START_LINE = -5 | 19 COMMIT_POSITION_CODE_REVIEW_URL_PARSING_START_LINE = -5 |
| 18 | 20 |
| 19 | 21 |
| 20 def ExtractCommitPositionAndCodeReviewUrl(message): | 22 def ExtractCommitPositionAndCodeReviewUrl(message): |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 if not lines[0].lower().startswith('revert'): | 71 if not lines[0].lower().startswith('revert'): |
| 70 return None | 72 return None |
| 71 | 73 |
| 72 for line in reversed(lines): # pragma: no cover | 74 for line in reversed(lines): # pragma: no cover |
| 73 # TODO: Handle cases where no reverted_revision in reverting message. | 75 # TODO: Handle cases where no reverted_revision in reverting message. |
| 74 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) | 76 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) |
| 75 if reverted_revision_match: | 77 if reverted_revision_match: |
| 76 return reverted_revision_match.group(1) | 78 return reverted_revision_match.group(1) |
| 77 | 79 |
| 78 | 80 |
| 79 # TODO(katesonia): Add local cache for this function. | 81 @cache_decorator.Cached('Command-output', cacher=cache_decorator.LocalCacher()) |
|
Martin Barbella
2016/10/26 23:21:20
Is the format used here for the namespace consiste
Sharu Jiang
2016/10/27 21:59:05
The other 2 are 'Gitiles-json-view' for SendReques
| |
| 80 def GetCommandOutput(command): | 82 def GetCommandOutput(command): |
| 81 """Gets the output stream of executable command. | 83 """Gets the output stream of executable command. |
| 82 | 84 |
| 83 Args: | 85 Args: |
| 84 command (str): Command to execute to get output. | 86 command (str): Command to execute to get output. |
| 85 | 87 |
| 86 Return: | 88 Return: |
| 87 Output steam of the command. | 89 Output steam of the command. |
| 88 """ | 90 """ |
| 89 p = subprocess.Popen( | 91 p = subprocess.Popen( |
| 90 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | 92 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |
| 91 stdoutdata, stderrdata = p.communicate() | 93 stdoutdata, stderrdata = p.communicate() |
| 92 | 94 |
| 93 if p.returncode != 0: | 95 if p.returncode != 0: |
| 94 logging.error('Error running command %s: %s', command, stderrdata) | 96 logging.error('Error running command %s: %s', command, stderrdata) |
| 95 return None | 97 return None |
| 96 | 98 |
| 97 return stdoutdata | 99 return stdoutdata |
| OLD | NEW |