tags:

views:

78

answers:

1

Is there a simple way to export the subversion logs to a CSV file?

I want to use them to approximate my hours spent on a project and doing so in an spreadsheet would be easy.

Thanks.

A: 

This short Python script will provide a CSV with your SVN log output:

#!/usr/bin/env python

import csv
import subprocess
import sys
import xml.etree.cElementTree as etree

log_text = subprocess.Popen(['svn', 'log', '--xml'] + sys.argv[1:],
                            stdout=subprocess.PIPE).communicate()[0]
log_xml = etree.XML(log_text)

csv_writer = csv.writer(sys.stdout)

for child in log_xml.getchildren():
        csv_writer.writerow([
                child.attrib['revision'],
                child.findtext('date'),
                child.findtext('author'),
                child.findtext('msg'),
        ])

It passes through command-line arguments to the underlying SVN call, so if you only want to see revision 34 and later, you can invoke it as follows:

$ svnlog2csv -r 34:HEAD >my_spreadsheet.csv 
Charles Duffy