~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to patch.py

  • Committer: Aaron Bentley
  • Date: 2005-09-13 22:49:40 UTC
  • mto: (147.1.21)
  • mto: This revision was merged to the branch mainline in revision 154.
  • Revision ID: abentley@panoramicfeedback.com-20050913224940-c6db07f39dd303be
Updated docs, obsoleted old executibles

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Aaron Bentley
2
 
# <aaron.bentley@utoronto.ca>
3
 
#
4
 
#    This program is free software; you can redistribute it and/or modify
5
 
#    it under the terms of the GNU General Public License as published by
6
 
#    the Free Software Foundation; either version 2 of the License, or
7
 
#    (at your option) any later version.
8
 
#
9
 
#    This program is distributed in the hope that it will be useful,
10
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
#    GNU General Public License for more details.
13
 
#
14
 
#    You should have received a copy of the GNU General Public License
15
 
#    along with this program; if not, write to the Free Software
16
 
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
1
import sys
18
2
from subprocess import Popen, PIPE
19
 
from bzrlib.transport import get_transport
20
 
from urlparse import urlsplit, urlunsplit
21
 
def patch(branch, location, strip):
22
 
    """Apply a patch to a branch, using patch(1).  URLs may be used."""
23
 
    my_file = None
24
 
    if location is None:
 
3
def patch(branch, filename, strip):
 
4
    """Apply a patch to a branch, using patch(1)."""
 
5
    if filename is None:
25
6
        my_file = sys.stdin
26
7
    else:
27
 
        for prefix in ('http://', 'sftp://', 'file://'):
28
 
            if not location.startswith(prefix):
29
 
                continue
30
 
            (scheme, loc, path, query, fragment) = urlsplit(location)
31
 
            loc_start = urlunsplit((scheme, loc, '/', '', ''))
32
 
            my_file = get_transport(loc_start).get(path[1:])
33
 
        if my_file is None:
34
 
            my_file = file(location, 'rb')
 
8
        my_file = file(filename, 'rb')
35
9
    cmd = ['patch', '--directory', branch.base, '--strip', str(strip)]
36
10
    child_proc = Popen(cmd, stdin=PIPE)
37
11
    for line in my_file: