Improve gclient Python 3 compatibility
This enables gclient sync and gclient runhooks to run, barring hook script failures.
git cl upload also now works.
The scripts still work with Python 2.
There are no intended behaviour changes.
Bug: 942522
Change-Id: I2ac587b5f803ba7f5bb5e412337ce049f4b1a741
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1524583
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
diff --git a/metrics.py b/metrics.py
index bcf0332..00d6e6d 100644
--- a/metrics.py
+++ b/metrics.py
@@ -15,7 +15,11 @@
import threading
import time
import traceback
-import urllib2
+
+try:
+ import urllib2 as urllib
+except ImportError: # For Py3 compatibility
+ import urllib.request as urllib
import detect_host_arch
import gclient_utils
@@ -60,9 +64,9 @@
# check if we can reach the page. An external developer would get access
# denied.
try:
- req = urllib2.urlopen(metrics_utils.APP_URL + '/should-upload')
+ req = urllib.urlopen(metrics_utils.APP_URL + '/should-upload')
self._config['is-googler'] = req.getcode() == 200
- except (urllib2.URLError, urllib2.HTTPError):
+ except (urllib.URLError, urllib.HTTPError):
self._config['is-googler'] = False
# Make sure the config variables we need are present, and initialize them to
@@ -224,7 +228,7 @@
self._upload_metrics_data()
if exception:
- raise exception[0], exception[1], exception[2]
+ gclient_utils.reraise(exception[0], exception[1], exception[2])
return result
def collect_metrics(self, command_name):