jsvn: add binaries subcommand

This commit is contained in:
Josh Holtrop 2011-04-25 12:43:09 -04:00
parent 78403d3bf2
commit 7ea964ea58

26
jsvn
View File

@ -31,6 +31,9 @@
# - block until the lock on a file/URL is released # - block until the lock on a file/URL is released
# users # users
# - show a list of contributing users to a SVN path # - show a list of contributing users to a SVN path
# binaries
# - show a list of versioned binary files under the current path, with
# a prepended '*' for those with svn:needs-lock set
import sys import sys
import os import os
@ -98,6 +101,9 @@ def getSVNTagList(svn):
colist.append(re.sub(r'/$', '', line)) colist.append(re.sub(r'/$', '', line))
return colist return colist
def getSVNProperty(svn, prop, path):
return Popen([svn, 'propget', prop, path], stdout=PIPE).communicate()[0]
def branch(argv, svn): def branch(argv, svn):
if len(argv) < 2: if len(argv) < 2:
bl = ['trunk'] + getSVNBranchList(svn) bl = ['trunk'] + getSVNBranchList(svn)
@ -260,6 +266,23 @@ def users(argv, svn):
print "%8d %s" % (v[1], v[0]) print "%8d %s" % (v[1], v[0])
return 0 return 0
def binaries(argv, svn, base_path = '.'):
for ent in os.listdir(base_path):
if ent in ('.', '..', '.svn'):
continue
ent_path = os.sep.join([base_path, ent])
if os.path.isfile(ent_path):
mime_type = getSVNProperty(svn, 'svn:mime-type', ent_path)
if re.match(r'application/octet-stream', mime_type):
# we found a binary file
needs_lock = getSVNProperty(svn, 'svn:needs-lock', ent_path)
sys.stdout.write('* ' if needs_lock != '' else ' ')
sys.stdout.write(ent_path)
sys.stdout.write('\n')
elif os.path.isdir(ent_path):
binaries(argv, svn, os.sep.join([base_path, ent]))
return 0
def main(argv): def main(argv):
realsvn = findInPath('svn') realsvn = findInPath('svn')
colorsvn = findInPath('colorsvn') colorsvn = findInPath('colorsvn')
@ -304,6 +327,9 @@ def main(argv):
if argv[0] == "users": if argv[0] == "users":
return users(argv, realsvn) return users(argv, realsvn)
if argv[0] == "binaries":
return binaries(argv, realsvn)
if argv[0] in ('st', 'status', 'log', 'up', 'update') \ if argv[0] in ('st', 'status', 'log', 'up', 'update') \
and colorsvn != '': and colorsvn != '':
realsvn = colorsvn realsvn = colorsvn