~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2005-11-11 17:43:12 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051111174312-1c627d82a07bf8fd
Added patch for tab-in-patch-filename support

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import errno
25
25
from subprocess import Popen, PIPE
26
26
import codecs
27
 
import re
28
27
 
29
28
def temp_branch():
30
29
    dirname = tempfile.mkdtemp("temp-branch")
44
43
    >>> file(fooname, "wb").write("bar")
45
44
    >>> is_clean(br)
46
45
    (True, [u'foo'])
47
 
    >>> bzrlib.add.smart_add_tree(br.working_tree(), [br.base])
48
 
    ([u'foo'], {})
 
46
    >>> bzrlib.add.smart_add_branch(br, [br.base])
 
47
    1
49
48
    >>> is_clean(br)
50
49
    (False, [])
51
 
    >>> br.working_tree().commit("added file")
 
50
    >>> br.commit("added file")
52
51
    >>> is_clean(br)
53
52
    (True, [])
54
53
    >>> rm_branch(br)
63
62
    delta = compare_trees(old_tree, new_tree, want_unchanged=False)
64
63
    return not delta.has_changed(), non_source
65
64
 
 
65
def set_pull_data(br, location, rev_id):
 
66
    pull_file = file (br.controlfilename("x-pull-data"), "wb")
 
67
    pull_file.write("%s\n%s\n" % (location, rev_id))
 
68
 
 
69
def get_pull_data(br):
 
70
    """
 
71
    >>> br = temp_branch()
 
72
    >>> get_pull_data(br)
 
73
    (None, None)
 
74
    >>> set_pull_data(br, 'http://somewhere', '888-777')
 
75
    >>> get_pull_data(br)
 
76
    ('http://somewhere', '888-777')
 
77
    >>> rm_branch(br)
 
78
    """
 
79
    filename = br.controlfilename("x-pull-data")
 
80
    if not os.path.exists(filename):
 
81
        return (None, None)
 
82
    pull_file = file (filename, "rb")
 
83
    location, rev_id = [f.rstrip('\n') for f in pull_file]
 
84
    return location, rev_id
 
85
 
66
86
def set_push_data(br, location):
67
 
    push_file = file (br.control_files.controlfilename("x-push-data"), "wb")
 
87
    push_file = file (br.controlfilename("x-push-data"), "wb")
68
88
    push_file.write("%s\n" % location)
69
89
 
70
90
def get_push_data(br):
77
97
    'http://somewhere'
78
98
    >>> rm_branch(br)
79
99
    """
80
 
    filename = br.control_files.controlfilename("x-push-data")
 
100
    filename = br.controlfilename("x-push-data")
81
101
    if not os.path.exists(filename):
82
102
        return None
83
103
    push_file = file (filename, "rb")
227
247
    except RsyncNoFile:
228
248
        return True
229
249
 
230
 
def push(cur_branch, location=None, overwrite=False, working_tree=True):
 
250
def push(cur_branch, location=None, overwrite=False):
231
251
    push_location = get_push_data(cur_branch)
232
252
    if location is not None:
233
253
        if not location.endswith('/'):
248
268
        print """Error: This tree has uncommitted changes or unknown (?) files.
249
269
Use "bzr status" to list them."""
250
270
        sys.exit(1)
251
 
    if working_tree:
252
 
        final_exclusions = non_source[:]
253
 
    else:
254
 
        wt = cur_branch.working_tree()
255
 
        final_exclusions = []
256
 
        for path, status, kind, file_id, entry in wt.list_files():
257
 
            final_exclusions.append(path)
258
 
 
259
 
    final_exclusions.extend(exclusions)
 
271
    non_source.extend(exclusions)
260
272
    if not overwrite:
261
273
        try:
262
274
            if not history_subset(push_location, cur_branch):
273
285
                " specified location.  Please ensure that"
274
286
                ' "%s" is of the form "machine:/path".' % push_location)
275
287
    print "Pushing to %s" % push_location
276
 
    rsync(cur_branch.base+'/', push_location, ssh=True, 
277
 
          excludes=final_exclusions)
 
288
    rsync(cur_branch.base+'/', push_location, ssh=True, excludes=non_source)
278
289
 
279
290
    set_push_data(cur_branch, push_location)
280
291
 
281
 
def short_committer(committer):
282
 
    new_committer = re.sub('<.*>', '', committer).strip(' ')
283
 
    if len(new_committer) < 2:
284
 
        return committer
285
 
    return new_committer
286
 
 
287
 
 
288
292
def run_tests():
289
293
    import doctest
290
294
    result = doctest.testmod()