From f2f98285ef3cc62b33e42c9096380762369bf941 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Tue, 1 Aug 2017 10:36:05 -0600 Subject: [PATCH] Add Adhoc frequency For the irc-meetings we would like to list the possiblity of a meeting but not actually formally schedule it. This change allows for an AdHoc meeting which is essentially a noop in the ical generation Change-Id: I843b5b3f2a6e5a74b85b13b86c8d16125a1ac7c7 --- yaml2ical/ical.py | 5 +++++ yaml2ical/recurrence.py | 24 ++++++++++++++++++++++++ yaml2ical/tests/sample_data.py | 14 ++++++++++++++ yaml2ical/tests/test_meeting.py | 7 +++++++ yaml2ical/tests/test_recurrence.py | 5 +++++ 5 files changed, 55 insertions(+) diff --git a/yaml2ical/ical.py b/yaml2ical/ical.py index e2c9fab..ea6f969 100644 --- a/yaml2ical/ical.py +++ b/yaml2ical/ical.py @@ -81,6 +81,11 @@ class Yaml2IcalCalendar(icalendar.Calendar): # get starting date next_meeting = sch.recurrence.next_occurence(sch.start_date, sch.day) + # NOTE(aschultz): to handle adhoc meetings, we check to make + # sure there is a next meeting before trying to add it to the + # the calendar + if next_meeting is None: + return next_meeting_date = datetime.datetime(next_meeting.year, next_meeting.month, next_meeting.day, diff --git a/yaml2ical/recurrence.py b/yaml2ical/recurrence.py index 9c02c2d..a3cbc01 100644 --- a/yaml2ical/recurrence.py +++ b/yaml2ical/recurrence.py @@ -78,8 +78,32 @@ class BiWeeklyRecurrence(object): return "Every two weeks (on %s weeks)" % self.style +class AdhocRecurrence(object): + """Meetings occuring as needed. + + Effectively this is a noop recurrance as next_occurance is always None + """ + def __init__(self): + pass + + def next_occurence(self, current_date, day): + """Calculate the next adhoc meeting. + + :param current_date: the current date + :param day: scheduled day of the meeting + :returns: datetime object of next meeting + """ + return None + + def rrule(self): + return {'freq': 'adhoc', 'interval': 0} + + def __str__(self): + return "Occurs as needed, no fixed schedule." + supported_recurrences = { 'weekly': WeeklyRecurrence(), 'biweekly-odd': BiWeeklyRecurrence(style='odd'), 'biweekly-even': BiWeeklyRecurrence(), + 'adhoc': AdhocRecurrence(), } diff --git a/yaml2ical/tests/sample_data.py b/yaml2ical/tests/sample_data.py index 4985dea..9218046 100644 --- a/yaml2ical/tests/sample_data.py +++ b/yaml2ical/tests/sample_data.py @@ -258,3 +258,17 @@ chair: Shannon Stacker description: > Weekly short meeting for Subteam project. """ + +# adhoc meeting +ADHOC_MEETING = """ +project: OpenStack Random Meeting +schedule: + - time: '1200' + day: Monday + start_date: 20150801 + irc: openstack-meeting + frequency: adhoc +chair: Shannon Stacker +description: > + Adhoc random meeting for Subteam project. +""" diff --git a/yaml2ical/tests/test_meeting.py b/yaml2ical/tests/test_meeting.py index 8b9820b..2651341 100644 --- a/yaml2ical/tests/test_meeting.py +++ b/yaml2ical/tests/test_meeting.py @@ -116,6 +116,13 @@ class MeetingTestCase(unittest.TestCase): for p in patterns: self.assertNotEqual(None, p.match(cal_str)) + def test_adhoc_meeting(self): + meeting_yaml = sample_data.ADHOC_MEETING + m = meeting.load_meetings(meeting_yaml)[0] + cal = ical.Yaml2IcalCalendar() + cal.add_meeting(m) + self.assertEqual(cal, ical.Yaml2IcalCalendar()) + def test_skip_meeting_missing_skip_date(self): self.assertRaises(KeyError, meeting.load_meetings, diff --git a/yaml2ical/tests/test_recurrence.py b/yaml2ical/tests/test_recurrence.py index a4e3957..afbc74f 100644 --- a/yaml2ical/tests/test_recurrence.py +++ b/yaml2ical/tests/test_recurrence.py @@ -37,3 +37,8 @@ class RecurrenceTestCase(unittest.TestCase): self.assertEqual( datetime.datetime(2014, 10, 15, 2, 47, 28, 832666), self.next_meeting(recurrence.BiWeeklyRecurrence(style='even'))) + + def test_next_adhoc(self): + self.assertEqual( + None, + self.next_meeting(recurrence.AdhocRecurrence()))