#!/usr/bin/python
"""
Update all Subversion trees within a given directory.
"""
import sys, os, os.path
from optparse import OptionParser
import pysvn
parser = OptionParser(usage="%prog [options] FILE...");
parser.add_option("-d", "--directory", dest="directory", default=".", help="The base directory for updating.", metavar="DIRECTORY")
(options, args) = parser.parse_args()
#repository = repos.open(directory)
basedir = options.directory
dirs = os.listdir(basedir)
def printlist(fnlist):
if len(fnlist) == 0:
print "\tNo files"
else:
for fn in fnlist:
print "\t%s" % (fn)
for dir in dirs:
client = pysvn.Client()
fulldir = os.path.join(basedir, dir)
if os.path.isdir(os.path.join(fulldir)):
print ""
print "Working on directory %s..." % (fulldir)
sys.stdout.flush()
try:
canupdate = True
changes = client.status(fulldir)
fadded = [f.path for f in changes if f.text_status == pysvn.wc_status_kind.added]
fremoved = [f.path for f in changes if f.text_status == pysvn.wc_status_kind.deleted]
fchanged = [f.path for f in changes if f.text_status == pysvn.wc_status_kind.modified]
fconflicts = [f.path for f in changes if f.text_status == pysvn.wc_status_kind.conflicted]
funversioned = [f.path for f in changes if f.text_status == pysvn.wc_status_kind.unversioned]
if ( (len(fadded) == 0)
and (len(fremoved) == 0)
and (len(fchanged) == 0)
and (len(fconflicts) == 0)
and (len(funversioned) == 0)) :
# If no local changes exist, update the repository
print "Updating repository in directory %s..." % (fulldir)
sys.stdout.flush()
client.update(fulldir)
print "Finished."
sys.stdout.flush()
else:
print 'files to be added:'
printlist(fadded)
print 'files to be removed:'
printlist(fremoved)
print 'files that have changed:'
printlist(fchanged)
print 'files with merge conflicts:'
printlist(fconflicts)
print 'unversioned files:'
printlist(funversioned)
sys.stdout.flush()
except:
print "failure"