Example #1
0
 def _wrap(fname, log_entry):
     with tempfile.TemporaryFile() as fil:
         fil.write('\0'.join(
             [util.utf8(x) for x in [fname] + list(log_entry)]))
         fil.flush()
         fil.seek(0)
         with util.wrap_popen(list_or_str, stdin_fil=fil) as out_fil:
             return out_fil.read()
Example #2
0
 def _wrap(fname, log_entry):
     with tempfile.TemporaryFile() as fil:
         fil.write('\0'.join([util.utf8(x)
                              for x
                              in [fname] + list(log_entry)]))
         fil.flush()
         fil.seek(0)
         with util.wrap_popen(list_or_str, stdin_fil=fil) as out_fil:
             return out_fil.read()
Example #3
0
def git_cmd(cmd, cwd, git_exe=None):
    """
    Run a git cmd and yield an open temporary file to the output.

    After the yield returns, the temporary file is removed.

    The file is returned, rather than a string containing the output,
    because the output of some of the commands we use is large.

    If the git cmd doesn't return 0, raise a WrappedPopenException.

    - `cmd`: a list of strings, as you would pass to subprocess.Popen.

    - `cwd`: the directory to run the command in (as
      subprocess.Popen's cwd param).

    - `git_exe`: the git exe to use to run the command (will be passed
      through resolve_git_exe, see that for rules).
    """
    git_exe = resolve_git_exe(git_exe)
    final_cmd = git_exe.split() + cmd
    with util.wrap_popen(final_cmd, cwd=cwd) as stdout_fil:
        yield stdout_fil