在Windows批处理文件中包装SVN Python钩子 [英] Wrapping an SVN Python hook in a Windows batch file

查看:45
本文介绍了在Windows批处理文件中包装SVN Python钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SVN预提交钩子,该钩子先前位于Linux服务器上.我现在正在尝试将内容移至Windows(Server 2003)服务器.

I have an SVN pre-commit hook that previously resided on a Linux server. I'm now trying to move things over to a Windows (Server 2003) server.

此钩子是用Python编写的,在Linux上运行良好,顶部带有#!/usr/bin/env python 行.但是Windows无法以这种方式工作,并且需要将钩子作为批处理文件(或其他格式,但仍然不是Python).

This hook was written in Python, which worked fine on Linux with its #!/usr/bin/env python line at the top. Windows, however, doesn't work that way and requires hooks to be batch files (or other formats, but still not Python).

重要的是,将参数传递给脚本,并将退出代码返回给调用进程(SVN服务器),以便它知道是否允许提交.我对 .bat 文件语法几乎一无所知,但我认为这样可以解决问题:

The important thing is that the arguments get passed to the script and the exit code gets returned to the calling process (the SVN server), so that it knows whether or not to allow the commit. I know next to nothing about .bat file syntax, but I thought that something like this would do the trick:

C:\Python26\python.exe pre-commit.py %1 %2

我是否正确地认为这是包装Python脚本的最简单方法?会自动返回脚本的退出代码吗?

Am I right in thinking that this is the simplest way to wrap the Python script? Will it automatically return the exit code of the script?

推荐答案

回答我自己的问题:这几乎可行.退出代码是通过 ERRORLEVEL 变量检测到的,但是由于环境为空,必须完全指定脚本的路径.幸运的是,第一个参数包含存储库的位置,因此它只是:

To answer my own question: this almost works. The exit code is detected through the ERRORLEVEL variable, but due to the empty environment, the path to the script must be fully specified. Thankfully the first argument contains the location of the repository, so it's just:

C:\Python26\python.exe %1\hooks\pre-commit.py %1 %2

这篇关于在Windows批处理文件中包装SVN Python钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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