|
=== Spads_ is now known as Spads |
|
[11:32] <aquarius> I'd like to do the equivalent of bzr cat from a Python script -- that is, write a function which takes an lp URL for a file and returns the content of that file. Is the best approach to call the bzr cat command object and give it a StringIO to output into (which I can't work out how to do), or to do the things that the command object *does* myself? |
|
[11:38] <aquarius> I *think* the way to do it is this: |
|
[11:39] <aquarius> from bzrlib.plugin import load_plugins;load_plugins();from bzrlib.branch import Branch;remote_branch_url = 'lp:~sil/+junk/ucs-demo-app';b = Branch.open(remote_branch_url); tree=b.basis_tree(); file_id=tree.path2id('ubuntu_component_store.json'); print tree.get_file_text(file_id) |
|
[11:42] <james_w> aquarius: that looks about right |
|
[11:42] <aquarius> cool, I'm not doing anything insane, then :) |
|
[11:43] <aquarius> am I better to check the file exists with tree.has_id first, or do I end up hitting the network twice then and so I should just catch exceptions on tree.path2id? |
|
[11:45] <james_w> aquarius: catching an exception makes more sense I thinnk |
|
[11:45] <james_w> aquarius: or I think it returns None in fact |
|
[11:45] <aquarius> cool, then I'll just do it and check :) |
|
=== ciampix_ is now known as ciampix |
|
|