~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2006-11-23 18:06:43 UTC
  • Revision ID: abentley@panoramicfeedback.com-20061123180643-6ry3xqozdbn4cfhy
Update docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron.bentley@utoronto.ca>
2
 
# Copyright (C) 2007 John Arbash Meinel
 
1
# Copyright (C) 2005 Aaron Bentley
 
2
# <aaron.bentley@utoronto.ca>
3
3
#
4
4
#    This program is free software; you can redistribute it and/or modify
5
5
#    it under the terms of the GNU General Public License as published by
26
26
import bzrlib
27
27
import bzrlib.errors
28
28
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
29
 
                           UnsupportedFormatError, TransportError,
 
29
                           UnsupportedFormatError, TransportError, 
30
30
                           NoWorkingTree, PermissionDenied)
31
31
from bzrlib.bzrdir import BzrDir, BzrDirFormat
32
32
 
40
40
def is_clean(cur_tree):
41
41
    """
42
42
    Return true if no files are modifed or unknown
 
43
    >>> import bzrlib.add
 
44
    >>> tree = temp_tree()
 
45
    >>> is_clean(tree)
 
46
    (True, [])
 
47
    >>> fooname = os.path.join(tree.basedir, "foo")
 
48
    >>> file(fooname, "wb").write("bar")
 
49
    >>> is_clean(tree)
 
50
    (True, [u'foo'])
 
51
    >>> bzrlib.add.smart_add_tree(tree, [tree.basedir])
 
52
    ([u'foo'], {})
 
53
    >>> is_clean(tree)
 
54
    (False, [])
 
55
    >>> tree.commit("added file", rev_id='commit-id')
 
56
    'commit-id'
 
57
    >>> is_clean(tree)
 
58
    (True, [])
 
59
    >>> rm_tree(tree)
43
60
    """
44
61
    old_tree = cur_tree.basis_tree()
45
62
    new_tree = cur_tree
46
63
    non_source = []
47
 
    new_tree.lock_read()
48
 
    try:
49
 
        for path, file_class, kind, file_id, entry in new_tree.list_files():
50
 
            if file_class in ('?', 'I'):
51
 
                non_source.append(path)
52
 
        delta = new_tree.changes_from(old_tree, want_unchanged=False)
53
 
    finally:
54
 
        new_tree.unlock()
 
64
    for path, file_class, kind, file_id, entry in new_tree.list_files():
 
65
        if file_class in ('?', 'I'):
 
66
            non_source.append(path)
 
67
    delta = new_tree.changes_from(old_tree, want_unchanged=False)
55
68
    return not delta.has_changed(), non_source
56
69
 
57
70
def set_push_data(tree, location):
99
112
    def __init__(self, rsync_name):
100
113
        Exception.__init__(self, "%s not found." % rsync_name)
101
114
 
102
 
def rsync(source, target, ssh=False, excludes=(), silent=False,
 
115
def rsync(source, target, ssh=False, excludes=(), silent=False, 
103
116
          rsync_name="rsync"):
104
117
    """
105
118
    >>> new_dir = tempfile.mkdtemp()
134
147
    except OSError, e:
135
148
        if e.errno == errno.ENOENT:
136
149
            raise NoRsync(rsync_name)
137
 
 
 
150
            
138
151
    proc.stdin.write('\n'.join(excludes)+'\n')
139
152
    proc.stdin.close()
140
153
    if silent:
176
189
        raise RsyncUnknownStatus(proc.returncode)
177
190
    return [l.split(' ')[-1].rstrip('\n') for l in result.splitlines(True)]
178
191
 
179
 
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
 
192
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent', 
180
193
              '.bzr/branch/parent', '.bzr/x-pull-data', '.bzr/x-pull',
181
194
              '.bzr/pull', '.bzr/stat-cache', '.bzr/x-rsync-data',
182
195
              '.bzr/basis-inventory', '.bzr/inventory.backup.weave')
216
229
        return False
217
230
    for local, remote in zip(remote_history, local_history):
218
231
        if local != remote:
219
 
            return False
 
232
            return False 
220
233
    return True
221
234
 
222
235
def empty_or_absent(location):
232
245
        if not location.endswith('/'):
233
246
            location += '/'
234
247
        push_location = location
235
 
 
 
248
    
236
249
    if push_location is None:
237
250
        raise BzrCommandError("No rspush location known or specified.")
238
251
 
239
 
    if (push_location.find('::') != -1):
240
 
        usessh=False
241
 
    else:
242
 
        usessh=True
243
 
 
244
252
    if (push_location.find('://') != -1 or
245
253
        push_location.find(':') == -1):
246
254
        raise BzrCommandError("Invalid rsync path %r." % push_location)
275
283
                " specified location.  Please ensure that"
276
284
                ' "%s" is of the form "machine:/path".' % push_location)
277
285
    print "Pushing to %s" % push_location
278
 
    rsync(tree.basedir+'/', push_location, ssh=usessh,
 
286
    rsync(tree.basedir+'/', push_location, ssh=True, 
279
287
          excludes=final_exclusions)
280
288
 
281
289
    set_push_data(tree, push_location)
354
362
    except (NoSuchFile, PermissionDenied, TransportError):
355
363
        pass
356
364
 
357
 
 
 
365
    
358
366
def bzrdir_from_transport(t):
359
367
    """Open a bzrdir from a transport (not a location)"""
360
368
    format = BzrDirFormat.find_format(t)