paul@48 | 1 | #!/usr/bin/env python |
paul@48 | 2 | |
paul@146 | 3 | """ |
paul@146 | 4 | Managing and presenting periods of time. |
paul@146 | 5 | |
paul@146 | 6 | Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> |
paul@146 | 7 | |
paul@146 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@146 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@146 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@146 | 11 | version. |
paul@146 | 12 | |
paul@146 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@146 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@146 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@146 | 16 | details. |
paul@146 | 17 | |
paul@146 | 18 | You should have received a copy of the GNU General Public License along with |
paul@146 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@146 | 20 | """ |
paul@146 | 21 | |
paul@430 | 22 | from bisect import bisect_left, bisect_right, insort_left |
paul@279 | 23 | from datetime import datetime, timedelta |
paul@256 | 24 | from imiptools.dates import get_datetime, get_start_of_day, to_timezone |
paul@48 | 25 | |
paul@291 | 26 | # Time management with datetime strings in the UTC time zone. |
paul@48 | 27 | |
paul@343 | 28 | def can_schedule(freebusy, periods, uid, recurrenceid): |
paul@221 | 29 | |
paul@221 | 30 | """ |
paul@221 | 31 | Return whether the 'freebusy' list can accommodate the given 'periods' |
paul@343 | 32 | employing the specified 'uid' and 'recurrenceid'. |
paul@221 | 33 | """ |
paul@221 | 34 | |
paul@221 | 35 | for conflict in have_conflict(freebusy, periods, True): |
paul@395 | 36 | start, end, found_uid, found_transp, found_recurrenceid = conflict[:5] |
paul@343 | 37 | if found_uid != uid and found_recurrenceid != recurrenceid: |
paul@221 | 38 | return False |
paul@221 | 39 | |
paul@221 | 40 | return True |
paul@221 | 41 | |
paul@72 | 42 | def have_conflict(freebusy, periods, get_conflicts=False): |
paul@72 | 43 | |
paul@72 | 44 | """ |
paul@72 | 45 | Return whether any period in 'freebusy' overlaps with the given 'periods', |
paul@72 | 46 | returning a collection of such overlapping periods if 'get_conflicts' is |
paul@72 | 47 | set to a true value. |
paul@72 | 48 | """ |
paul@72 | 49 | |
paul@72 | 50 | conflicts = [] |
paul@72 | 51 | for start, end in periods: |
paul@74 | 52 | overlapping = period_overlaps(freebusy, (start, end), get_conflicts) |
paul@74 | 53 | if overlapping: |
paul@72 | 54 | if get_conflicts: |
paul@74 | 55 | conflicts += overlapping |
paul@72 | 56 | else: |
paul@72 | 57 | return True |
paul@74 | 58 | |
paul@72 | 59 | if get_conflicts: |
paul@72 | 60 | return conflicts |
paul@72 | 61 | else: |
paul@72 | 62 | return False |
paul@72 | 63 | |
paul@48 | 64 | def insert_period(freebusy, period): |
paul@362 | 65 | |
paul@362 | 66 | "Insert into 'freebusy' the given 'period'." |
paul@362 | 67 | |
paul@48 | 68 | insort_left(freebusy, period) |
paul@48 | 69 | |
paul@343 | 70 | def remove_period(freebusy, uid, recurrenceid=None): |
paul@362 | 71 | |
paul@362 | 72 | """ |
paul@362 | 73 | Remove from 'freebusy' all periods associated with 'uid' and 'recurrenceid' |
paul@362 | 74 | (which if omitted causes the "parent" object's periods to be referenced). |
paul@362 | 75 | """ |
paul@362 | 76 | |
paul@48 | 77 | i = 0 |
paul@48 | 78 | while i < len(freebusy): |
paul@48 | 79 | t = freebusy[i] |
paul@343 | 80 | if len(t) >= 5 and t[2] == uid and t[4] == recurrenceid: |
paul@48 | 81 | del freebusy[i] |
paul@48 | 82 | else: |
paul@48 | 83 | i += 1 |
paul@48 | 84 | |
paul@382 | 85 | def remove_additional_periods(freebusy, uid, recurrenceids=None): |
paul@381 | 86 | |
paul@381 | 87 | """ |
paul@381 | 88 | Remove from 'freebusy' all periods associated with 'uid' having a |
paul@381 | 89 | recurrence identifier indicating an additional or modified period. |
paul@382 | 90 | |
paul@382 | 91 | If 'recurrenceids' is specified, remove all periods associated with 'uid' |
paul@382 | 92 | that do not have a recurrence identifier in the given list. |
paul@381 | 93 | """ |
paul@381 | 94 | |
paul@381 | 95 | i = 0 |
paul@381 | 96 | while i < len(freebusy): |
paul@381 | 97 | t = freebusy[i] |
paul@382 | 98 | if len(t) >= 5 and t[2] == uid and t[4] and ( |
paul@382 | 99 | recurrenceids is None or |
paul@382 | 100 | recurrenceids is not None and t[4] not in recurrenceids |
paul@382 | 101 | ): |
paul@381 | 102 | del freebusy[i] |
paul@381 | 103 | else: |
paul@381 | 104 | i += 1 |
paul@381 | 105 | |
paul@361 | 106 | def remove_affected_period(freebusy, uid, recurrenceid): |
paul@362 | 107 | |
paul@362 | 108 | """ |
paul@362 | 109 | Remove from 'freebusy' a period associated with 'uid' that provides an |
paul@362 | 110 | occurrence starting at the given 'recurrenceid', where the recurrence |
paul@362 | 111 | identifier is used to provide an alternative time period whilst also acting |
paul@362 | 112 | as a reference to the originally-defined occurrence. |
paul@362 | 113 | """ |
paul@362 | 114 | |
paul@361 | 115 | found = bisect_left(freebusy, (recurrenceid,)) |
paul@376 | 116 | while found < len(freebusy): |
paul@361 | 117 | start, end, _uid, transp, _recurrenceid = freebusy[found][:5] |
paul@376 | 118 | |
paul@376 | 119 | # Stop looking if the start no longer matches the recurrence identifier. |
paul@376 | 120 | |
paul@376 | 121 | if start != recurrenceid: |
paul@376 | 122 | return |
paul@376 | 123 | |
paul@376 | 124 | # If the period belongs to the parent object, remove it and return. |
paul@376 | 125 | |
paul@376 | 126 | if not _recurrenceid and uid == _uid: |
paul@361 | 127 | del freebusy[found] |
paul@376 | 128 | break |
paul@376 | 129 | |
paul@376 | 130 | # Otherwise, keep looking for a matching period. |
paul@376 | 131 | |
paul@376 | 132 | found += 1 |
paul@361 | 133 | |
paul@327 | 134 | def get_overlapping(freebusy, period): |
paul@327 | 135 | |
paul@327 | 136 | """ |
paul@430 | 137 | Return the entries in 'freebusy' providing periods overlapping with |
paul@327 | 138 | 'period'. |
paul@327 | 139 | """ |
paul@327 | 140 | |
paul@327 | 141 | dtstart, dtend = period[:2] |
paul@327 | 142 | |
paul@430 | 143 | # Find the range of periods potentially overlapping the period in the |
paul@430 | 144 | # free/busy collection. |
paul@327 | 145 | |
paul@430 | 146 | last = bisect_right(freebusy, (dtend,)) |
paul@430 | 147 | startpoints = freebusy[:last] |
paul@327 | 148 | |
paul@430 | 149 | # Find the range of periods potentially overlapping the period in a version |
paul@430 | 150 | # of the free/busy collection sorted according to end datetimes. |
paul@327 | 151 | |
paul@430 | 152 | endpoints = [((fb[1], fb[0]) + fb[2:]) for fb in startpoints] |
paul@430 | 153 | endpoints.sort() |
paul@430 | 154 | first = bisect_left(endpoints, (dtstart,)) |
paul@430 | 155 | endpoints = endpoints[first:] |
paul@327 | 156 | |
paul@430 | 157 | overlapping = set() |
paul@327 | 158 | |
paul@430 | 159 | for fb in endpoints: |
paul@430 | 160 | end, start = fb[:2] |
paul@430 | 161 | if end > dtstart and start < dtend: |
paul@430 | 162 | overlapping.add((start, end) + fb[2:]) |
paul@327 | 163 | |
paul@430 | 164 | overlapping = list(overlapping) |
paul@430 | 165 | overlapping.sort() |
paul@430 | 166 | return overlapping |
paul@327 | 167 | |
paul@74 | 168 | def period_overlaps(freebusy, period, get_periods=False): |
paul@72 | 169 | |
paul@72 | 170 | """ |
paul@74 | 171 | Return whether any period in 'freebusy' overlaps with the given 'period', |
paul@74 | 172 | returning a collection of overlapping periods if 'get_periods' is set to a |
paul@74 | 173 | true value. |
paul@72 | 174 | """ |
paul@72 | 175 | |
paul@430 | 176 | overlapping = get_overlapping(freebusy, period) |
paul@74 | 177 | |
paul@74 | 178 | if get_periods: |
paul@430 | 179 | return overlapping |
paul@74 | 180 | else: |
paul@430 | 181 | return len(overlapping) != 0 |
paul@327 | 182 | |
paul@327 | 183 | def remove_overlapping(freebusy, period): |
paul@327 | 184 | |
paul@327 | 185 | "Remove from 'freebusy' all periods overlapping with 'period'." |
paul@327 | 186 | |
paul@437 | 187 | overlapping = get_overlapping(freebusy, period) |
paul@327 | 188 | |
paul@437 | 189 | if overlapping: |
paul@437 | 190 | for fb in overlapping: |
paul@437 | 191 | freebusy.remove(fb) |
paul@327 | 192 | |
paul@327 | 193 | def replace_overlapping(freebusy, period, replacements): |
paul@327 | 194 | |
paul@327 | 195 | """ |
paul@327 | 196 | Replace existing periods in 'freebusy' within the given 'period', using the |
paul@327 | 197 | given 'replacements'. |
paul@327 | 198 | """ |
paul@327 | 199 | |
paul@327 | 200 | remove_overlapping(freebusy, period) |
paul@327 | 201 | for replacement in replacements: |
paul@327 | 202 | insert_period(freebusy, replacement) |
paul@48 | 203 | |
paul@240 | 204 | # Period layout mostly with datetime objects. |
paul@113 | 205 | |
paul@162 | 206 | def convert_periods(periods, tzid): |
paul@162 | 207 | |
paul@162 | 208 | "Convert 'periods' to use datetime objects employing the given 'tzid'." |
paul@162 | 209 | |
paul@162 | 210 | l = [] |
paul@162 | 211 | |
paul@162 | 212 | for t in periods: |
paul@162 | 213 | start, end = t[:2] |
paul@204 | 214 | |
paul@204 | 215 | # NOTE: This only really works if the datetimes are UTC already. |
paul@232 | 216 | # NOTE: Since the periods should originate from the free/busy data, |
paul@232 | 217 | # NOTE: and since that data should employ UTC times, this should not be |
paul@232 | 218 | # NOTE: an immediate problem. |
paul@204 | 219 | |
paul@232 | 220 | start = get_datetime(start) |
paul@232 | 221 | end = get_datetime(end) |
paul@232 | 222 | |
paul@232 | 223 | start = isinstance(start, datetime) and to_timezone(start, tzid) or get_start_of_day(start, tzid) |
paul@232 | 224 | end = isinstance(end, datetime) and to_timezone(end, tzid) or get_start_of_day(end, tzid) |
paul@232 | 225 | |
paul@162 | 226 | l.append((start, end) + tuple(t[2:])) |
paul@162 | 227 | |
paul@162 | 228 | return l |
paul@162 | 229 | |
paul@162 | 230 | def get_scale(periods): |
paul@113 | 231 | |
paul@113 | 232 | """ |
paul@162 | 233 | Return an ordered time scale from the given list 'periods', with the first |
paul@162 | 234 | two elements of each tuple being start and end times. |
paul@153 | 235 | |
paul@162 | 236 | The given 'tzid' is used to make sure that the times are defined according |
paul@162 | 237 | to the chosen time zone. |
paul@162 | 238 | |
paul@162 | 239 | The returned scale is a mapping from time to (starting, ending) tuples, |
paul@162 | 240 | where starting and ending are collections of tuples from 'periods'. |
paul@113 | 241 | """ |
paul@113 | 242 | |
paul@113 | 243 | scale = {} |
paul@113 | 244 | |
paul@162 | 245 | for t in periods: |
paul@113 | 246 | start, end = t[:2] |
paul@113 | 247 | |
paul@113 | 248 | # Add a point and this event to the starting list. |
paul@113 | 249 | |
paul@113 | 250 | if not scale.has_key(start): |
paul@113 | 251 | scale[start] = [], [] |
paul@113 | 252 | scale[start][0].append(t) |
paul@113 | 253 | |
paul@113 | 254 | # Add a point and this event to the ending list. |
paul@113 | 255 | |
paul@113 | 256 | if not scale.has_key(end): |
paul@113 | 257 | scale[end] = [], [] |
paul@113 | 258 | scale[end][1].append(t) |
paul@113 | 259 | |
paul@113 | 260 | return scale |
paul@113 | 261 | |
paul@455 | 262 | class Point: |
paul@455 | 263 | |
paul@455 | 264 | "A qualified point in time." |
paul@455 | 265 | |
paul@455 | 266 | PRINCIPAL, REPEATED = 0, 1 |
paul@455 | 267 | |
paul@455 | 268 | def __init__(self, point, indicator=None): |
paul@455 | 269 | self.point = point |
paul@455 | 270 | self.indicator = indicator or self.PRINCIPAL |
paul@455 | 271 | |
paul@455 | 272 | def __hash__(self): |
paul@455 | 273 | return hash((self.point, self.indicator)) |
paul@455 | 274 | |
paul@455 | 275 | def __cmp__(self, other): |
paul@455 | 276 | if isinstance(other, Point): |
paul@455 | 277 | return cmp((self.point, self.indicator), (other.point, other.indicator)) |
paul@455 | 278 | elif isinstance(other, datetime): |
paul@455 | 279 | return cmp(self.point, other) |
paul@455 | 280 | else: |
paul@455 | 281 | return 1 |
paul@455 | 282 | |
paul@455 | 283 | def __eq__(self, other): |
paul@455 | 284 | return self.__cmp__(other) == 0 |
paul@455 | 285 | |
paul@455 | 286 | def __ne__(self, other): |
paul@455 | 287 | return not self == other |
paul@455 | 288 | |
paul@455 | 289 | def __lt__(self, other): |
paul@455 | 290 | return self.__cmp__(other) < 0 |
paul@455 | 291 | |
paul@455 | 292 | def __le__(self, other): |
paul@455 | 293 | return self.__cmp__(other) <= 0 |
paul@455 | 294 | |
paul@455 | 295 | def __gt__(self, other): |
paul@455 | 296 | return not self <= other |
paul@455 | 297 | |
paul@455 | 298 | def __ge__(self, other): |
paul@455 | 299 | return not self < other |
paul@455 | 300 | |
paul@455 | 301 | def __repr__(self): |
paul@455 | 302 | return "Point(%r, Point.%s)" % (self.point, self.indicator and "REPEATED" or "PRINCIPAL") |
paul@452 | 303 | |
paul@162 | 304 | def get_slots(scale): |
paul@113 | 305 | |
paul@113 | 306 | """ |
paul@162 | 307 | Return an ordered list of time slots from the given 'scale'. |
paul@113 | 308 | |
paul@452 | 309 | Each slot is a tuple containing details of a point in time for the start of |
paul@452 | 310 | the slot, together with a list of parallel event tuples, each tuple |
paul@452 | 311 | containing the original details of an event. |
paul@452 | 312 | |
paul@455 | 313 | Each point in time is described as a Point representing the actual point in |
paul@455 | 314 | time together with an indicator of the nature of the point in time (as a |
paul@455 | 315 | principal point in a time scale or as a repeated point used to terminate |
paul@455 | 316 | events occurring for an instant in time). |
paul@113 | 317 | """ |
paul@113 | 318 | |
paul@113 | 319 | slots = [] |
paul@113 | 320 | active = [] |
paul@113 | 321 | |
paul@162 | 322 | points = scale.items() |
paul@162 | 323 | points.sort() |
paul@162 | 324 | |
paul@162 | 325 | for point, (starting, ending) in points: |
paul@449 | 326 | ending = set(ending) |
paul@449 | 327 | instants = ending.intersection(starting) |
paul@113 | 328 | |
paul@113 | 329 | # Discard all active events ending at or before this start time. |
paul@161 | 330 | # Free up the position in the active list. |
paul@113 | 331 | |
paul@449 | 332 | for t in ending.difference(instants): |
paul@113 | 333 | i = active.index(t) |
paul@113 | 334 | active[i] = None |
paul@113 | 335 | |
paul@161 | 336 | # For each event starting at the current point, fill any newly-vacated |
paul@161 | 337 | # position or add to the end of the active list. |
paul@161 | 338 | |
paul@113 | 339 | for t in starting: |
paul@113 | 340 | try: |
paul@113 | 341 | i = active.index(None) |
paul@113 | 342 | active[i] = t |
paul@113 | 343 | except ValueError: |
paul@113 | 344 | active.append(t) |
paul@113 | 345 | |
paul@161 | 346 | # Discard vacant positions from the end of the active list. |
paul@161 | 347 | |
paul@113 | 348 | while active and active[-1] is None: |
paul@113 | 349 | active.pop() |
paul@113 | 350 | |
paul@452 | 351 | # Add an entry for the time point before "instants". |
paul@452 | 352 | |
paul@455 | 353 | slots.append((Point(point), active[:])) |
paul@113 | 354 | |
paul@449 | 355 | # Discard events ending at the same time as they began. |
paul@449 | 356 | |
paul@449 | 357 | if instants: |
paul@449 | 358 | for t in instants: |
paul@449 | 359 | i = active.index(t) |
paul@449 | 360 | active[i] = None |
paul@449 | 361 | |
paul@449 | 362 | # Discard vacant positions from the end of the active list. |
paul@449 | 363 | |
paul@449 | 364 | while active and active[-1] is None: |
paul@449 | 365 | active.pop() |
paul@449 | 366 | |
paul@452 | 367 | # Add another entry for the time point after "instants". |
paul@449 | 368 | |
paul@455 | 369 | slots.append((Point(point, Point.REPEATED), active[:])) |
paul@449 | 370 | |
paul@113 | 371 | return slots |
paul@113 | 372 | |
paul@244 | 373 | def add_day_start_points(slots, tzid): |
paul@153 | 374 | |
paul@153 | 375 | """ |
paul@162 | 376 | Introduce into the 'slots' any day start points required by multi-day |
paul@244 | 377 | periods. The 'tzid' is required to make sure that appropriate time zones |
paul@244 | 378 | are chosen and not necessarily those provided by the existing time points. |
paul@153 | 379 | """ |
paul@153 | 380 | |
paul@162 | 381 | new_slots = [] |
paul@153 | 382 | current_date = None |
paul@200 | 383 | previously_active = [] |
paul@153 | 384 | |
paul@455 | 385 | for point, active in slots: |
paul@455 | 386 | start_of_day = get_start_of_day(point.point, tzid) |
paul@455 | 387 | this_date = point.point.date() |
paul@153 | 388 | |
paul@198 | 389 | # For each new day, add a slot for the start of the day where periods |
paul@198 | 390 | # are active and where no such slot already exists. |
paul@153 | 391 | |
paul@153 | 392 | if this_date != current_date: |
paul@414 | 393 | |
paul@414 | 394 | # Fill in days where events remain active. |
paul@414 | 395 | |
paul@414 | 396 | if current_date: |
paul@414 | 397 | current_date += timedelta(1) |
paul@414 | 398 | while current_date < this_date: |
paul@455 | 399 | new_slots.append((Point(get_start_of_day(current_date, tzid)), previously_active)) |
paul@414 | 400 | current_date += timedelta(1) |
paul@414 | 401 | else: |
paul@414 | 402 | current_date = this_date |
paul@153 | 403 | |
paul@153 | 404 | # Add any continuing periods. |
paul@153 | 405 | |
paul@455 | 406 | if point.point != start_of_day: |
paul@455 | 407 | new_slots.append((Point(start_of_day), previously_active)) |
paul@153 | 408 | |
paul@153 | 409 | # Add the currently active periods at this point in time. |
paul@153 | 410 | |
paul@153 | 411 | previously_active = active |
paul@153 | 412 | |
paul@162 | 413 | for t in new_slots: |
paul@162 | 414 | insort_left(slots, t) |
paul@162 | 415 | |
paul@162 | 416 | def add_slots(slots, points): |
paul@162 | 417 | |
paul@162 | 418 | """ |
paul@162 | 419 | Introduce into the 'slots' entries for those in 'points' that are not |
paul@170 | 420 | already present, propagating active periods from time points preceding |
paul@170 | 421 | those added. |
paul@162 | 422 | """ |
paul@162 | 423 | |
paul@162 | 424 | new_slots = [] |
paul@162 | 425 | |
paul@162 | 426 | for point in points: |
paul@452 | 427 | i = bisect_left(slots, (point,)) # slots is [(point, active)...] |
paul@162 | 428 | if i < len(slots) and slots[i][0] == point: |
paul@162 | 429 | continue |
paul@162 | 430 | |
paul@170 | 431 | new_slots.append((point, i > 0 and slots[i-1][1] or [])) |
paul@162 | 432 | |
paul@162 | 433 | for t in new_slots: |
paul@162 | 434 | insort_left(slots, t) |
paul@162 | 435 | |
paul@162 | 436 | def partition_by_day(slots): |
paul@162 | 437 | |
paul@162 | 438 | """ |
paul@162 | 439 | Return a mapping from dates to time points provided by 'slots'. |
paul@162 | 440 | """ |
paul@162 | 441 | |
paul@162 | 442 | d = {} |
paul@162 | 443 | |
paul@455 | 444 | for point, value in slots: |
paul@455 | 445 | day = point.point.date() |
paul@162 | 446 | if not d.has_key(day): |
paul@162 | 447 | d[day] = [] |
paul@455 | 448 | d[day].append((point, value)) |
paul@162 | 449 | |
paul@162 | 450 | return d |
paul@153 | 451 | |
paul@283 | 452 | def add_empty_days(days, tzid): |
paul@279 | 453 | |
paul@279 | 454 | "Add empty days to 'days' between busy days." |
paul@279 | 455 | |
paul@279 | 456 | last_day = None |
paul@279 | 457 | all_days = days.keys() |
paul@279 | 458 | all_days.sort() |
paul@279 | 459 | |
paul@279 | 460 | for day in all_days: |
paul@279 | 461 | if last_day: |
paul@279 | 462 | empty_day = last_day + timedelta(1) |
paul@279 | 463 | while empty_day < day: |
paul@455 | 464 | days[empty_day] = [(Point(get_start_of_day(empty_day, tzid)), None)] |
paul@279 | 465 | empty_day += timedelta(1) |
paul@279 | 466 | last_day = day |
paul@279 | 467 | |
paul@114 | 468 | def get_spans(slots): |
paul@114 | 469 | |
paul@114 | 470 | "Inspect the given 'slots', returning a mapping of event uids to spans." |
paul@114 | 471 | |
paul@455 | 472 | points = [point for point, active in slots] |
paul@114 | 473 | spans = {} |
paul@114 | 474 | |
paul@449 | 475 | for _point, active in slots: |
paul@114 | 476 | for t in active: |
paul@185 | 477 | if t and len(t) >= 2: |
paul@395 | 478 | start, end, uid, recurrenceid, summary, organiser, key = get_freebusy_details(t) |
paul@185 | 479 | |
paul@455 | 480 | start_slot = bisect_left(points, start) |
paul@455 | 481 | end_slot = bisect_left(points, end) |
paul@185 | 482 | spans[key] = end_slot - start_slot |
paul@114 | 483 | |
paul@114 | 484 | return spans |
paul@114 | 485 | |
paul@185 | 486 | def get_freebusy_details(t): |
paul@185 | 487 | |
paul@395 | 488 | """ |
paul@395 | 489 | Return a tuple of the form (start, end, uid, recurrenceid, summary, |
paul@395 | 490 | organiser, key) from 't'. |
paul@395 | 491 | """ |
paul@185 | 492 | |
paul@185 | 493 | # Handle both complete free/busy details... |
paul@185 | 494 | |
paul@395 | 495 | if len(t) >= 7: |
paul@395 | 496 | start, end, uid, transp, recurrenceid, summary, organiser = t[:7] |
paul@425 | 497 | key = uid, recurrenceid, start |
paul@185 | 498 | |
paul@185 | 499 | # ...and published details without specific event details. |
paul@185 | 500 | |
paul@185 | 501 | else: |
paul@185 | 502 | start, end = t[:2] |
paul@185 | 503 | uid = None |
paul@343 | 504 | recurrenceid = None |
paul@395 | 505 | summary = None |
paul@395 | 506 | organiser = None |
paul@185 | 507 | key = (start, end) |
paul@185 | 508 | |
paul@395 | 509 | return start, end, uid, recurrenceid, summary, organiser, key |
paul@185 | 510 | |
paul@395 | 511 | def update_freebusy(freebusy, periods, transp, uid, recurrenceid, summary, organiser): |
paul@250 | 512 | |
paul@250 | 513 | """ |
paul@395 | 514 | Update the free/busy details with the given 'periods', 'transp' setting, |
paul@395 | 515 | 'uid' plus 'recurrenceid' and 'summary' and 'organiser' details. |
paul@250 | 516 | """ |
paul@250 | 517 | |
paul@343 | 518 | remove_period(freebusy, uid, recurrenceid) |
paul@250 | 519 | |
paul@250 | 520 | for start, end in periods: |
paul@395 | 521 | insert_period(freebusy, (start, end, uid, transp, recurrenceid, summary, organiser)) |
paul@250 | 522 | |
paul@48 | 523 | # vim: tabstop=4 expandtab shiftwidth=4 |