PySVN - 确定存储库是否存在
我正在编写一个小脚本来管理多个 SVN 存储库。用户传递他们想要更改的存储库的 ID(存储库的根的格式为 https://www.mydomain.com/)。 mydomain.com/)。
我需要检查给定的存储库是否确实存在。我尝试使用 Client.list 来查看是否可以找到任何文件,如下所示:
client = pysvn.Client()
client.list("https://.../<username>/")
但是如果存储库不存在,则脚本将挂在列表行上。通过挖掘回溯,看起来 pysvn 实际上挂在登录凭据回调上(client.callback_get_login - 我已经实现但省略了,如果存储库存在,它不会失败)。
你能建议我如何使用 pysvn 确定存储库是否存在?
干杯,
皮特
I'm writing a small script that manages several SVN repositories. Users pass through the ID of the repository they want to change (the root of the repos are of the form https://www.mydomain.com/).
I need to check if the given repo actually exists. I've tried using Client.list
to see if I can find any files, like so:
client = pysvn.Client()
client.list("https://.../<username>/")
But if the repo does not exist then the script hangs on the list line. From digging through the tracebacks it looks like pysvn is actually hanging on the login credentials callback (client.callback_get_login - which I have implemented but omitted, it does not fail if the repo exists).
Can you suggest how I can determine if a repo exists or not using pysvn?
Cheers,
Pete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现您的挂在凭据回调中问题,因此可能需要对该问题进行扩展描述。我在 Ubuntu 10.04、Python 2.6.6 上运行 pysvn 1.7.2。
当我尝试使用 client.list() 列出不存在的远程存储库时,它会引发异常。您还可以使用 client.info2() 来检查远程存储库是否存在:
I couldn't reproduce your hanging in credentials callback problem, so it might need an expanded description of the problem. I'm running pysvn 1.7.2 on Ubuntu 10.04, Python 2.6.6.
When I try to list a non-existent remote repository with
client.list()
it raises an exception. You could also useclient.info2()
to check for existence of a remote repository:彼得,
我和我的团队经历了同样的挑战。 Samplebias,尝试提供
callback_get_login
函数,但将callback_server_ssl_trust_prompt
设置为返回(True, trust_dict['failures'], True)
。 IFF subversion 没有缓存你的服务器证书信任设置,那么你可能会发现info2()
(或 Peter 的list()
命令)挂起(它实际上不是挂起,它只是间歇性地需要更长的时间才能返回)。奇怪的是,当您在这些场景中按 CTRL-C 解释器时,您会得到指示,表明它挂在登录回调上,而不是 server_cert 验证上。尝试一下您的~/.subversion/auth
设置(特别是svn.simple
和svn.ssl.server
目录),然后您就可以了您会看到不同数量的“停留时间”。如果您需要处理真正永远不会返回的情况,请查看 pysvn.Client.callback_cancel 。考虑: http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_client_callback_ssl_server_trust_prompt 你需要决定你想要的行为是什么。您是否只想允许那些已缓存信任答案的连接?或者,无论服务器证书验证如何,您是否要始终接受(警告:这可能(显然)产生负面的安全影响)。考虑以下建议:
实际上,您可能不想像我一样对返回值感兴趣。我确实认为单独考虑服务器返回的潜在 403 和“找不到主机”场景很重要。
Peter,
My team and I have experienced the same challenge. Samplebias, try providing a
callback_get_login
function but set yourcallback_server_ssl_trust_prompt
to return(True, trust_dict['failures'], True)
. IFF subversion has not cached your server certificate trust settings, then you may find theinfo2()
(or Peter'slist()
command) hangs (it's not actually hanging, it just takes intermittently much longer time to return). Oddly, when you CTRL-C the interpreter in these scenarios, you'll get indication that it hung on the login callback, not the server_cert verification. Play around with your~/.subversion/auth
settings (in particular thesvn.simple
andsvn.ssl.server
directories) and you'll see different amounts of 'hang time'. Look atpysvn.Client.callback_cancel
if you need to handle situations which truly never return.Considering: http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_client_callback_ssl_server_trust_prompt you need to decide what your desired behavior is. Do you want ONLY to allow those connections for which you already have a cached trust answer? Or, do you want to ALWAYS accept regardless of server certificate verification (WARNING: this could (obviously) have negative security implications). Consider the following suggestion:
In actuality, you probably don't want to get as fancy as I have with the return values. I do think it was important to consider a potential 403 returned by the server and the "Host not found" scenario separately.