Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting Subversion log to CSV

Tags:

logging

svn

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.

like image 677
Allain Lalonde Avatar asked Apr 23 '10 02:04

Allain Lalonde


People also ask

How do I view SVN logs?

Examples. You can see the log messages for all the paths that changed in your working copy by running svn log from the top: $ svn log ------------------------------------------------------------------------ r20 | harry | 2003-01-17 22:56:19 -0600 (Fri, 17 Jan 2003) | 1 line Tweak.


1 Answers

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').encode('utf-8'),
                child.findtext('msg').encode('utf-8'),
        ])

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 
like image 180
Charles Duffy Avatar answered Oct 15 '22 07:10

Charles Duffy