views:

28

answers:

2

hi, guys,

if i use python write a script to call svn as a subprocess to checkout source code, e.g.

p = subprocess.Popen("svn checkout file:///tmp/repos/test mine"),

what is the return value of the success or failure of svn-checkout subprocess?

Thanks

A: 

Have you read the docs about Subprocess ?

 returnCode = p.returncode

This will contain the return code of the svn call.

khmarbaise
OK, maybe I did not write it clearly. I know there is p.returncode. but what I want to know is, what is the return value for the success or failure of svn checkout, if there is any.
pepero
the exact value, not the code or variable. e.g. 0 for success. -1 for failure.
pepero
0 means success anything else means something has gone wrong.
khmarbaise
Thank you khmarbaise, for your follow-up. is it possible to know the failure type. e.g. if it is the password error, network connection error or wrong url error. I am asking this because i am developing a GUI with python. so I need this error type to give interactive feedback to the user.
pepero
As far as i know not. But you can ask on the Subversion dev-list for this kind of information. If you developing in Python why don't you use the pyhton bindings than you have more control on the error handling for this.
khmarbaise
Here you find an example for Python with Python binding: http://svnbook.red-bean.com/nightly/en/svn-book.html#svn.developer.usingapi.otherlangs.ex-2
khmarbaise
A: 

According to this Python 2.7 spec, calling Popen.wait() or Popen.poll() sets the Popen.returncode attribute. I guess you can try:

p = subprocess.Popen("svn checkout file:///tmp/repos/test mine")
p.wait() # this deadlocks the thread until process completion, so use with care

# There was an error
if p.returncode != 0:
   # ...

According to the spec:

The child return code, set by poll() and wait() (and indirectly by communicate()). A None value indicates that the process hasn’t terminated yet. A negative value -N indicates that the child was terminated by signal N (Unix only).

Jaime Soto