~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2006-03-24 16:22:11 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060324162211-587ea2d2e6386e63
Added branches subcommand

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import bzrlib
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
from bzrlib.bzrdir import BzrDir, BzrDirFormat
30
31
 
31
32
def temp_tree():
32
33
    dirname = tempfile.mkdtemp("temp-branch")
301
302
    return new_committer
302
303
 
303
304
 
 
305
def iter_branches(t):
 
306
    """Iterate through all the branches under a transport"""
 
307
    try:
 
308
        bzrdir = bzrdir_from_transport(t)
 
309
        branch = bzrdir.open_branch()
 
310
        if branch.bzrdir is bzrdir:
 
311
            yield branch
 
312
    except (NotBranchError, UnsupportedFormatError):
 
313
        pass
 
314
    except TransportError, e:
 
315
        pass
 
316
    try:
 
317
        for directory in t.list_dir('.'):
 
318
            if directory == ".bzr":
 
319
                continue
 
320
            subt = t.clone(directory)
 
321
            for branch in iter_branches(subt):
 
322
                yield branch
 
323
    except NoSuchFile:
 
324
        pass
 
325
    except TransportError, e:
 
326
        pass
 
327
 
 
328
    
 
329
def bzrdir_from_transport(t):
 
330
    """Open a bzrdir from a transport (not a location)"""
 
331
    format = BzrDirFormat.find_format(t)
 
332
    BzrDir._check_supported(format, False)
 
333
    return format.open(t)
 
334
 
 
335
 
304
336
def run_tests():
305
337
    import doctest
306
338
    result = doctest.testmod()