mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
depot_tools: Make some changes to make metrics collection compatible with Python 3.
Bug: 984182 Change-Id: I55e9e83d01d5a86464cc234c083e4212f0ba4a1e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1713217 Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org> Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org> Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
This commit is contained in:
@@ -185,7 +185,7 @@ class MetricsCollector(object):
|
|||||||
# so that we are able to return immediately, leaving the upload running in
|
# so that we are able to return immediately, leaving the upload running in
|
||||||
# the background.
|
# the background.
|
||||||
p = subprocess.Popen([sys.executable, UPLOAD_SCRIPT], stdin=subprocess.PIPE)
|
p = subprocess.Popen([sys.executable, UPLOAD_SCRIPT], stdin=subprocess.PIPE)
|
||||||
p.stdin.write(json.dumps(self._reported_metrics))
|
p.stdin.write(json.dumps(self._reported_metrics).encode('utf-8'))
|
||||||
|
|
||||||
def _collect_metrics(self, func, command_name, *args, **kwargs):
|
def _collect_metrics(self, func, command_name, *args, **kwargs):
|
||||||
# If we're already collecting metrics, just execute the function.
|
# If we're already collecting metrics, just execute the function.
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ def get_git_version():
|
|||||||
['git', '--version'],
|
['git', '--version'],
|
||||||
stdout=subprocess2.PIPE, stderr=subprocess2.PIPE)
|
stdout=subprocess2.PIPE, stderr=subprocess2.PIPE)
|
||||||
stdout, _ = p.communicate()
|
stdout, _ = p.communicate()
|
||||||
match = GIT_VERSION_RE.match(stdout)
|
match = GIT_VERSION_RE.match(stdout.decode('utf-8'))
|
||||||
if not match:
|
if not match:
|
||||||
return None
|
return None
|
||||||
return '%s.%s.%s' % match.groups()
|
return '%s.%s.%s' % match.groups()
|
||||||
|
|||||||
@@ -705,7 +705,7 @@ class MetricsUtilsTest(unittest.TestCase):
|
|||||||
def test_get_git_version(self, mockPopen):
|
def test_get_git_version(self, mockPopen):
|
||||||
"""Tests that we can get the git version."""
|
"""Tests that we can get the git version."""
|
||||||
mockProcess = mock.Mock()
|
mockProcess = mock.Mock()
|
||||||
mockProcess.communicate.side_effect = [('git version 2.18.0.123.foo', '')]
|
mockProcess.communicate.side_effect = [(b'git version 2.18.0.123.foo', '')]
|
||||||
mockPopen.side_effect = [mockProcess]
|
mockPopen.side_effect = [mockProcess]
|
||||||
|
|
||||||
self.assertEqual('2.18.0', metrics_utils.get_git_version())
|
self.assertEqual('2.18.0', metrics_utils.get_git_version())
|
||||||
@@ -714,7 +714,7 @@ class MetricsUtilsTest(unittest.TestCase):
|
|||||||
def test_get_git_version_unrecognized(self, mockPopen):
|
def test_get_git_version_unrecognized(self, mockPopen):
|
||||||
"""Tests that we can get the git version."""
|
"""Tests that we can get the git version."""
|
||||||
mockProcess = mock.Mock()
|
mockProcess = mock.Mock()
|
||||||
mockProcess.communicate.side_effect = [('Blah blah blah', 'blah blah')]
|
mockProcess.communicate.side_effect = [(b'Blah blah blah', 'blah blah')]
|
||||||
mockPopen.side_effect = [mockProcess]
|
mockPopen.side_effect = [mockProcess]
|
||||||
|
|
||||||
self.assertIsNone(metrics_utils.get_git_version())
|
self.assertIsNone(metrics_utils.get_git_version())
|
||||||
|
|||||||
@@ -4,18 +4,19 @@
|
|||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
|
||||||
|
from third_party.six.moves import urllib
|
||||||
|
from third_party.six.moves import input # pylint: disable=redefined-builtin
|
||||||
|
|
||||||
import metrics_utils
|
import metrics_utils
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
metrics = raw_input()
|
metrics = input()
|
||||||
try:
|
try:
|
||||||
urllib2.urlopen(metrics_utils.APP_URL + '/upload', metrics)
|
urllib.request.urlopen(
|
||||||
except urllib2.HTTPError:
|
metrics_utils.APP_URL + '/upload', metrics.encode('utf-8'))
|
||||||
pass
|
except (urllib.error.HTTPError, urllib.error.URLError):
|
||||||
except urllib2.URLError:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user