[英]how to find if svn command executed successfully or not in python
I am executing svn commands (assume I do not want to use pysvn) from my python script in the following manner (for example): 我正在以以下方式(例如)从我的python脚本执行svn命令(假设我不想使用pysvn):
cmd = 'svn update http://myserver/myrepo'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, stderr = p.communicate()
status = p.returncode
if status != 0:
logging.error('A fatal has error occurred while executing command: ' + cmd)
exit(-1)
Let's say myrepo does NOT exists on the server. 假设myrepo在服务器上不存在。 It this case SVN will silently produces output like: 在这种情况下,SVN会静默产生如下输出:
Skipped http://myserver/myrepo
and the status variable has the value '0'. 并且状态变量的值为“ 0”。 Is there a way I can detect via the return code to check if SVN update skipped or in fact did update the repo successfully? 有没有一种方法可以通过返回码进行检测,以检查是否跳过了SVN更新,或者实际上是否成功更新了存储库?
For now, I am using the following solution but not sure if it is an elegant one: 目前,我正在使用以下解决方案,但不确定是否是一种优雅的解决方案:
if 'Skipped' in output:
logging.error('SVN update failed!')
exit(-1)
Elegant or not, if it works it works! 优雅与否,如果可行,那么可行! However I think you should look into pysvn, it might do the things you need. 但是我认为您应该研究pysvn,它可能会满足您的需要。 However it seems to be using svn 1.6 and not 1.7: http://pysvn.tigris.org/docs/pysvn_prog_guide.html 但是,它似乎使用的是svn 1.6,而不是1.7: http : //pysvn.tigris.org/docs/pysvn_prog_guide.html
So looks like this will be a good solution taking into consideation David's suggestion: 因此,考虑到David的建议,这似乎是一个很好的解决方案:
cmd = 'svn update http://myserver/myrepo'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, stderr = p.communicate()
status = p.returncode
if output.strip().startswith('Skipped'):
logging.error('A fatal has error occurred while executing command: ' + cmd)
exit(-1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.