Reading bazaar output?

John Arbash Meinel john at arbash-meinel.com
Sun Aug 10 21:37:36 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Eduardo O. Padoan wrote:
> On Sun, Aug 10, 2008 at 3:48 PM, Javier Derderian <javierder at gmail.com> wrote:
>> Hi,
>>
>> I'm working on a feature for bzr-gedit that needs reading/grabbing all the
>> info bzr writes to stdout, it's an "output window".
>> How can i do this, since i'm using bzrlib?
>> I mean, how can I do this from "inside" python?
> 
> You could redirect the IO to a StringIO file:
> http://code.activestate.com/recipes/534166/
> 
> But does the bzrlib api produces any output? I mean, this is the work
> of the tool, not of the api. But I haven't tryed the extension api
> (yet!), so I'm just guessing :)
> 
> (Sorry Javier, replying to the list too now)
> 
>> Thanks.
>>
>> --
>> Javier Derderian
>> javierder at gmail.com
>> ---
>> En la Alegría serás Imbatible

So, you *could* use the cmd_* classes to run operations. In general,
though, we have a much richer api using Objects. For example:

a_branch = bzrlib.branch.Branch.open('location')

or to do status

working_tree = bzrlib.workingtree.WorkingTree.open('location')
working_tree.lock_read()
basis_tree = working_tree.basis_tree()

for XXX in working_tree.iter_changes(basis_tree):

Which will give you nicely parsed information about changed paths, and
what has changed, etc. Rather than trying to parse the output of "bzr
status" to give you the same information.

If you were strictly trying to just run a bzr command (say something
that bzr-gedit doesn't normally allow), then I would probably do
something like:

cmd = bzrlib.builtins.cmd_status()
cmd.outf = my_file_like_object
cmd.run()

Or if you really want to force it, you can override sys.stdout and
sys.stderr.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkifUZAACgkQJdeBCYSNAAOL4QCgu/m+HyB8PhcfV4EGUi+BOuHc
mfwAoNGQUh85lwTYYKZDVyzzDh7Thexg
=G791
-----END PGP SIGNATURE-----



More information about the bazaar mailing list