Skip to content

Instantly share code, notes, and snippets.

@schuster-rainer
Created October 12, 2011 12:41
Show Gist options
  • Save schuster-rainer/1281133 to your computer and use it in GitHub Desktop.
Save schuster-rainer/1281133 to your computer and use it in GitHub Desktop.
get the change history from a repository and write it as csv to disk
# download and install http://pysvn.tigris.org
import pysvn
import csv
from datetime import datetime
svn = pysvn.Client()
#DATEFORMAT = "%Y-%m-%d %H:%M:%S"
DATEFORMAT = "%Y-%m-%d"
def create_change_entry(log_item):
""" revision number based"""
date = datetime.fromtimestamp(log_item["date"])
return dict(revision=log_item["revision"].number,
date=date.strftime(dateformat),
message=log_item["message"],
author=log_item["author"])
def write_csv( filename, changes, fields=None, delimiter="\t"):
with open( filename, 'w') as outfile:
if fields:
# only use the fields specified and don't throw an exception on extra fields
writer = csv.DictWriter(outfile, fields, delimiter=delimiter, extrasaction='ignore')
else:
writer = csv.DictWriter(outfile, delimiter=delimiter)
writer.writeheader()
writer.writerows(changes)
if __name__ == "__main__":
#TODO: Add command line parsing
# parameters: dateformat, ouput_file, url
# optionally use the pipe as output
output_file = "<some file name>"
url = "<some subversion repository>"
log_items = svn.log(url)
changes = map( create_change_entry, log_items)
write_csv( output_file, changes, fields=["revision", "date", "message", "author"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment