Bazaar:bzrlib 相当于“bzr info”

发布于 2025-01-02 09:58:39 字数 993 浏览 0 评论 0原文

我正在尝试编写一个简单的脚本,它会遍历目录列表,检查它们是否受 bzr 版本控制,然后告诉我它们的状态是什么 - 即有多少文件已被修改、添加等。

我已经使用 bzrlib Python API 完成了这项工作,并且效果很好。

我的最后一个绊脚石是试图找出如何到达树枝起源的树干。

在命令行执行此操作很简单:

 bzr info

但是,bzrlib 中的等效项是什么?

目前,我正在将位置打开为工作树:

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

我倾向于在工作中使用“签出”,因此我会寻找一些东西来告诉我当前实例签出的分支的位置,例如从命令行:

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

我基本上希望最后一行作为可以插入脚本中的字符串。

非常感谢您抽出时间,

干杯,

戴夫

,供感兴趣的人将来参考。按照下面接受的答案中的提示,以下是如何获取使用位置“d”的 bzr 信息:

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)

也许有一种更优雅的方法来执行此操作,在这种情况下,请随意在此处添加评论!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨落□心尘 2025-01-09 09:58:39

看看以下方法:

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

基本上,gather_location_info() 会给你信息,但 AFAICT 你需要给它一个打开的存储库、分支和工作树。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文