27
27
import bzrlib.errors
28
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
29
UnsupportedFormatError, TransportError,
30
NoWorkingTree, PermissionDenied)
31
from bzrlib.bzrdir import BzrDir, BzrDirFormat
28
from bzrlib.errors import BzrCommandError
29
from bzrlib.bzrdir import BzrDir
34
32
dirname = tempfile.mkdtemp("temp-branch")
69
66
return not delta.has_changed(), non_source
71
68
def set_push_data(tree, location):
72
tree.branch.control_files.put_utf8("x-push-data", "%s\n" % location)
69
push_file = file (tree.branch.control_files.controlfilename("x-push-data"), "wb")
70
push_file.write("%s\n" % location)
74
72
def get_push_data(tree):
79
77
>>> set_push_data(tree, 'http://somewhere')
80
78
>>> get_push_data(tree)
85
location = tree.branch.control_files.get_utf8('x-push-data').read()
82
filename = tree.branch.control_files.controlfilename("x-push-data")
83
if not os.path.exists(filename):
88
return location.rstrip('\n')
85
push_file = file (filename, "rb")
86
(location,) = [f.rstrip('\n') for f in push_file]
91
90
>>> shell_escape('hello')
240
239
except RsyncNoFile:
243
def rspush(tree, location=None, overwrite=False, working_tree=True):
242
def push(tree, location=None, overwrite=False, working_tree=True):
244
243
push_location = get_push_data(tree)
245
244
if location is not None:
246
245
if not location.endswith('/'):
248
247
push_location = location
250
249
if push_location is None:
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)
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
258
262
clean, non_source = is_clean(tree)
297
301
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)
376
306
result = doctest.testmod()