[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

cadaver+expect+wget = svn co

From: Craig Peterein <craig_at_peterein.org>
Date: 2002-12-06 02:27:39 CET

Someone a while back wanted to wget from an svn repository. But you can't just
grab the regular url, since someone may commit in the middle. I wrote the
script below as a small exercise, and as an excuse to install cadaver. Given a
repository and a path, it gets the baseline collection url.

Props to sussman for walking me through the three steps to the baseline
collection. That was a few weeks ago on irc.

Enjoy :-)

Craig

$ cat get-bc-url
#!/usr/bin/env expect

log_user 0
set timeout -1
set usage_text "
Returns the current magic baseline collection URL for a given REPO PATH
combination. If authentication is required, use USER and read the password
from stdin.

Usage:
get-bc-url REPO PATH \[USER]

Examples:
get-bc-url http://svn.collab.net/repos/svn trunk

get-bc-url http://host/repo path user << EOF
password
EOF

bcurl=\$(get-bc-url ...)
wget -q -np --mirror -e \"robots = off\" \"\${bcurl}\"
"

proc usage {} {
        global usage_text
        send_error "$usage_text"
        exit
}

if { $argc < 2 } { usage }

set url [string trim [lindex "$argv" 0] "/"]
set path [string trim [lindex "$argv" 1] "/"]
set username [lindex "$argv" 2]

proc handle_auth {} {
        global username
        if { $username == "" } { usage }

        send "$username\n"

        expect "Password:"
        stty -echo
        expect_user -re "(.*)\n"
        stty echo
        set password "$expect_out(1,string)"

        send "$password\n"
        expect ">"
}

spawn cadaver $url
expect ">" {} "Username:" { handle_auth }

send "set namespace DAV:\n"
expect ">"

# figure out version controlled configuration
send "propget . version-controlled-configuration\n"
expect -re "<href>(.+)</href>"
set vcc "$expect_out(1,string)"
expect ">"

# figure out baseline resource
send "propget $vcc checked-in\n"
expect -re "<href>(.+)</href>"
set br "$expect_out(1,string)"
expect ">"

# figure out baseline collection
send "propget $br baseline-collection\n"
expect -re "<href>(.+)</href>"
set bc "$expect_out(1,string)"
expect ">"

send "cd $bc$path\n"
expect ">"

send "pwd\n"
expect -re "`(.+)'\."
set out "$expect_out(1,string)"

send_user "$out\n"

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Dec 6 02:28:27 2002

This is an archived mail posted to the Subversion Dev mailing list.