自动获取 SVN 修订号到程序中 [英] Getting SVN revision number into a program automatically

查看:26
本文介绍了自动获取 SVN 修订号到程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SVN下有一个python项目,我想在运行时显示版本号.有没有办法做到这一点(例如在提交时自动运行一个可以更新版本文件的短脚本,或者在 Python 中查询 SVN 存储库?)

I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)

推荐答案

我不确定 Python 的具体细节,但是如果将字符串 $Revision$ 放入您的文件中的某个位置并且您在其中启用了 enable-auto-props=true您的 SVN 配置,它将被重写为类似 $Revision: 144$ 的内容.然后你可以在你的脚本中解析它.

I'm not sure about the Python specifics, but if put the string $Revision$ into your file somewhere and you have enable-auto-props=true in your SVN config, it'll get rewritten to something like $Revision: 144$. You could then parse this in your script.

一个数字您可以通过这种方式使用的属性关键字.

这不会有任何开销,例如查询 SVN 存储库,因为该字符串在提交或更新时被硬编码到您的文件中.

This won't have any overhead, e.g. querying the SVN repo, because the string is hard-coded into your file on commit or update.

我不确定你会如何在 Python 中解析它,但在 PHP 中我会这样做:

I'm not sure how you'd parse this in Python but in PHP I'd do:

$revString = '$Revision: 144$';
if(preg_match('/: ([0-9]+)\$/', $revString, $matches) {
    echo 'Revision is ' . $matches[1];
}

这篇关于自动获取 SVN 修订号到程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆