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/gclient_paths.py b/gclient_paths.py
index b860855..36e96f7 100644
--- a/gclient_paths.py
+++ b/gclient_paths.py
@@ -7,6 +7,9 @@
 # code, and even more importantly don't add more toplevel import statements,
 # particularly for modules that are not builtin (see sys.builtin_modules_names,
 # os isn't built in, but it's essential to this file).
+
+from __future__ import print_function
+
 import os
 import sys
 
@@ -30,16 +33,17 @@
       # might have failed. In that case, we cannot verify that the .gclient
       # is the one we want to use. In order to not to cause too much trouble,
       # just issue a warning and return the path anyway.
-      print >> sys.stderr, ("%s missing, %s file in parent directory %s might "
-          "not be the file you want to use." %
-          (entries_filename, filename, path))
+      print(
+          "%s missing, %s file in parent directory %s might not be the file "
+          "you want to use." % (entries_filename, filename, path),
+          file=sys.stderr)
       return path
     scope = {}
     try:
       import io
       with io.open(entries_filename, encoding='utf-8') as f:
         exec(f.read(), scope)
-    except SyntaxError, e:
+    except SyntaxError as e:
       SyntaxErrorToError(filename, e)
     all_directories = scope['entries'].keys()
     path_to_check = real_from_dir[len(path)+1:]
@@ -113,7 +117,7 @@
   elif sys.platform == 'darwin':
     subdir = 'mac'
   elif sys.platform.startswith('linux'):
-      subdir = 'linux64'
+    subdir = 'linux64'
   else:
     raise Error('Unknown platform: ' + sys.platform)
   return os.path.join(buildtools_path, subdir)
@@ -130,7 +134,8 @@
   """Returns the name of the primary solution in the .gclient file specified."""
   gclient_config_file = os.path.join(gclient_root_dir_path, '.gclient')
   env = {}
-  execfile(gclient_config_file, env)
+  exec(compile(open(gclient_config_file).read(), gclient_config_file, 'exec'),
+       env)
   solutions = env.get('solutions', [])
   if solutions:
     return solutions[0].get('name')