All pastes #617050 Raw Edit

Unnamed

public python v1 · immutable
·published 2007-07-13 00:09 UTC
rendered paste body
import osfrom xml.dom import pulldomclass SvnLogParser:    def __init__(self, f):        self._events = pulldom.parse(f)    def __getitem__(self, idx):        for event, node in self._events:            if event == pulldom.START_ELEMENT and node.tagName == "logentry":                self._events.expandNode(node)                return self.SvnLogRevision(node)        raise IndexError    class SvnLogRevision:        def __init__(self, xmlnode):            self._node = xmlnode        def revision(self):            return self._node.getAttribute("revision")        def author(self):            return self._node.getElementsByTagName("author")[0].firstChild.data        def paths(self):            paths = []            for n in self._node.getElementsByTagName("path"):                paths.append(self.SvnLogPath(n))            return paths        class SvnLogPath:            def __init__(self, xmlnode):                self._node = xmlnode            def action(self):                return self._node.getAttribute("action")            def pathid(self):                return self._node.firstChild.data            def copyfrom_rev(self):                return self._node.getAttribute("copyfrom-rev")            def copyfrom_pathid(self):                return self._node.getAttribute("copyfrom-path")def svnlog(target):    return SvnLogParser(os.popen("svn log --xml -v %s" % target))if __name__ == "__main__":    URL = "http://svn.collab.net/repos/svn/trunk/contrib/client-side/svnmerge/svnmerge.py"    for chg in svnlog(URL):        print chg.revision(), chg.author()        for p in chg.paths():            print "   ", p.action(), p.pathid(), p.copyfrom_rev(), p.copyfrom_pathid()