1.1 --- a/imiptools/content.py Tue Feb 03 23:16:13 2015 +0100
1.2 +++ b/imiptools/content.py Tue Feb 03 23:16:39 2015 +0100
1.3 @@ -26,11 +26,13 @@
1.4 from imiptools.data import Object, parse_object, \
1.5 get_address, get_uri, get_value, \
1.6 is_new_object, uri_dict, uri_item
1.7 -from imiptools.dates import *
1.8 -from imiptools.period import can_schedule, insert_period, remove_period
1.9 +from imiptools.dates import format_datetime, to_timezone
1.10 +from imiptools.period import can_schedule, insert_period, remove_period, \
1.11 + get_periods, remove_from_freebusy, \
1.12 + remove_from_freebusy_for_other, \
1.13 + update_freebusy, update_freebusy_for_other
1.14 from pytz import timezone
1.15 from socket import gethostname
1.16 -from vRecurrence import get_parameters, get_rule
1.17 import imip_store
1.18
1.19 try:
1.20 @@ -38,99 +40,6 @@
1.21 except ImportError:
1.22 from StringIO import StringIO
1.23
1.24 -# NOTE: Need to expose the 100 day window for recurring events in the
1.25 -# NOTE: configuration.
1.26 -
1.27 -def get_periods(obj, window_size=100):
1.28 -
1.29 - """
1.30 - Return periods for the given object 'obj', confining materialised periods
1.31 - to the given 'window_size' in days starting from the present moment.
1.32 - """
1.33 -
1.34 - dtstart = obj.get_utc_datetime("DTSTART")
1.35 - dtend = obj.get_utc_datetime("DTEND")
1.36 -
1.37 - # NOTE: Need also DURATION support.
1.38 -
1.39 - duration = dtend - dtstart
1.40 -
1.41 - # Recurrence rules create multiple instances to be checked.
1.42 - # Conflicts may only be assessed within a period defined by policy
1.43 - # for the agent, with instances outside that period being considered
1.44 - # unchecked.
1.45 -
1.46 - window_end = datetime.now() + timedelta(window_size)
1.47 -
1.48 - # NOTE: Need also RDATE and EXDATE support.
1.49 -
1.50 - rrule = obj.get_value("RRULE")
1.51 -
1.52 - if rrule:
1.53 - selector = get_rule(dtstart, rrule)
1.54 - parameters = get_parameters(rrule)
1.55 - periods = []
1.56 - for start in selector.materialise(dtstart, window_end, parameters.get("COUNT"), parameters.get("BYSETPOS")):
1.57 - start = datetime(*start, tzinfo=timezone("UTC"))
1.58 - end = start + duration
1.59 - periods.append((format_datetime(start), format_datetime(end)))
1.60 - else:
1.61 - periods = [(format_datetime(dtstart), format_datetime(dtend))]
1.62 -
1.63 - return periods
1.64 -
1.65 -def remove_from_freebusy(freebusy, attendee, uid, store):
1.66 -
1.67 - """
1.68 - For the given 'attendee', remove periods from 'freebusy' that are associated
1.69 - with 'uid' in the 'store'.
1.70 - """
1.71 -
1.72 - remove_period(freebusy, uid)
1.73 - store.set_freebusy(attendee, freebusy)
1.74 -
1.75 -def remove_from_freebusy_for_other(freebusy, user, other, uid, store):
1.76 -
1.77 - """
1.78 - For the given 'user', remove for the 'other' party periods from 'freebusy'
1.79 - that are associated with 'uid' in the 'store'.
1.80 - """
1.81 -
1.82 - remove_period(freebusy, uid)
1.83 - store.set_freebusy_for_other(user, freebusy, other)
1.84 -
1.85 -def _update_freebusy(freebusy, periods, transp, uid):
1.86 -
1.87 - """
1.88 - Update the free/busy details with the given 'periods', 'transp' setting and
1.89 - 'uid'.
1.90 - """
1.91 -
1.92 - remove_period(freebusy, uid)
1.93 -
1.94 - for start, end in periods:
1.95 - insert_period(freebusy, (start, end, uid, transp))
1.96 -
1.97 -def update_freebusy(freebusy, attendee, periods, transp, uid, store):
1.98 -
1.99 - """
1.100 - For the given 'attendee', update the free/busy details with the given
1.101 - 'periods', 'transp' setting and 'uid' in the 'store'.
1.102 - """
1.103 -
1.104 - _update_freebusy(freebusy, periods, transp, uid)
1.105 - store.set_freebusy(attendee, freebusy)
1.106 -
1.107 -def update_freebusy_for_other(freebusy, user, other, periods, transp, uid, store):
1.108 -
1.109 - """
1.110 - For the given 'user', update the free/busy details of 'other' with the given
1.111 - 'periods', 'transp' setting and 'uid' in the 'store'.
1.112 - """
1.113 -
1.114 - _update_freebusy(freebusy, periods, transp, uid)
1.115 - store.set_freebusy_for_other(user, freebusy, other)
1.116 -
1.117 # Handler mechanism objects.
1.118
1.119 def handle_itip_part(part, handlers):