~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2007-06-10 17:55:08 UTC
  • mfrom: (531.2.2 bzrtools)
  • Revision ID: aaron.bentley@utoronto.ca-20070610175508-gex1oxvmfv0qoagi
Merge whitespace cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Aaron Bentley
2
 
# <aaron.bentley@utoronto.ca>
 
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron.bentley@utoronto.ca>
 
2
# Copyright (C) 2007 John Arbash Meinel
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)
60
43
    """
61
44
    old_tree = cur_tree.basis_tree()
62
45
    new_tree = cur_tree
63
46
    non_source = []
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)
 
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()
68
55
    return not delta.has_changed(), non_source
69
56
 
70
57
def set_push_data(tree, location):
112
99
    def __init__(self, rsync_name):
113
100
        Exception.__init__(self, "%s not found." % rsync_name)
114
101
 
115
 
def rsync(source, target, ssh=False, excludes=(), silent=False, 
 
102
def rsync(source, target, ssh=False, excludes=(), silent=False,
116
103
          rsync_name="rsync"):
117
104
    """
118
105
    >>> new_dir = tempfile.mkdtemp()
147
134
    except OSError, e:
148
135
        if e.errno == errno.ENOENT:
149
136
            raise NoRsync(rsync_name)
150
 
            
 
137
 
151
138
    proc.stdin.write('\n'.join(excludes)+'\n')
152
139
    proc.stdin.close()
153
140
    if silent:
189
176
        raise RsyncUnknownStatus(proc.returncode)
190
177
    return [l.split(' ')[-1].rstrip('\n') for l in result.splitlines(True)]
191
178
 
192
 
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent', 
 
179
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
193
180
              '.bzr/branch/parent', '.bzr/x-pull-data', '.bzr/x-pull',
194
181
              '.bzr/pull', '.bzr/stat-cache', '.bzr/x-rsync-data',
195
182
              '.bzr/basis-inventory', '.bzr/inventory.backup.weave')
229
216
        return False
230
217
    for local, remote in zip(remote_history, local_history):
231
218
        if local != remote:
232
 
            return False 
 
219
            return False
233
220
    return True
234
221
 
235
222
def empty_or_absent(location):
245
232
        if not location.endswith('/'):
246
233
            location += '/'
247
234
        push_location = location
248
 
    
 
235
 
249
236
    if push_location is None:
250
237
        raise BzrCommandError("No rspush location known or specified.")
251
238
 
 
239
    if (push_location.find('::') != -1):
 
240
        usessh=False
 
241
    else:
 
242
        usessh=True
 
243
 
252
244
    if (push_location.find('://') != -1 or
253
245
        push_location.find(':') == -1):
254
246
        raise BzrCommandError("Invalid rsync path %r." % push_location)
283
275
                " specified location.  Please ensure that"
284
276
                ' "%s" is of the form "machine:/path".' % push_location)
285
277
    print "Pushing to %s" % push_location
286
 
    rsync(tree.basedir+'/', push_location, ssh=True, 
 
278
    rsync(tree.basedir+'/', push_location, ssh=usessh,
287
279
          excludes=final_exclusions)
288
280
 
289
281
    set_push_data(tree, push_location)
362
354
    except (NoSuchFile, PermissionDenied, TransportError):
363
355
        pass
364
356
 
365
 
    
 
357
 
366
358
def bzrdir_from_transport(t):
367
359
    """Open a bzrdir from a transport (not a location)"""
368
360
    format = BzrDirFormat.find_format(t)