From 3219dea702997b1fccf80a1ba8d5c799ed3580d0 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Mon, 15 Dec 2008 16:20:41 -0600 Subject: Move the smarts for picking recipients. This should be done in the consumer, which will save a number of invocations of the producer and save the user time and the number of times that diffs need to be produced. --- README | 2 +- loginfo-consumer | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- loginfo-producer | 6 ------ 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/README b/README index 8bd859f..c021545 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ Really basic instructions: edit "loginfo" and add this line - ALL /path/to/loginfo-producer + ALL /path/to/loginfo-producer %{sVv} cvs ci -m "Add loginfo hook" diff --git a/loginfo-consumer b/loginfo-consumer index edab648..15ca8cd 100755 --- a/loginfo-consumer +++ b/loginfo-consumer @@ -65,8 +65,44 @@ def append_package_owner_email(directory, recipients): package_match = package_re.match(directory) if package_match and package_match.group(1): - recipients.append('%s-owner@fedoraproject.org' % package_match.group(1)) - + recipients.add('%s-owner@fedoraproject.org' % package_match.group(1)) + + +directory_based_notifications = [(re.compile(r'^rpms'), [append_package_owner_email, + 'cvsextras@fedoraproject.org']), + (re.compile(r'^devel'), [append_package_owner_email, + 'cvsextras@fedoraproject.org']), + (re.compile(r'^common'), ['cvsextras@fedoraproject.org', + 'jkeating@redhat.com']), + (re.compile(r'^owners'), ['cvsextras@fedoraproject.org', + 'cvsadmin-menbers@fedoraproject.org']), + (re.compile(r'^comps'), ['cvsextras@fedoraproject.org', + 'katzj@redhat.com', + 'notting@redhat.com', + 'jkeating@redhat.com'])] + +message_based_notifications = [(re.compile(r'docs'), ['relnotes@fedoraproject.org'])] + +def process_notifications(directory, message, recipients, notifications): + for notification in notifications: + if isinstance(notification, basestring): + recipients.add(notification) + elif callable(notification): + notification(directory, message, recipients) + +def compute_directory_based_notifications(directory, message, recipients): + for pattern, notifications in directory_based_notifications: + match = pattern.match(directory) + if match: + process_notifications(directory, message, recipients, notifications) + + +def compute_message_based_notifications(directory, message, email_recipient_set): + for pattern, notifications in message_based_notifications: + match = pattern.search(message) + if match: + process_notifications(directory, message, recipients, notifications) + host = '127.0.0.1' port = 5672 @@ -119,13 +155,15 @@ while True: # build the list of recipients - email_recipients = [] - for notification_element in root_element.xpath('/loginfo/notifications/notification'): - notification = notification_element.text - if notification == u'%%OWNER%%': - append_package_owner_email(directory, email_recipients) - else: - email_recipients.append(notification) + recipients = set() + compute_directory_based_notifications(directory, message, recipients) + compute_message_based_notifications(directory, message, recipients) + + if len(recipients) == 0: + recipients.add('admin@fedoraproject.org') + + email_recipients = list(recipients) + email_recipients.sort() # Build the email object diff --git a/loginfo-producer b/loginfo-producer index e4c6b8b..f927168 100755 --- a/loginfo-producer +++ b/loginfo-producer @@ -60,12 +60,6 @@ cvsroot = os.environ['CVSROOT'] cvsroot_element = etree.SubElement(root_element, 'cvsroot') cvsroot_element.text = cvsroot -notifications_element = etree.SubElement(root_element, 'notifications') - -for arg in sys.argv[2:]: - notification_element = etree.SubElement(notifications_element, 'notification') - notification_element.text = arg - directory_re = re.compile(r'^Update of %s/(.*)$' % (cvsroot,), re.M) message = sys.stdin.read().decode('utf-8') -- cgit