~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sys
from subprocess import Popen, PIPE
def patch(branch, filename, strip):
    """Apply a patch to a branch, using patch(1)."""
    if filename is None:
        my_file = sys.stdin
    else:
        my_file = file(filename, 'rb')
    cmd = ['patch', '--directory', branch.base, '--strip', str(strip)]
    child_proc = Popen(cmd, stdin=PIPE)
    for line in my_file:
        child_proc.stdin.write(line)
    child_proc.stdin.close()
    return child_proc.wait()