Commit 73065b20 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

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: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent 004da782
......@@ -185,7 +185,7 @@ class MetricsCollector(object):
# so that we are able to return immediately, leaving the upload running in
# the background.
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):
# If we're already collecting metrics, just execute the function.
......
......@@ -168,7 +168,7 @@ def get_git_version():
['git', '--version'],
stdout=subprocess2.PIPE, stderr=subprocess2.PIPE)
stdout, _ = p.communicate()
match = GIT_VERSION_RE.match(stdout)
match = GIT_VERSION_RE.match(stdout.decode('utf-8'))
if not match:
return None
return '%s.%s.%s' % match.groups()
......
......@@ -705,7 +705,7 @@ class MetricsUtilsTest(unittest.TestCase):
def test_get_git_version(self, mockPopen):
"""Tests that we can get the git version."""
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]
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):
"""Tests that we can get the git version."""
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]
self.assertIsNone(metrics_utils.get_git_version())
......
......@@ -4,18 +4,19 @@
# found in the LICENSE file.
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
def main():
metrics = raw_input()
metrics = input()
try:
urllib2.urlopen(metrics_utils.APP_URL + '/upload', metrics)
except urllib2.HTTPError:
pass
except urllib2.URLError:
urllib.request.urlopen(
metrics_utils.APP_URL + '/upload', metrics.encode('utf-8'))
except (urllib.error.HTTPError, urllib.error.URLError):
pass
return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment