我最终使用 pysvn 绑定(非常易于使用)编写了一个脚本来执行此操作。它在下面,以防有人想要它。
import sys
import os
from optparse import OptionParser
import pysvn
import re
usage = """%prog [path] property-name property-value
Set property-name to property-value on all non-tag subdirectories in an svn working copy.
path is an optional argument and defaults to "."
"""
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main():
try:
parser = OptionParser(usage)
(options, args) = parser.parse_args()
if len(args) < 2:
raise Usage("Must specify property-name and property-value")
elif len(args) == 2:
directory = "."
property_name = args[0]
property_value = args[1]
elif len(args) == 3:
directory = args[0]
property_name = args[1]
property_value = args[2]
elif len(args) > 3:
raise Usage("Too many arguments specified")
print "Setting property %s to %s for non-tag subdirectories of %s" % (property_name, property_value, directory)
client = pysvn.Client()
for path_info in client.info2(directory):
path = path_info[0]
if path_info[1]["kind"] != pysvn.node_kind.dir:
#print "Ignoring file directory: %s" % path
continue
remote_path = path_info[1]["URL"]
if not re.search('(?i)(\/tags$)|(\/tags\/)', remote_path):
print "%s" % path
client.propset(property_name, property_value, path, depth=pysvn.depth.empty)
else:
print "Ignoring tag directory: %s" % path
except Usage, err:
parser.error(err.msg)
return 2
if __name__ == "__main__":
sys.exit(main())