在不调用 bzr 的情况下从 Python 确定 Bazaar 版本号
我有一个 django (Python) 项目,需要知道其代码在 Bazaar 中的版本用于部署目的。这是一个 Web 应用程序,所以我不想这样做,因为它会触发一个新的子进程,并且不会扩展。
import subprocess
subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
有没有办法解析 Bazaar 存储库来计算版本号? Bazaar 本身是用 Python 编写的,包含用于计算 revno 的代码,这让我觉得这并不简单。
rh = self.revision_history()
revno = len(rh)
编辑:最终修复
from bzrlib.branch import BzrBranch
branch = BzrBranch.open_containing('.')[0]
revno = len(branch.revision_history())
编辑:最终修复,但这次是真的
from bzrlib.branch import BzrBranch
branch = BzrBranch.open_containing('.')[0]
revno = branch.last_revision_info()[0]
I have a django (Python) project that needs to know what version its code is on in Bazaar for deployment purposes. This is a web application, so I don't want to do this because it fires off a new subprocess and that's not going to scale.
import subprocess
subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
Is there a way to parse Bazaar repositories to calculate the version number? Bazaar itself is written in Python and contains this code for calculating the revno, which makes me think it isn't exactly trivial.
rh = self.revision_history()
revno = len(rh)
Edit: Final fix
from bzrlib.branch import BzrBranch
branch = BzrBranch.open_containing('.')[0]
revno = len(branch.revision_history())
Edit: Final fix but for real this time
from bzrlib.branch import BzrBranch
branch = BzrBranch.open_containing('.')[0]
revno = branch.last_revision_info()[0]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行一次并缓存结果(如果需要,在数据库/文件中)?我怀疑版本会改变那么多。
Do it once and cache the result (in a DB/file, if need be)? I doubt the version is going to change that much.
您可以使用 Bazaar 的
bzrlib
API 获取有关任何给定 Bazaar 存储库的信息。更多示例请参见此处。
You can use Bazaar's
bzrlib
API to get information about any given Bazaar repository.More examples are available here.