[Zope3-checkins] CVS: Products3/z3checkins - message.py:1.33
Marius Gedminas
marius at pov.lt
Thu Mar 18 12:48:29 EST 2004
Update of /cvs-repository/Products3/z3checkins
In directory cvs.zope.org:/tmp/cvs-serv31357
Modified Files:
message.py
Log Message:
Catch up with Zope 3 package removals.
Refactor the message parsing a bit to make it somewhat less ugly.
=== Products3/z3checkins/message.py 1.32 => 1.33 ===
--- Products3/z3checkins/message.py:1.32 Sun Mar 14 05:56:48 2004
+++ Products3/z3checkins/message.py Thu Mar 18 12:48:29 2004
@@ -15,7 +15,7 @@
from datetime import datetime, tzinfo, timedelta
from persistence import Persistent
-from zope.app.form.browser.widget import FileWidget
+from zope.app.form.browser.textwidgets import FileWidget
from zope.app.container.interfaces import IReadContainer
from zope.app.datetimeutils import parseDatetimetz, DateTimeError
from zope.app.form.widget import CustomWidgetFactory
@@ -119,7 +119,7 @@
"""Persistent email message."""
implements(IMessage, IMessageContained)
-
+
__parent__ = __name__ = None
def __init__(self, message_id=None, author_name=None,
@@ -172,6 +172,8 @@
implements(IMessageParser)
def parse(self, input):
+ """See IMessageParser."""
+
if not hasattr(input, 'readline'):
full_text = str(input)
input = StringIO(full_text)
@@ -210,44 +212,53 @@
date = datetime(year, month, day, hours, minutes, seconds,
tzinfo=FixedTimezone(tzoffset / 60))
- try:
- if not (subject.startswith("Re:") or
- subject.find("CVS:") == -1
- and subject.find("rev ") == -1):
-
- if subject.find("CVS:") != -1:
- parts = subject.split("CVS: ", 1)
- if len(parts) < 2:
- raise FormatError()
- subject = parts[1]
- directory = subject.split(' - ')[0]
- elif subject.find("rev ") != -1:
- parts = subject.split(' - ')
- if len(parts) < 2:
- raise FormatError()
- directory = parts[1]
-
- m.rewindbody()
- body_lines = input.readlines()
- # this might throw a FormatError on its own as well
- log_message, branch = self.extract_log(body_lines)
- return CheckinMessage(
- message_id=message_id,
- author_name=author_name,
- author_email=author_email, subject=subject,
- date=date, full_text=full_text,
- directory=directory, log_message=log_message,
- branch=branch)
-
- except FormatError:
- # fall back to adding a simple message
- pass
+ checkin_info = self.tryToParseCheckinMessage(subject, m, input)
+ if checkin_info is not None:
+ directory, log_message, branch = checkin_info
+ return CheckinMessage(message_id=message_id,
+ author_name=author_name,
+ author_email=author_email, subject=subject,
+ date=date, full_text=full_text,
+ directory=directory, log_message=log_message,
+ branch=branch)
return Message(message_id=message_id,
author_name=author_name,
author_email=author_email, subject=subject,
date=date, full_text=full_text)
+ def tryToParseCheckinMessage(self, subject, msg, input):
+ """Detect and parse CVS/Subversion checkin messages.
+
+ Returns a tuple (directory, log_message, branch) for checkin
+ messages, and None if message is not a checkin message.
+ """
+
+ if subject.startswith("Re:"):
+ return None
+
+ if "CVS:" in subject:
+ parts = subject.split("CVS: ", 1)
+ if len(parts) < 2:
+ return None
+ subject = parts[1]
+ directory = subject.split(' - ')[0]
+ elif "rev " in subject:
+ parts = subject.split(' - ')
+ if len(parts) < 2:
+ return None
+ directory = parts[1]
+ else:
+ return None
+
+ msg.rewindbody()
+ body_lines = input.readlines()
+ try:
+ log_message, branch = self.extract_log(body_lines)
+ except FormatError:
+ return None
+
+ return directory, log_message, branch
def extract_log(self, lines):
log_message = []
More information about the Zope3-Checkins
mailing list