thirdparty/rietveld/upload.py
changeset 687 4755caf1d7a6
parent 478 613951c35706
equal deleted inserted replaced
686:df109be0567c 687:4755caf1d7a6
   149       HTTPError: If there was some other form of HTTP error.
   149       HTTPError: If there was some other form of HTTP error.
   150 
   150 
   151     Returns:
   151     Returns:
   152       The authentication token returned by ClientLogin.
   152       The authentication token returned by ClientLogin.
   153     """
   153     """
   154     # account_type = "GOOGLE"
       
   155     account_type = "HOSTED_OR_GOOGLE"
   154     account_type = "HOSTED_OR_GOOGLE"
   156     if self.host.endswith(".google.com"):
   155     if self.host.endswith(".google.com"):
   157       # Needed for use inside Google.
   156       # Needed for use inside Google.
   158       account_type = "HOSTED"
   157       account_type = "HOSTED"
   159     req = self._CreateRequest(
   158     req = self._CreateRequest(
   508 # Use a shell for subcommands on Windows to get a PATH search.
   507 # Use a shell for subcommands on Windows to get a PATH search.
   509 use_shell = sys.platform.startswith("win")
   508 use_shell = sys.platform.startswith("win")
   510 
   509 
   511 def RunShellWithReturnCode(command, print_output=False,
   510 def RunShellWithReturnCode(command, print_output=False,
   512                            universal_newlines=True):
   511                            universal_newlines=True):
   513   """Executes a command and returns the output and the return code.
   512   """Executes a command and returns the output from stdout and the return code.
   514 
   513 
   515   Args:
   514   Args:
   516     command: Command to execute.
   515     command: Command to execute.
   517     print_output: If True, the output is printed to stdout.
   516     print_output: If True, the output is printed to stdout.
       
   517                   If False, both stdout and stderr are ignored.
   518     universal_newlines: Use universal_newlines flag (default: True).
   518     universal_newlines: Use universal_newlines flag (default: True).
   519 
   519 
   520   Returns:
   520   Returns:
   521     Tuple (output, return code)
   521     Tuple (output, return code)
   522   """
   522   """
   523   logging.info("Running %s", command)
   523   logging.info("Running %s", command)
   524   p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=use_shell,
   524   p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
   525                        universal_newlines=universal_newlines)
   525                        shell=use_shell, universal_newlines=universal_newlines)
   526   if print_output:
   526   if print_output:
   527     output_array = []
   527     output_array = []
   528     while True:
   528     while True:
   529       line = p.stdout.readline()
   529       line = p.stdout.readline()
   530       if not line:
   530       if not line:
   533       output_array.append(line)
   533       output_array.append(line)
   534     output = "".join(output_array)
   534     output = "".join(output_array)
   535   else:
   535   else:
   536     output = p.stdout.read()
   536     output = p.stdout.read()
   537   p.wait()
   537   p.wait()
       
   538   errout = p.stderr.read()
       
   539   if print_output and errout:
       
   540     print >>sys.stderr, errout
   538   p.stdout.close()
   541   p.stdout.close()
       
   542   p.stderr.close()
   539   return output, p.returncode
   543   return output, p.returncode
   540 
   544 
   541 
   545 
   542 def RunShell(command, silent_ok=False, universal_newlines=True,
   546 def RunShell(command, silent_ok=False, universal_newlines=True,
   543              print_output=False):
   547              print_output=False):