2 from xml.sax import saxutils
3 from xml.sax import make_parser
5 # from pprint import pprint
7 class CommitParserHandler(saxutils.DefaultHandler):
18 def startElement(self, name, attrs):
19 if name == "revision":
32 def characters(self, data):
33 if self.inRevision == 1 or self.inAuthor == 1 or self.inLog == 1 or self.inFile == 1:
36 def endElement(self, name):
37 if name == "revision":
39 self.revision = self.buffer
42 self.author = self.buffer
45 self.logmessage = self.buffer
48 self.filelist.append(self.buffer)
63 parser = make_parser( )
64 handler = CommitParserHandler( )
65 parser.setContentHandler(handler)
66 parser.parse(self.filename)
68 # Let's find out what dirs were touched
69 filelist = handler.filelist
81 while i < maxi and ok == 1:
82 search = filelist[i].find("/")
84 #okay, we have a fil in the "top" dir let's stop it
88 # we have a subdir in here, so count ;)
92 if ok == 1 and multidir == 0:
93 if subdirlinecount == maxi:
94 #okay all dirs still have a slash
95 # everything in the same dir?
101 if dir.find("/") > -1:
102 if dir[:dir.find("/")+1] != lastdir:
104 lastdir = dir[:dir.find("/")+1]
106 if subdirlinecount == 1:
107 # okay, all lines have the same slashpos.
108 # strip everything up to it
110 path += filelist[0][:search+1]
112 filelist[i] = filelist[i][search+1:]
115 for line in filelist:
119 #no we seem to have the topdir now..
120 dircount = subdirlinecount
130 if dir.find("/") > -1:
131 if dir[:dir.find("/")+1] != lastdir:
133 lastdir = dir[:dir.find("/")+1]
136 self.author = handler.author
137 self.revision = handler.revision
138 self.logmessage = handler.logmessage
139 self.dircount = dircount
140 self.filecount = filecount
141 self.filelist = filelist
143 def generate_pathline(self):
145 if self.filecount == 1 and self.dircount == 0:
146 self.pathline = self.path + filelist[0]
147 if (self.filecount > 1 or self.filecount < 4) and self.dircount == 0:
148 self.pathline = self.path + " ("
149 for file in self.filelist:
150 self.pathline += file + " "
151 self.pathline = self.pathline[:-1] + ")"
152 if self.filecount >= 1 and self.dircount >= 1 and self.filecount+self.dircount < 4:
153 self.pathline = self.path + " ("
154 for file in self.filelist:
155 self.pathline += file + " "
156 self.pathline = self.pathline[:-1] + ")"
157 if self.filecount >= 1 and self.dircount >= 1 and self.filecount+self.dircount >= 4:
158 self.pathline = self.path + " ("
159 if self.filecount == 1:
160 self.pathline += "1 file"
161 if self.filecount > 1:
162 self.pathline += "%i files" % self.filecount
163 if self.dircount == 1:
164 self.pathline += " in 2 dirs"
165 if self.dircount > 1:
166 self.pathline += " in %i dirs" % (self.dircount)
171 self.generate_pathline()