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._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._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')
190
189
raise RsyncUnknownStatus(proc.returncode)
191
190
return [l.split(' ')[-1].rstrip('\n') for l in result.splitlines(True)]
193
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
194
'.bzr/branch/parent', '.bzr/x-pull-data', '.bzr/x-pull',
195
'.bzr/pull', '.bzr/stat-cache', '.bzr/x-rsync-data',
196
'.bzr/basis-inventory', '.bzr/inventory.backup.weave')
192
exclusions = ('.bzr/x-push-data', '.bzr/parent', '.bzr/x-pull-data',
193
'.bzr/x-pull', '.bzr/pull', '.bzr/stat-cache',
194
'.bzr/x-rsync-data', '.bzr/basis-inventory',
195
'.bzr/inventory.backup.weave')
199
198
def read_revision_history(fname):
212
211
tempdir = tempfile.mkdtemp('push')
214
213
history_fname = os.path.join(tempdir, 'revision-history')
216
cmd = rsync(location+'.bzr/revision-history', history_fname,
219
cmd = rsync(location+'.bzr/branch/revision-history', history_fname,
214
cmd = rsync(location+'.bzr/revision-history', history_fname,
221
216
history = read_revision_history(history_fname)
223
218
shutil.rmtree(tempdir)
240
235
except RsyncNoFile:
243
def rspush(tree, location=None, overwrite=False, working_tree=True):
238
def push(tree, location=None, overwrite=False, working_tree=True):
244
239
push_location = get_push_data(tree)
245
240
if location is not None:
246
241
if not location.endswith('/'):
248
243
push_location = location
250
245
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)
246
if tree.branch.get_push_location() is None:
247
raise BzrCommandError("No push location known or specified.")
249
raise bzrlib.errors.MustUseDecorated
251
if push_location.find('://') != -1:
252
raise bzrlib.errors.MustUseDecorated
254
if push_location.find(':') == -1:
255
raise bzrlib.errors.MustUseDecorated
257
clean, non_source = is_clean(tree)
259
print """Error: This tree has uncommitted changes or unknown (?) files.
260
Use "bzr status" to list them."""
258
clean, non_source = is_clean(tree)
260
print """Error: This tree has uncommitted changes or unknown (?) files.
261
Use "bzr status" to list them."""
263
263
final_exclusions = non_source[:]
297
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)
376
302
result = doctest.testmod()