From f307e3d2566732271b69452cd53c71d2f8fceec7 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 13 Apr 2011 08:43:15 -0400 Subject: [PATCH] jsvn: add 'watch-lock' subcommand for notification when file is unlocked --- jsvn | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/jsvn b/jsvn index 493341a..07bae44 100755 --- a/jsvn +++ b/jsvn @@ -30,6 +30,7 @@ import sys import os import re +import time from subprocess import * PATH = os.environ['PATH'].split(os.pathsep) @@ -180,6 +181,47 @@ def merge(argv, svn): root + '/branches/' + argv[1] + path, '.']).wait() return 0 +def watch_lock(argv, svn): + if len(argv) < 2: + return -1 + path = argv[1] + if os.path.exists(path): + # Get the repository URL of the file being watched + p = Popen([svn, 'info', path], stdout=PIPE) + lines = p.communicate()[0].split('\n') + for line in lines: + m = re.match(r'URL: (.*)', line) + if m is not None: + path = m.group(1) + break + + last_lock_owner = '' + while 1: + lock_owner = '' + p = Popen([svn, 'info', path], stdout=PIPE) + lines = p.communicate()[0].split('\n') + for line in lines: + m = re.match(r'Lock\sOwner:\s*(.*)', line) + if m is not None: + lock_owner = m.group(1) + break + if lock_owner == '': + break + if lock_owner != last_lock_owner: + sys.stdout.write('Locked by: %s\n' % lock_owner) + last_lock_owner = lock_owner + time.sleep(60) + + sys.stdout.write(''' + _ _ _ _ _ _ +| | | |_ __ | | ___ ___| | _____ __| | | +| | | | '_ \| |/ _ \ / __| |/ / _ \/ _` | | +| |_| | | | | | (_) | (__| < __/ (_| |_| + \___/|_| |_|_|\___/ \___|_|\_\___|\__,_(_) + +''') + return 0 + def main(argv): realsvn = findInPath('svn') colorsvn = findInPath('colorsvn') @@ -218,6 +260,9 @@ def main(argv): sys.stdout.write(getSVNRoot(realsvn) + '\n') return 0 + if argv[0] == "watch-lock": + return watch_lock(argv, realsvn) + if argv[0] in ('st', 'status', 'log', 'up', 'update') \ and colorsvn != '': realsvn = colorsvn