DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Copy All Subversion Properties On Directories And Files From One Source Tree To Another Identical Source Tree

  • submit to reddit
        Copy all subversion properties on directories and files from one source tree to another identical source tree. 

Works well for copying between two revisions of a vendor library where a new directory is used for each revision. For example, svncopyprop openssl/0.9.8l openssl/0.9.8m

Works on Windows. Expect that it should work on Linux as well.

# This script will copy all subversion properties from one source tree
# to another identical source tree. It is best for copying between
# revisions of a vendor library. e.g. /openssl/0.9.8l -> /openssl/0.9.8m
# Usage: svncopyprop SRC DST

import sys, os, subprocess, tempfile

mytemp = tempfile.NamedTemporaryFile(delete=False)
mytempfile =

def myexec(kargs, show):
    if show: print ' '.join(kargs)
    return subprocess.Popen(kargs, stdout=subprocess.PIPE).communicate()[0]
def svncopyprop(src, dst):
    if not os.path.exists(dst): 
    out = myexec(['svn', 'pl', '-q', src], False)
    pnames = out.split()
    for pname in pnames:
        out = myexec(['svn', 'pg', '--strict', pname, src], False)
        with file(mytempfile, 'wt') as f:
            out = '\n'.join(out.split())
        myexec(['svn', 'ps', pname, dst, '--file', mytempfile], True)

    if os.path.isdir(src): 
        for subdir in os.listdir(src):
            if subdir == '.svn': continue
            nsrc = os.path.join(src, subdir)
            ndst = os.path.join(dst, subdir)
            svncopyprop(nsrc, ndst)
svncopyprop(sys.argv[1], sys.argv[2])