Bug 1595982 - make mozharness::base::transfer.py python3 compatible r=aki
authorEdwin Takahashi <egao@mozilla.com>
Mon, 18 Nov 2019 18:17:55 +0000
changeset 502456 a52abf84721ad2f0ff2f56b8f2667ab46cc716b3
parent 502455 9d2c4851e407f7f49d01549f295f44094ca0a525
child 502457 3ec96c0dd69655f71c67e434e589fe745dc05200
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaki
bugs1595982
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1595982 - make mozharness::base::transfer.py python3 compatible r=aki Changes: Run `isort` to fix the import ordering. Change import of `urllib2` module to import just `urlopen` which eliminates the need for an `if/else` or `try/except ` block in the main code section. Depends on D52791 Differential Revision: https://phabricator.services.mozilla.com/D53097
testing/mozharness/mozharness/base/transfer.py
--- a/testing/mozharness/mozharness/base/transfer.py
+++ b/testing/mozharness/mozharness/base/transfer.py
@@ -4,39 +4,44 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 # ***** END LICENSE BLOCK *****
 """Generic ways to upload + download files.
 """
 
 import os
 import pprint
-import urllib2
+try:
+    from urllib2 import urlopen
+except ImportError:
+    from urllib.request import urlopen
+
+from mozharness.base.errors import SSHErrorList
+from mozharness.base.log import DEBUG, ERROR
+
 try:
     import simplejson as json
     assert json
 except ImportError:
     import json
 
-from mozharness.base.errors import SSHErrorList
-from mozharness.base.log import DEBUG, ERROR
-
 
 # TransferMixin {{{1
 class TransferMixin(object):
     """
     Generic transfer methods.
 
     Dependent on BaseScript.
     """
+
     def load_json_from_url(self, url, timeout=30, log_level=DEBUG):
         self.log("Attempting to download %s; timeout=%i" % (url, timeout),
                  level=log_level)
         try:
-            r = urllib2.urlopen(url, timeout=timeout)
+            r = urlopen(url, timeout=timeout)
             j = json.load(r)
             self.log(pprint.pformat(j), level=log_level)
         except BaseException:
             self.exception(message="Unable to download %s!" % url)
             raise
         return j
 
     def scp_upload_directory(self, local_path, ssh_key, ssh_user,
@@ -52,17 +57,18 @@ class TransferMixin(object):
         Returns:
             None: on success
               -1: if local_path is not a directory
               -2: if the remote_directory cannot be created
                   (it only makes sense if create_remote_directory is True)
               -3: scp fails to copy to the remote directory
         """
         dirs = self.query_abs_dirs()
-        self.info("Uploading the contents of %s to %s:%s" % (local_path, remote_host, remote_path))
+        self.info("Uploading the contents of %s to %s:%s" %
+                  (local_path, remote_host, remote_path))
         ssh = self.query_exe("ssh")
         scp = self.query_exe("scp")
         if scp_options is None:
             scp_options = '-rp'
         if not os.path.isdir(local_path):
             self.log("%s isn't a directory!" % local_path,
                      level=ERROR)
             return -1