27
27
import bzrlib.errors
28
from bzrlib.errors import BzrCommandError
29
from bzrlib.bzrdir import BzrDir
28
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
29
UnsupportedFormatError, TransportError,
30
NoWorkingTree, PermissionDenied)
31
from bzrlib.bzrdir import BzrDir, BzrDirFormat
32
34
dirname = tempfile.mkdtemp("temp-branch")
66
69
return not delta.has_changed(), non_source
68
71
def set_push_data(tree, location):
69
push_file = file (tree.branch.control_files.controlfilename("x-push-data"), "wb")
70
push_file.write("%s\n" % location)
72
tree.branch.control_files.put_utf8("x-push-data", "%s\n" % location)
72
74
def get_push_data(tree):
77
79
>>> set_push_data(tree, 'http://somewhere')
78
80
>>> get_push_data(tree)
82
filename = tree.branch.control_files.controlfilename("x-push-data")
83
if not os.path.exists(filename):
85
location = tree.branch.control_files.get_utf8('x-push-data').read()
85
push_file = file (filename, "rb")
86
(location,) = [f.rstrip('\n') for f in push_file]
88
return location.rstrip('\n')
90
91
>>> shell_escape('hello')
239
240
except RsyncNoFile:
242
def push(tree, location=None, overwrite=False, working_tree=True):
243
def rspush(tree, location=None, overwrite=False, working_tree=True):
243
244
push_location = get_push_data(tree)
244
245
if location is not None:
245
246
if not location.endswith('/'):
247
248
push_location = location
249
250
if push_location is None:
250
if tree.branch.get_push_location() is None:
251
raise BzrCommandError("No push location known or specified.")
253
raise bzrlib.errors.MustUseDecorated
255
if push_location.find('://') != -1:
256
raise bzrlib.errors.MustUseDecorated
258
if push_location.find(':') == -1:
259
raise bzrlib.errors.MustUseDecorated
251
raise BzrCommandError("No rspush location known or specified.")
253
if (push_location.find('://') != -1 or
254
push_location.find(':') == -1):
255
raise BzrCommandError("Invalid rsync path %r." % push_location)
262
258
clean, non_source = is_clean(tree)
301
297
return new_committer
301
"""Screen-scrape Apache listings"""
302
apache_dir = '<img border="0" src="/icons/folder.gif" alt="[dir]">'\
305
expr = re.compile('<a[^>]*href="([^>]*)"[^>]*>', flags=re.I)
307
match = expr.search(line)
311
if url.startswith('http://') or url.startswith('/') or '../' in url:
315
yield url.rstrip('/')
318
def iter_branches(t, lister=None):
319
"""Iterate through all the branches under a transport"""
320
for bzrdir in iter_bzrdirs(t, lister):
322
branch = bzrdir.open_branch()
323
if branch.bzrdir is bzrdir:
325
except (NotBranchError, UnsupportedFormatError):
329
def iter_branch_tree(t, lister=None):
330
for bzrdir in iter_bzrdirs(t, lister):
332
wt = bzrdir.open_workingtree()
334
except NoWorkingTree, UnsupportedFormatError:
336
branch = bzrdir.open_branch()
337
if branch.bzrdir is bzrdir:
339
except (NotBranchError, UnsupportedFormatError):
343
def iter_bzrdirs(t, lister=None):
346
return t.list_dir('.')
348
bzrdir = bzrdir_from_transport(t)
350
except (NotBranchError, UnsupportedFormatError, TransportError,
354
for directory in lister(t):
355
if directory == ".bzr":
358
subt = t.clone(directory)
359
except UnicodeDecodeError:
361
for bzrdir in iter_bzrdirs(subt, lister):
363
except (NoSuchFile, PermissionDenied, TransportError):
367
def bzrdir_from_transport(t):
368
"""Open a bzrdir from a transport (not a location)"""
369
format = BzrDirFormat.find_format(t)
370
BzrDir._check_supported(format, False)
371
return format.open(t)
306
376
result = doctest.testmod()