tools/git-sync-deps works with either python

Bug: skia:9079
Change-Id: Id172efad6bbfaeb1d1f6bc00bcda622588f0a924
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263355
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
diff --git a/bin/fetch-gn b/bin/fetch-gn
index 5d03fd3..e7cc923 100755
--- a/bin/fetch-gn
+++ b/bin/fetch-gn
@@ -10,7 +10,11 @@
 import shutil
 import stat
 import sys
-import urllib2
+
+if sys.version_info[0] < 3:
+  from urllib2 import urlopen
+else:
+  from urllib.request import urlopen
 
 os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
 
@@ -29,7 +33,7 @@
 
 if sha1_of_file(dst) != sha1:
   with open(dst, 'wb') as f:
-    f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
+    f.write(urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
 
   os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
                 stat.S_IRGRP                | stat.S_IXGRP |
diff --git a/tools/git-sync-deps b/tools/git-sync-deps
index ff121b1..ca1ba47 100755
--- a/tools/git-sync-deps
+++ b/tools/git-sync-deps
@@ -94,7 +94,7 @@
   try:
     toplevel = subprocess.check_output(
       [git, 'rev-parse', '--show-toplevel'], cwd=directory).strip()
-    return os.path.realpath(directory) == os.path.realpath(toplevel)
+    return os.path.realpath(directory) == os.path.realpath(toplevel.decode())
   except subprocess.CalledProcessError:
     return False
 
@@ -172,7 +172,8 @@
 
 def parse_file_to_dict(path):
   dictionary = {}
-  execfile(path, dictionary)
+  with open(path) as f:
+    exec(f.read(), dictionary)
   return dictionary
 
 
@@ -214,9 +215,9 @@
         raise Exception('%r is parent of %r' % (other_dir, directory))
   list_of_arg_lists = []
   for directory in sorted(dependencies):
-    if not isinstance(dependencies[directory], basestring):
+    if not isinstance(dependencies[directory], str):
       if verbose:
-        print 'Skipping "%s".' % directory
+        sys.stdout.write( 'Skipping "%s".\n' % directory)
       continue
     if '@' in dependencies[directory]:
       repo, commithash = dependencies[directory].split('@', 1)