예제 #1
0
 def run(self, command):
     command = "%s %s" % (self.cmd_command, command)
     with chdir(self.folder) if self.folder else no_op():
         with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op():
             with pyinstaller_bundle_env_cleaned():
                 if not self._runner:
                     return check_output_runner(command).strip()
                 else:
                     return self._runner(command)
예제 #2
0
파일: runner.py 프로젝트: manuelbcd/conan
    def __call__(self,
                 command,
                 output=True,
                 log_filepath=None,
                 cwd=None,
                 subprocess=False):
        """
        @param command: Command to execute
        @param output: Instead of print to sys.stdout print to that stream. Could be None
        @param log_filepath: If specified, also log to a file
        @param cwd: Move to directory to execute
        """
        if output and isinstance(output, io.StringIO) and six.PY2:
            # in py2 writing to a StringIO requires unicode, otherwise it fails
            print("*** WARN: Invalid output parameter of type io.StringIO(), "
                  "use six.StringIO() instead ***")

        user_output = output if output and hasattr(output, "write") else None
        stream_output = user_output or self._output or sys.stdout
        if hasattr(stream_output, "flush"):
            # We do not want output from different streams to get mixed (sys.stdout, os.system)
            stream_output = _UnbufferedWrite(stream_output)

        if not self._generate_run_log_file:
            log_filepath = None

        # Log the command call in output and logger
        call_message = "\n----Running------\n> %s\n-----------------\n" % (
            command, )
        if self._print_commands_to_output and stream_output and self._log_run_to_output:
            stream_output.write(call_message)

        with pyinstaller_bundle_env_cleaned():
            # No output has to be redirected to logs or buffer or omitted
            if (output is True and not self._output and not log_filepath
                    and self._log_run_to_output and not subprocess):
                return self._simple_os_call(command, cwd)
            elif log_filepath:
                if stream_output:
                    stream_output.write(
                        "Logging command output to file '%s'\n" %
                        (log_filepath, ))
                with open(log_filepath, "a+") as log_handler:
                    if self._print_commands_to_output:
                        log_handler.write(call_message)
                    return self._pipe_os_call(command, stream_output,
                                              log_handler, cwd, user_output)
            else:
                return self._pipe_os_call(command, stream_output, None, cwd,
                                          user_output)