Thursday, November 13, 2014

command line SVN in Windows

I have a system with TortoiseSVN installed, and a windows program that is running python that can make DOS system calls. I needed a way to do an SVN checkout from our repository from a python script.

TortoiseSVN has a command line interface, but it turns out that what this interface actually does is control the Tortoise GUI, not directly issue SVN commands. What I needed was to perform checkouts of specific files from a list of repository locations and revision levels. It turns out that using the Tortoise command line interface it is possible to check out folders, but not individual files. Also, the GUI pops up and you have to his OK or CANCEL, etc.

In the end, I installed a different SVN client. I recall that there weren't all that many options; I chose "Slik Subversion" despite it's lack of documentation.

https://www.sliksvn.com/en/support/using-subversion/basic-subversion-usage

I had a ton of problems getting the command line for performing the SlikSvn export to work, I was getting a message 'C:\Program' is not recognized as an internal or external command, operable program or batch file.' As one forum thread I consulted noted, this is obviously because "Program Files" has a space. By now, I am not sure exactly why this was a problem now and not with any of the other GNU routines that I am command-line calling from other parts of my python code. However, I did use the "shortened" version of Program Files in the final code. The final code also had a bunch of nice neatening and trimming of the SVN location pointer from each line of the configuration file. Here is the result:

svn_command = "C:/Progra~1/SlikSvn/bin/svn.exe export --force -r %s %s %s" % (svn_level, checkout_url, buildDir)
status = 0
try:
status = os.system('"C:/Progra~1/SlikSvn/bin/svn.exe" export --force -r %s %s %s' % (svn_level, checkout_url, buildDir) )
except:
print "Svn checkout command %s failed. Exiting." % svn_command
manifest_file.close()
return
if (status != 0):
print "Svn checkout command %s failed. Exiting." % svn_command
manifest_file.close()
return


Here is a forum thread about using alternatives to os.system to get status back from system calls. Again, I am not sure why I was over on this page, since os.system ended up verifiably returning status very nicely in my final code.

http://stackoverflow.com/questions/3503879/assign-output-of-os-system-to-a-variable-and-prevent-it-from-being-displayed-on

Here is the Wikipedia page listing all the SVN clients available. There's plenty of Windows ones here even after the Linux clients are ruled out. Not sure why I picked SlikSVN except that somebody must have mentioned it favorably in a forum thread somewhere.

http://en.wikipedia.org/wiki/Comparison_of_Subversion_clients


Here's the "money link" where it states that there is no way to do a single file checkout from the TortoiseSVN command line controller
http://subversion.1072662.n5.nabble.com/Ask-question-gt-Can-checkout-only-single-file-td138991.html


Links to the TortoiseSVN Command Line controller documentation:
http://stackoverflow.com/questions/1625406/using-tortoisesvn-via-the-command-line
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html
Note: I checked out using Export instead of Checkout, but that GUI control for this command is even less helpful:
http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-dug-export.html
However, knowing that single-file checkouts just don't happen in SVN (from the below link) was the knowledge that enabled me to format my SlikSubversion command as an Export:
http://stackoverflow.com/questions/122107/checkout-one-file-from-subversion

When I was thrashing about with the "C:\Program is not recognized as an internal or external command" error, I found a few links about something called the Command Processor AutoRun setting. This turned out to not have anything to do with my problem, but was interesting anyways:
http://www.donationcoder.com/forum/index.php?topic=33462.0;prev_next=prev
http://blogs.msdn.com/b/oldnewthing/archive/2007/11/21/6447771.aspx
http://www.herongyang.com/Windows-Security/PWS-Command-Processor-AutoRun-Registry-Value.html