Perforce To SVN Output
rss

I find at work I do a lot of command line hackery, and Perforce’s output is a touch spamtastic. As such, I whipped up a quick script in python that converts most of the output to svn style output. Hope this helps someone.

# Author: Eddie Parker
# URL: http://kickingdragon.com

# Usage: p4 [command] | python perforce_to_svn.py
# i.e. p4 sync | python perforce_to_svn.py

import sys
import re
import os

r = re.compile('^.*- (?P<COMMAND>.+) (?P<PATH>[a-zA-Z]:\\\.*)')

cwd = os.getcwd().lower()

if cwd.startswith('/cygdrive/'):
	# Make it non cygwin.
	cwd = cwd.replace('/cygdrive/','')
	cwd = cwd[0] + ':' + cwd[1:]
	cwd = cwd.replace('/', '\\')

	if cwd[-1] != '\\':
		cwd += '\\'

for line in sys.stdin:
	m = r.match(line)

	if m != None:
		d = m.groupdict()
		characterCode = d['COMMAND'][0].upper()
		path = d['PATH']

		if path.lower().startswith(cwd):
			path = path[len(cwd):]

		print ' %s %s'%(characterCode, path)
	else:
		sys.stdout.write(line)