def parse_mediawiki_xml(file_handle): """ Read messages from ``mediawiki.xml`` """ doc = etree.parse(file_handle) root = doc.getroot() ns = "{http://www.mediawiki.org/xml/export-0.4/}" if root.tag != ns + "mediawiki": raise Exception("Root tag of svn-log.xml must be <mediawiki>") for page in root.iter(ns + "page"): for title in page.iter(ns + "title"): path_ = unicodeanyway(title.text).encode("trans") break action_ = "A" for revision in page.iter(ns + "revision"): for contributor in revision.iter(ns + "contributor"): for username in contributor.iter(ns + "username"): author_ = username.text break break for timestamp in revision.iter(ns + "timestamp"): date_ = timestamp.text date_ = time.strptime(date_, "%Y-%m-%dT%H:%M:%SZ") date_ = int(time.mktime(date_)) * 1000 break comment_ = "" for comment in revision.iter(ns + "comment"): comment_ = unicodeanyway(comment.text).encode("utf8") if action_ == "A": comment_ = unicodeanyway(title.text).encode("utf8") break event_list.append(Event(path_, date_, author_, action=action_, comment=comment_)) action_ = "M"
def __init__(self, filename, date, author, action="M", comment=""): self.filename = unicodeanyway(filename) self.date = date # time in milliseconds self.action = textfilter(action) self.author = textfilter(author) self.filename = textfilter(self.filename) self.comment = textfilter(comment)
def textfilter(text): """ Kill emplylines, newlines, convert quotes, convert to unicode. """ text = unicodeanyway(text) if type(text) != type(u""): return u"" text = re.sub('^\n', '', text) text = text.replace("\n", ". ").replace('''"''', """'""") return text
def textfilter(text): """ Kill emplylines, newlines, convert quotes, convert to unicode. """ text = unicodeanyway(text) if type(text) != type(u""): return u"" text = re.sub("^\n", "", text) text = text.replace("\n", ". ").replace('''"''', """'""") return text
def write_gource_custom(self, filepath): """ Write out the file in «Gource Custom format» with team events """ lf = open(filepath, 'w') self.events.sort() for event in self.events: ev = copy(event) ev.date = long(ev.date) / 1000 ev.filename = unicodeanyway(ev.filename) s = u"%(date)s|%(author)s|%(action)s|%(filename)s|\n" % vars(ev) lf.write(s.encode("trans")) lf.close()
def write_gource_custom(self, filepath): """ Write out the file in «Gource Custom format» with team events """ lf = open(filepath, "w") self.events.sort() for event in self.events: ev = copy(event) ev.date = long(ev.date) / 1000 ev.filename = unicodeanyway(ev.filename) s = u"%(date)s|%(author)s|%(action)s|%(filename)s|\n" % vars(ev) lf.write(s.encode("trans")) lf.close()
def parse_mediawiki_xml(file_handle): """ Read messages from ``mediawiki.xml`` """ doc = etree.parse(file_handle) root = doc.getroot() ns = "{http://www.mediawiki.org/xml/export-0.4/}" if root.tag != ns + "mediawiki": raise Exception("Root tag of svn-log.xml must be <mediawiki>") for page in root.iter(ns + "page"): for title in page.iter(ns + "title"): path_ = unicodeanyway(title.text).encode("trans") break action_ = 'A' for revision in page.iter(ns + "revision"): for contributor in revision.iter(ns + "contributor"): for username in contributor.iter(ns + "username"): author_ = username.text break break for timestamp in revision.iter(ns + "timestamp"): date_ = timestamp.text date_ = time.strptime(date_, '%Y-%m-%dT%H:%M:%SZ') date_ = int(time.mktime(date_)) * 1000 break comment_ = "" for comment in revision.iter(ns + "comment"): comment_ = unicodeanyway(comment.text).encode("utf8") if action_ == 'A': comment_ = unicodeanyway(title.text).encode("utf8") break event_list.append( Event(path_, date_, author_, action=action_, comment=comment_)) action_ = 'M'