[gsoc-admin] EventConfig: Allow regex to match name



commit 44ebe68d1d7c4cf05ec473510bc46bc97679c7c6
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date:   Wed Aug 12 17:59:30 2015 +0200

    EventConfig: Allow regex to match name

 data/config.cfg   |    3 ++-
 maillib/config.py |   22 +++++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/data/config.cfg b/data/config.cfg
index ac7c4f7..9623d71 100644
--- a/data/config.cfg
+++ b/data/config.cfg
@@ -1,6 +1,7 @@
 [GSoC_Dates]
 type = ics_source
-url = http://www.google.com/calendar/ical/gsummerofcode%%40gmail.com/public/basic.ics
+#url = http://www.google.com/calendar/ical/gsummerofcode%%40gmail.com/public/basic.ics
+path = basic.ics
 
 [GSoC_Students]
 type = csv_source
diff --git a/maillib/config.py b/maillib/config.py
index 03a7c30..8d671a8 100644
--- a/maillib/config.py
+++ b/maillib/config.py
@@ -6,7 +6,6 @@ import csv
 from ics import Calendar
 import re
 from urllib import request
-import sys
 
 from maillib.email import Contact, EmailTemplate
 
@@ -63,14 +62,19 @@ class EventConfig:
         regex = section['description_regex']
         if not regex.endswith('$'):
             regex += '$'
-        possible = list(filter(lambda ev:
-                               re.match(regex, ev.description) is not None,
-                               events))
-        assert len(possible) == 1, ("There are {num} possible events that "
-                                    "match the given regex '{regex}', only 1 "
-                                    "allowed.".format(num=len(possible),
-                                                      regex=regex))
-        self.dates[section.name] = possible[0]
+
+        compiled = re.compile(regex)
+        for event in events:
+            if (
+                    (event.description is not None and
+                     compiled.match(event.description) is not None) or
+                    (event.name is not None and
+                     compiled.match(event.name))):
+                self.dates[section.name] = event
+                return
+
+        raise AssertionError("There are no events matching the regular "
+                             "expression '{}'.".format(regex))
 
     def append_mail_from_section(self, section):
         text = get_main_data_from_section(section)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]