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
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
27
from bzrlib import urlutils
27
28
import bzrlib.errors
28
29
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
29
UnsupportedFormatError, TransportError,
30
NoWorkingTree, PermissionDenied)
30
UnsupportedFormatError, TransportError,
31
NoWorkingTree, PermissionDenied, ConnectionError)
31
32
from bzrlib.bzrdir import BzrDir, BzrDirFormat
33
from bzrlib.transport import get_transport
34
36
dirname = tempfile.mkdtemp("temp-branch")
40
42
def is_clean(cur_tree):
42
44
Return true if no files are modifed or unknown
44
>>> tree = temp_tree()
47
>>> fooname = os.path.join(tree.basedir, "foo")
48
>>> file(fooname, "wb").write("bar")
51
>>> bzrlib.add.smart_add_tree(tree, [tree.basedir])
55
>>> tree.commit("added file")
60
from bzrlib.diff import compare_trees
61
46
old_tree = cur_tree.basis_tree()
62
47
new_tree = cur_tree
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 = compare_trees(old_tree, new_tree, want_unchanged=False)
51
for path, file_class, kind, file_id, entry in new_tree.list_files():
52
if file_class in ('?', 'I'):
53
non_source.append(path)
54
delta = new_tree.changes_from(old_tree, want_unchanged=False)
68
57
return not delta.has_changed(), non_source
70
59
def set_push_data(tree, location):
71
push_file = file (tree.branch.control_files.controlfilename("x-push-data"), "wb")
72
push_file.write("%s\n" % location)
60
tree.branch.control_files.put_utf8("x-push-data", "%s\n" % location)
74
62
def get_push_data(tree):
79
67
>>> set_push_data(tree, 'http://somewhere')
80
68
>>> get_push_data(tree)
84
filename = tree.branch.control_files.controlfilename("x-push-data")
85
if not os.path.exists(filename):
73
location = tree.branch.control_files.get_utf8('x-push-data').read()
87
push_file = file (filename, "rb")
88
(location,) = [f.rstrip('\n') for f in push_file]
76
return location.rstrip('\n')
92
79
>>> shell_escape('hello')
114
101
def __init__(self, rsync_name):
115
102
Exception.__init__(self, "%s not found." % rsync_name)
117
def rsync(source, target, ssh=False, excludes=(), silent=False,
104
def rsync(source, target, ssh=False, excludes=(), silent=False,
118
105
rsync_name="rsync"):
120
107
>>> new_dir = tempfile.mkdtemp()
191
178
raise RsyncUnknownStatus(proc.returncode)
192
179
return [l.split(' ')[-1].rstrip('\n') for l in result.splitlines(True)]
194
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
181
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
195
182
'.bzr/branch/parent', '.bzr/x-pull-data', '.bzr/x-pull',
196
183
'.bzr/pull', '.bzr/stat-cache', '.bzr/x-rsync-data',
197
184
'.bzr/basis-inventory', '.bzr/inventory.backup.weave')
247
234
if not location.endswith('/'):
249
236
push_location = location
251
238
if push_location is None:
252
239
raise BzrCommandError("No rspush location known or specified.")
241
if (push_location.find('::') != -1):
254
246
if (push_location.find('://') != -1 or
255
247
push_location.find(':') == -1):
256
248
raise BzrCommandError("Invalid rsync path %r." % push_location)
285
277
" specified location. Please ensure that"
286
278
' "%s" is of the form "machine:/path".' % push_location)
287
279
print "Pushing to %s" % push_location
288
rsync(tree.basedir+'/', push_location, ssh=True,
280
rsync(tree.basedir+'/', push_location, ssh=usessh,
289
281
excludes=final_exclusions)
291
283
set_push_data(tree, push_location)
302
294
"""Screen-scrape Apache listings"""
303
295
apache_dir = '<img border="0" src="/icons/folder.gif" alt="[dir]">'\
298
t._remote_path = lambda x: t.base
306
300
expr = re.compile('<a[^>]*href="([^>]*)"[^>]*>', flags=re.I)
307
301
for line in lines:
308
302
match = expr.search(line)
349
343
bzrdir = bzrdir_from_transport(t)
345
except (ConnectionError):
351
347
except (NotBranchError, UnsupportedFormatError, TransportError,
352
348
PermissionDenied):
364
360
except (NoSuchFile, PermissionDenied, TransportError):
368
364
def bzrdir_from_transport(t):
369
365
"""Open a bzrdir from a transport (not a location)"""
370
366
format = BzrDirFormat.find_format(t)
372
368
return format.open(t)
371
def open_from_url(location):
372
location = urlutils.normalize_url(location)
373
dirname, basename = urlutils.split(location)
374
return get_transport(dirname).get(basename)
377
379
result = doctest.testmod()