Revert "Remove code duplication and improve style."

This reverts commit 850ee065dd840ef7112671c11fc54d9e6b52aa2f.

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@56894 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index dd5ae18..1efa036 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -23,6 +23,7 @@
 import sys
 import threading
 import time
+import threading
 import xml.dom.minidom
 import xml.parsers.expat
 
@@ -38,20 +39,8 @@
     self.stderr = stderr
 
 
-def Popen(*args, **kwargs):
-  # *Sigh*:  Windows needs shell=True, or else it won't search %PATH% for the
-  # executable, but shell=True makes subprocess on Linux fail when it's called
-  # with a list because it only tries to execute the first item in the list.
-  if not 'env' in kwargs:
-    # It's easier to parse the stdout if it is always in English.
-    kwargs['env'] = os.environ.copy()
-    kwargs['env']['LANGUAGE'] = 'en'
-  return subprocess.Popen(*args, shell=(sys.platform=='win32'), **kwargs)
-
-
 def CheckCall(command, cwd=None, print_error=True):
-  """Similar subprocess.check_call() but redirects stdout and
-  returns (stdout, stderr).
+  """Like subprocess.check_call() but returns stdout.
 
   Works on python 2.4
   """
@@ -60,7 +49,13 @@
     stderr = None
     if not print_error:
       stderr = subprocess.PIPE
-    process = Popen(command, cwd=cwd, stdout=subprocess.PIPE, stderr=stderr)
+    env = os.environ.copy()
+    env['LANGUAGE'] = 'en'
+    process = subprocess.Popen(command, cwd=cwd,
+                               shell=sys.platform.startswith('win'),
+                               stdout=subprocess.PIPE,
+                               stderr=stderr,
+                               env=env)
     std_out, std_err = process.communicate()
   except OSError, e:
     raise CheckCallError(command, cwd, e.errno, None)
@@ -280,9 +275,15 @@
   if print_messages:
     print('\n________ running \'%s\' in \'%s\''
           % (' '.join(command), in_directory))
+  env = os.environ.copy()
+  env['LANGUAGE'] = 'en'
 
-  kid = Popen(command, bufsize=0, cwd=in_directory,
-              stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+  # *Sigh*:  Windows needs shell=True, or else it won't search %PATH% for the
+  # executable, but shell=True makes subprocess on Linux fail when it's called
+  # with a list because it only tries to execute the first item in the list.
+  kid = subprocess.Popen(command, bufsize=0, cwd=in_directory,
+      shell=(sys.platform == 'win32'), stdout=subprocess.PIPE,
+      stderr=subprocess.STDOUT, env=env)
 
   # Do a flush of sys.stdout before we begin reading from the subprocess's
   # stdout.
@@ -322,7 +323,7 @@
     msg = 'failed to run command: %s' % ' '.join(command)
 
     if fail_status != None:
-      print >> sys.stderr, msg
+      print >>sys.stderr, msg
       sys.exit(fail_status)
 
     raise Error(msg)
@@ -332,10 +333,10 @@
   """Tries to find the gclient root."""
   path = os.path.realpath(from_dir)
   while not os.path.exists(os.path.join(path, filename)):
-    split_path = os.path.split(path)
-    if not split_path[1]:
+    next = os.path.split(path)
+    if not next[1]:
       return None
-    path = split_path[0]
+    path = next[0]
   logging.info('Found gclient root at ' + path)
   return path