From 7c3ef317df62dcc72cca739a5adfc364f8384771 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 9 Feb 2009 13:21:30 +0100 Subject: [PATCH] Parse "What's cooking" mails --- db.py | 11 +++++++++++ mail.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/db.py b/db.py index 5544a28..a6c527d 100644 --- a/db.py +++ b/db.py @@ -102,6 +102,17 @@ class Patch(DeclarativeBase): self.extra_notes = extra_notes +class Topic(DeclarativeBase): + __tablename__ = 'topics' + + id = Column(Integer, primary_key=True) + name = Column(String(255)) + mail_id = Column(Integer, ForeignKey('mails.id')) + cooking_notes = Column(Binary) + + mail = relation('Mail', backref='topic') + + DeclarativeBase.metadata.create_all(engine) if __name__ == '__main__': diff --git a/mail.py b/mail.py index 6efba2b..84cf8c2 100644 --- a/mail.py +++ b/mail.py @@ -136,6 +136,45 @@ def try_patch_anywhere(session, msg, m): return applied # all out of ideas! +_whats_cooking_subject = re.compile(r"^What's cooking in git\.git") +_whats_cooking_category = re.compile(r"^\[(.*)\]$") +_whats_cooking_header = re.compile(r"\* (../[a-zA-Z0-9-]) \([^)]*\) \d+ commits?") +_whats_cooking_separator = re.compile(r"^(-{5,}|-- )$") + +def parse_whats_cooking(session, msg, m): + if not _whats_cooking_subject.match(m["Subject"]): + return + category = None + branch = 'pu' # initial part goes on 'pu' + notes = [] + def _rotate_notes(): + if branch: + t = db.query(db.Topic).filter(db.Topic.name==branch).first() + if not t: + t = db.Topic() + t.name = branch + session.add(t) + t.mail_id = m.id + t.extra_notes = '\n'.join(notes) + notes = [] + if category: + notes.append(category) + for line in _get_text_payload(msg).splitlines(): + if _whats_cooking_separator.match(line): + category = None + _rotate_notes() + branch = None + continue + if _whats_cooking_category.match(line): + category = m.group(1) + _rotate_notes() + continue + if _whats_cooking_header.match(line): + _rotate_notes() + branch = m.group(1) + continue + notes.append(line) + def parse_mail(session, msg): if (session.query(db.Mail.message_id) .filter(db.Mail.message_id == _parse_msg_id(msg['Message-Id'])) @@ -153,9 +192,12 @@ def parse_mail(session, msg): if msg['References']: for im in _msg_id_regex.finditer(' '.join(msg.get_all('References'))): references.append((m, im.group(1))) + # try patching patch = try_patch_anywhere(session, msg, m) if patch: m.patch_id = patch.commit.patch_id + # try reading a what's cooking message + parse_whats_cooking(session, msg, m) session.commit() return references -- 2.11.4.GIT