''' Created on Jun 14, 2013 @author: acaproni ''' import os from xml.dom import minidom import SvnLogEntry import TwikiChangeLog class SvnLog: ''' Read a XML file of logs generated by SVN and build a internal representation. The internal representation is a in-memory representation of the original XML i.e. a list of logeEntry objects with author, date @see: SvnLogEntry ''' def __init__(self, fileName): self.fileName=fileName # In-memory representation of the log entries # (list of SvnLogEntry objects for instance) self.svnLogEntries=[] # If the file is not readable then throw an exception if not os.access(self.fileName, os.R_OK): raise Exception("SVN log file unreadable: self.fileName") print "Parsing",self.fileName+"...", self.parseFile(self.fileName) print "found",len(self.svnLogEntries),"log entries" # Invoke the twiki formatter self.twikiFormatter=TwikiChangeLog.TwikiChangeLog(self.svnLogEntries) def createChangeLog(self, outFile): """ Create the ChangeLog by delegating to the twiki formatter outFile: the file to write the twiki page into """ self.twikiFormatter.createTwikiPage(outFile) def createChangeLogByUser(self, outFile): """ Create the ChangeLog for each user by delegating to the twiki formatter outFile: the file to write the twiki page into """ self.twikiFormatter.changeByDeveloper(outFile) def cleanPath(self,fileName): ''' Clean the path by removing useless parts fileName: the original file name ''' return fileName.strip() def getText(self,nodelist): rc = [] for node in nodelist: if node.nodeType == node.TEXT_NODE: rc.append(node.data) return ''.join(rc) def parseFile(self,fileName): xmldoc = minidom.parse(fileName) itemlist = xmldoc.getElementsByTagName('logentry') for item in itemlist: revisionAttr=item.attributes["revision"] author = item.getElementsByTagName('author')[0] nodes=author.childNodes date = item.getElementsByTagName('date')[0] dateNodes=date.childNodes msg = item.getElementsByTagName('msg')[0] msgNodes=msg.childNodes #print "\tauthor",self.getText(nodes),"on",self.getText(dateNodes),"msg",self.getText(msgNodes),"revision",revisionAttr.nodeValue pathlist = item.getElementsByTagName('paths') paths=pathlist[0].getElementsByTagName('path') # The in-memory representation of the list of paths of a svn Log entry # (list of SvnLogPathEntry objects for instance) svnPaths=[] for path in paths: filePath=path.childNodes kindAttr=path.attributes["kind"] actionAttr=path.attributes["action"] #print "\t\t",self.getText(filePath),"kind",kindAttr.nodeValue,"action",actionAttr.nodeValue fileName=self.getText(filePath) svnPath=SvnLogEntry.SvnLogPathEntry(kindAttr.nodeValue,actionAttr.nodeValue,fileName) svnPaths.append(svnPath) svnLogEntry=SvnLogEntry.SvnLogEntry(revisionAttr.nodeValue,self.getText(nodes),self.getText(dateNodes),svnPaths,self.getText(msgNodes)) self.svnLogEntries.append(svnLogEntry)