Skip to content

Instantly share code, notes, and snippets.

@xperimental
Created April 1, 2010 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperimental/351503 to your computer and use it in GitHub Desktop.
Save xperimental/351503 to your computer and use it in GitHub Desktop.
Simple script to switch multiple working copies to a new URL
# Simple script to switch multiple working copies to a new URL
import glob
import os
from optparse import OptionParser
import subprocess
import re
print "switch-all SVN mass switch script\n"
url_re = re.compile('URL:\s(\S+)')
parser = OptionParser()
parser.add_option("-b", "--base", dest="basedir", help="local base directory of projects")
parser.add_option("-f", "--from", dest="fromurl", help="part of URL to replace")
parser.add_option("-t", "--to", dest="tourl", help="replacement for FROMURL part")
(options, args) = parser.parse_args()
if (not options.basedir):
print "error: BASEDIR missing!"
exit()
if (not options.fromurl):
print "error: FROMURL missing!"
exit()
if (not options.tourl):
print "error: TOURL missing!"
exit()
print "Base: " + options.basedir
print "From: " + options.fromurl
print " To: " + options.tourl
dirs = glob.glob(options.basedir + "/*")
for p in dirs:
print "\nProject: " + p
if (not os.path.isdir(p + "/.svn")):
print " skip: no svn working copy!"
continue
print " getting current url..."
svn = subprocess.Popen(['svn', 'info', p], stdout=subprocess.PIPE)
(svnout, svnerr) = svn.communicate()
url_match = url_re.search(svnout)
if (not url_match):
print " skip: no URL found!"
continue
url_current = url_match.group(1)
print " URL: " + url_current
print " Create new url..."
url_new = url_current.replace(options.fromurl, options.tourl)
print " URL: " + url_new
if (url_new == url_current):
print " skip: no URL change!"
continue
print " Switch project to new URL..."
svn = subprocess.Popen(['svn', 'switch', url_new, p], stdout=subprocess.PIPE)
(svnout, svnerr) = svn.communicate()
print " Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment