~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-18 20:37:53 UTC
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: bialix@ukr.net-20060718203753-fa30c2f3cc59316b
don't use curses on win32

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