Dave
Dave

Reputation: 6554

Bazaar: bzrlib equivalent of "bzr info"

I'm trying to write a simple script that trawls through a list of directories, checks if they are bzr version-controlled, and then tells me what their status is - ie, how many files have been modified, added etc.

I've done this with the bzrlib Python API, and it's working great.

My final stumbling block has been trying to figure out how to get at the trunk the branch originated from.

To do this at the command line is a simple:

 bzr info

However, what is the equivalent in bzrlib?

At the moment, I'm opening the locations as working trees:

d = 'some directory'
wt = workingtree.WorkingTree.open(d)

I tend to use "checkout" in my work, so I would be looking for something to tell me the location of the branch the current instance is checked out from, eg from the command-line:

>bzr info dev
 Checkout (format: unnamed)
 Location:
    checkout dev: dev
 checkout of branch: bzr+ssh://bazaar.launchpad.net/....

I basically want the last line as some string that I can plug into my script.

Many thanks in advance for your time

Cheers,

Dave

For future reference, for those interested. Following the hint in the accepted answer below, here is how to get at the bzr info for using location 'd':

from bzrlib import repository, branch, workingtree, info
r = repository.Repository.open(d)
b = branch.Branch.open(d)
w = workingtree.WorkingTree.open(d)

bzr_info = info.gather_location_info(r,branch=b,working=w)

There is perhaps a more elegant way to do this, in which case feel free to add comments here!

Upvotes: 4

Views: 428

Answers (1)

AmanicA
AmanicA

Reputation: 5505

Take a look at the following methods:

bzrlib.builtins.cmd_info
bzrlib.info.show_component_info
bzrlib.info.gather_location_info

basically gather_location_info() will give you the info but AFAICT you need to give it an opened repository, branch and workingtree.

Upvotes: 2

Related Questions