Example #1
0
 def _execute(self, args, log=True):
     """Executes the given command inside the environment and returns the output."""
     if not self._ready:
         self.open_or_create()
     output = ''
     error = ''
     try:
         if args[0] == 'pip':
             args += ['--disable-pip-version-check']
         proc = subprocess.Popen(args, cwd=self.path, env=self.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         output, error = proc.communicate()
         returncode = proc.returncode
         if returncode:
             raise subprocess.CalledProcessError(returncode, proc, (output, error))
         return to_text(output)
     except OSError as e:
         # raise a more meaningful error with the program name
         prog = args[0]
         if prog[0] != os.sep:
             prog = os.path.join(self.path, prog)
         raise OSError('%s: %s' % (prog, six.u(e)))
     except subprocess.CalledProcessError as e:
         output, error = e.output
         e.output = output
         raise e
     finally:
         if log:
             try:
                 self._write_to_log(to_text(output))
                 self._write_to_error(to_text(error))
             except NameError:
                 pass  # We tried
Example #2
0
 def _execute(self, args, log=True):
     """Executes the given command inside the environment and returns the output."""
     if not self._ready:
         self.open_or_create()
     output = ''
     error = ''
     try:
         proc = subprocess.Popen(args, cwd=self.path, env=self.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         output, error = proc.communicate()
         returncode = proc.returncode
         if returncode:
             raise subprocess.CalledProcessError(returncode, proc, (output, error))
         return to_text(output)
     except OSError as e:
         # raise a more meaningful error with the program name
         prog = args[0]
         if prog[0] != os.sep:
             prog = os.path.join(self.path, prog)
         raise OSError('%s: %s' % (prog, six.u(str(e))))
     except subprocess.CalledProcessError as e:
         output, error = e.output
         e.output = output
         raise e
     finally:
         if log:
             try:
                 self._write_to_log(to_text(output))
                 self._write_to_error(to_text(error))
             except NameError:
                 pass  # We tried
Example #3
0
 def _write_to_error(self, s, truncate=False):
     """Writes the given output to the error file, appending unless `truncate` is True."""
     # if truncate is True, set write mode to truncate
     with open(self._errorfile, 'w' if truncate else 'a') as fp:
         fp.writelines((to_text(s)), )
Example #4
0
 def _write_to_error(self, s, truncate=False):
     """Writes the given output to the error file, appending unless `truncate` is True."""
     # if truncate is True, set write mode to truncate
     with open(self._errorfile, 'w' if truncate else 'a') as fp:
         fp.writelines((to_text(s)), )