1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imiptools/stores/__init__.py Sun Mar 06 00:44:42 2016 +0100
1.3 @@ -0,0 +1,529 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +General support for calendar data storage.
1.8 +
1.9 +Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +class StoreBase:
1.26 +
1.27 + "The core operations of a data store."
1.28 +
1.29 + def acquire_lock(self, user, timeout=None):
1.30 + pass
1.31 +
1.32 + def release_lock(self, user):
1.33 + pass
1.34 +
1.35 + # User discovery.
1.36 +
1.37 + def get_users(self):
1.38 +
1.39 + "Return a list of users."
1.40 +
1.41 + pass
1.42 +
1.43 + # Event and event metadata access.
1.44 +
1.45 + def get_events(self, user):
1.46 +
1.47 + "Return a list of event identifiers."
1.48 +
1.49 + pass
1.50 +
1.51 + def get_all_events(self, user):
1.52 +
1.53 + "Return a set of (uid, recurrenceid) tuples for all events."
1.54 +
1.55 + uids = self.get_events(user)
1.56 + if not uids:
1.57 + return set()
1.58 +
1.59 + all_events = set()
1.60 + for uid in uids:
1.61 + all_events.add((uid, None))
1.62 + all_events.update([(uid, recurrenceid) for recurrenceid in self.get_recurrences(user, uid)])
1.63 +
1.64 + return all_events
1.65 +
1.66 + def get_event(self, user, uid, recurrenceid=None, dirname=None):
1.67 +
1.68 + """
1.69 + Get the event for the given 'user' with the given 'uid'. If
1.70 + the optional 'recurrenceid' is specified, a specific instance or
1.71 + occurrence of an event is returned.
1.72 + """
1.73 +
1.74 + pass
1.75 +
1.76 + def get_complete_event(self, user, uid):
1.77 +
1.78 + "Get the event for the given 'user' with the given 'uid'."
1.79 +
1.80 + pass
1.81 +
1.82 + def set_event(self, user, uid, recurrenceid, node):
1.83 +
1.84 + """
1.85 + Set an event for 'user' having the given 'uid' and 'recurrenceid' (which
1.86 + if the latter is specified, a specific instance or occurrence of an
1.87 + event is referenced), using the given 'node' description.
1.88 + """
1.89 +
1.90 + if recurrenceid:
1.91 + return self.set_recurrence(user, uid, recurrenceid, node)
1.92 + else:
1.93 + return self.set_complete_event(user, uid, node)
1.94 +
1.95 + def set_complete_event(self, user, uid, node):
1.96 +
1.97 + "Set an event for 'user' having the given 'uid' and 'node'."
1.98 +
1.99 + pass
1.100 +
1.101 + def remove_event(self, user, uid, recurrenceid=None):
1.102 +
1.103 + """
1.104 + Remove an event for 'user' having the given 'uid'. If the optional
1.105 + 'recurrenceid' is specified, a specific instance or occurrence of an
1.106 + event is removed.
1.107 + """
1.108 +
1.109 + if recurrenceid:
1.110 + return self.remove_recurrence(user, uid, recurrenceid)
1.111 + else:
1.112 + for recurrenceid in self.get_recurrences(user, uid) or []:
1.113 + self.remove_recurrence(user, uid, recurrenceid)
1.114 + return self.remove_complete_event(user, uid)
1.115 +
1.116 + def remove_complete_event(self, user, uid):
1.117 +
1.118 + "Remove an event for 'user' having the given 'uid'."
1.119 +
1.120 + self.remove_recurrences(user, uid)
1.121 + return self.remove_parent_event(user, uid)
1.122 +
1.123 + def remove_parent_event(self, user, uid):
1.124 +
1.125 + "Remove the parent event for 'user' having the given 'uid'."
1.126 +
1.127 + pass
1.128 +
1.129 + def get_recurrences(self, user, uid):
1.130 +
1.131 + """
1.132 + Get additional event instances for an event of the given 'user' with the
1.133 + indicated 'uid'. Both active and cancelled recurrences are returned.
1.134 + """
1.135 +
1.136 + return self.get_active_recurrences(user, uid) + self.get_cancelled_recurrences(user, uid)
1.137 +
1.138 + def get_active_recurrences(self, user, uid):
1.139 +
1.140 + """
1.141 + Get additional event instances for an event of the given 'user' with the
1.142 + indicated 'uid'. Cancelled recurrences are not returned.
1.143 + """
1.144 +
1.145 + pass
1.146 +
1.147 + def get_cancelled_recurrences(self, user, uid):
1.148 +
1.149 + """
1.150 + Get additional event instances for an event of the given 'user' with the
1.151 + indicated 'uid'. Only cancelled recurrences are returned.
1.152 + """
1.153 +
1.154 + pass
1.155 +
1.156 + def get_recurrence(self, user, uid, recurrenceid):
1.157 +
1.158 + """
1.159 + For the event of the given 'user' with the given 'uid', return the
1.160 + specific recurrence indicated by the 'recurrenceid'.
1.161 + """
1.162 +
1.163 + pass
1.164 +
1.165 + def set_recurrence(self, user, uid, recurrenceid, node):
1.166 +
1.167 + "Set an event for 'user' having the given 'uid' and 'node'."
1.168 +
1.169 + pass
1.170 +
1.171 + def remove_recurrence(self, user, uid, recurrenceid):
1.172 +
1.173 + """
1.174 + Remove a special recurrence from an event stored by 'user' having the
1.175 + given 'uid' and 'recurrenceid'.
1.176 + """
1.177 +
1.178 + pass
1.179 +
1.180 + def remove_recurrences(self, user, uid):
1.181 +
1.182 + """
1.183 + Remove all recurrences for an event stored by 'user' having the given
1.184 + 'uid'.
1.185 + """
1.186 +
1.187 + for recurrenceid in self.get_recurrences(user, uid):
1.188 + self.remove_recurrence(user, uid, recurrenceid)
1.189 +
1.190 + return self.remove_recurrence_collection(user, uid)
1.191 +
1.192 + def remove_recurrence_collection(self, user, uid):
1.193 +
1.194 + """
1.195 + Remove the collection of recurrences stored by 'user' having the given
1.196 + 'uid'.
1.197 + """
1.198 +
1.199 + pass
1.200 +
1.201 + # Free/busy period providers, upon extension of the free/busy records.
1.202 +
1.203 + def get_freebusy_providers(self, user, dt=None):
1.204 +
1.205 + """
1.206 + Return a set of uncancelled events of the form (uid, recurrenceid)
1.207 + providing free/busy details beyond the given datetime 'dt'.
1.208 +
1.209 + If 'dt' is not specified, all events previously found to provide
1.210 + details will be returned. Otherwise, if 'dt' is earlier than the
1.211 + datetime recorded for the known providers, None is returned, indicating
1.212 + that the list of providers must be recomputed.
1.213 +
1.214 + This function returns a list of (uid, recurrenceid) tuples upon success.
1.215 + """
1.216 +
1.217 + pass
1.218 +
1.219 + def set_freebusy_providers(self, user, dt, providers):
1.220 +
1.221 + """
1.222 + Define the uncancelled events providing free/busy details beyond the
1.223 + given datetime 'dt'.
1.224 + """
1.225 +
1.226 + pass
1.227 +
1.228 + def append_freebusy_provider(self, user, provider):
1.229 +
1.230 + "For the given 'user', append the free/busy 'provider'."
1.231 +
1.232 + pass
1.233 +
1.234 + def remove_freebusy_provider(self, user, provider):
1.235 +
1.236 + "For the given 'user', remove the free/busy 'provider'."
1.237 +
1.238 + pass
1.239 +
1.240 + # Free/busy period access.
1.241 +
1.242 + def get_freebusy(self, user, name=None):
1.243 +
1.244 + "Get free/busy details for the given 'user'."
1.245 +
1.246 + pass
1.247 +
1.248 + def get_freebusy_for_other(self, user, other):
1.249 +
1.250 + "For the given 'user', get free/busy details for the 'other' user."
1.251 +
1.252 + pass
1.253 +
1.254 + def set_freebusy(self, user, freebusy, name=None):
1.255 +
1.256 + "For the given 'user', set 'freebusy' details."
1.257 +
1.258 + pass
1.259 +
1.260 + def set_freebusy_for_other(self, user, freebusy, other):
1.261 +
1.262 + "For the given 'user', set 'freebusy' details for the 'other' user."
1.263 +
1.264 + pass
1.265 +
1.266 + # Tentative free/busy periods related to countering.
1.267 +
1.268 + def get_freebusy_offers(self, user):
1.269 +
1.270 + "Get free/busy offers for the given 'user'."
1.271 +
1.272 + pass
1.273 +
1.274 + def set_freebusy_offers(self, user, freebusy):
1.275 +
1.276 + "For the given 'user', set 'freebusy' offers."
1.277 +
1.278 + return self.set_freebusy(user, freebusy, "freebusy-offers")
1.279 +
1.280 + # Requests and counter-proposals.
1.281 +
1.282 + def get_requests(self, user):
1.283 +
1.284 + "Get requests for the given 'user'."
1.285 +
1.286 + pass
1.287 +
1.288 + def set_requests(self, user, requests):
1.289 +
1.290 + "For the given 'user', set the list of queued 'requests'."
1.291 +
1.292 + pass
1.293 +
1.294 + def set_request(self, user, uid, recurrenceid=None, type=None):
1.295 +
1.296 + """
1.297 + For the given 'user', set the queued 'uid' and 'recurrenceid',
1.298 + indicating a request, along with any given 'type'.
1.299 + """
1.300 +
1.301 + pass
1.302 +
1.303 + def queue_request(self, user, uid, recurrenceid=None, type=None):
1.304 +
1.305 + """
1.306 + Queue a request for 'user' having the given 'uid'. If the optional
1.307 + 'recurrenceid' is specified, the entry refers to a specific instance
1.308 + or occurrence of an event. The 'type' parameter can be used to indicate
1.309 + a specific type of request.
1.310 + """
1.311 +
1.312 + requests = self.get_requests(user) or []
1.313 +
1.314 + if not self.have_request(requests, uid, recurrenceid):
1.315 + return self.set_request(user, uid, recurrenceid, type)
1.316 +
1.317 + return False
1.318 +
1.319 + def dequeue_request(self, user, uid, recurrenceid=None):
1.320 +
1.321 + """
1.322 + Dequeue all requests for 'user' having the given 'uid'. If the optional
1.323 + 'recurrenceid' is specified, all requests for that specific instance or
1.324 + occurrence of an event are dequeued.
1.325 + """
1.326 +
1.327 + requests = self.get_requests(user) or []
1.328 + result = []
1.329 +
1.330 + for request in requests:
1.331 + if request[:2] != (uid, recurrenceid):
1.332 + result.append(request)
1.333 +
1.334 + self.set_requests(user, result)
1.335 + return True
1.336 +
1.337 + def has_request(self, user, uid, recurrenceid=None, type=None, strict=False):
1.338 + return self.have_request(self.get_requests(user) or [], uid, recurrenceid, type, strict)
1.339 +
1.340 + def have_request(self, requests, uid, recurrenceid=None, type=None, strict=False):
1.341 +
1.342 + """
1.343 + Return whether 'requests' contains a request with the given 'uid' and
1.344 + any specified 'recurrenceid' and 'type'. If 'strict' is set to a true
1.345 + value, the precise type of the request must match; otherwise, any type
1.346 + of request for the identified object may be matched.
1.347 + """
1.348 +
1.349 + for request in requests:
1.350 + if request[:2] == (uid, recurrenceid) and (
1.351 + not strict or
1.352 + not request[2:] and not type or
1.353 + request[2:] and request[2] == type):
1.354 +
1.355 + return True
1.356 +
1.357 + return False
1.358 +
1.359 + def get_counters(self, user, uid, recurrenceid=None):
1.360 +
1.361 + """
1.362 + For the given 'user', return a list of users from whom counter-proposals
1.363 + have been received for the given 'uid' and optional 'recurrenceid'.
1.364 + """
1.365 +
1.366 + pass
1.367 +
1.368 + def get_counter(self, user, other, uid, recurrenceid=None):
1.369 +
1.370 + """
1.371 + For the given 'user', return the counter-proposal from 'other' for the
1.372 + given 'uid' and optional 'recurrenceid'.
1.373 + """
1.374 +
1.375 + pass
1.376 +
1.377 + def set_counter(self, user, other, node, uid, recurrenceid=None):
1.378 +
1.379 + """
1.380 + For the given 'user', store a counter-proposal received from 'other' the
1.381 + given 'node' representing that proposal for the given 'uid' and
1.382 + 'recurrenceid'.
1.383 + """
1.384 +
1.385 + pass
1.386 +
1.387 + def remove_counters(self, user, uid, recurrenceid=None):
1.388 +
1.389 + """
1.390 + For the given 'user', remove all counter-proposals associated with the
1.391 + given 'uid' and 'recurrenceid'.
1.392 + """
1.393 +
1.394 + pass
1.395 +
1.396 + def remove_counter(self, user, other, uid, recurrenceid=None):
1.397 +
1.398 + """
1.399 + For the given 'user', remove any counter-proposal from 'other'
1.400 + associated with the given 'uid' and 'recurrenceid'.
1.401 + """
1.402 +
1.403 + pass
1.404 +
1.405 + # Event cancellation.
1.406 +
1.407 + def cancel_event(self, user, uid, recurrenceid=None):
1.408 +
1.409 + """
1.410 + Cancel an event for 'user' having the given 'uid'. If the optional
1.411 + 'recurrenceid' is specified, a specific instance or occurrence of an
1.412 + event is cancelled.
1.413 + """
1.414 +
1.415 + pass
1.416 +
1.417 + def uncancel_event(self, user, uid, recurrenceid=None):
1.418 +
1.419 + """
1.420 + Uncancel an event for 'user' having the given 'uid'. If the optional
1.421 + 'recurrenceid' is specified, a specific instance or occurrence of an
1.422 + event is uncancelled.
1.423 + """
1.424 +
1.425 + pass
1.426 +
1.427 + def remove_cancellations(self, user, uid, recurrenceid=None):
1.428 +
1.429 + """
1.430 + Remove cancellations for 'user' for any event having the given 'uid'. If
1.431 + the optional 'recurrenceid' is specified, a specific instance or
1.432 + occurrence of an event is affected.
1.433 + """
1.434 +
1.435 + # Remove all recurrence cancellations if a general event is indicated.
1.436 +
1.437 + if not recurrenceid:
1.438 + for _recurrenceid in self.get_cancelled_recurrences(user, uid):
1.439 + self.remove_cancellation(user, uid, _recurrenceid)
1.440 +
1.441 + return self.remove_cancellation(user, uid, recurrenceid)
1.442 +
1.443 + def remove_cancellation(self, user, uid, recurrenceid=None):
1.444 +
1.445 + """
1.446 + Remove a cancellation for 'user' for the event having the given 'uid'.
1.447 + If the optional 'recurrenceid' is specified, a specific instance or
1.448 + occurrence of an event is affected.
1.449 + """
1.450 +
1.451 + pass
1.452 +
1.453 +class PublisherBase:
1.454 +
1.455 + "The core operations of a data publisher."
1.456 +
1.457 + def set_freebusy(self, user, freebusy):
1.458 +
1.459 + "For the given 'user', set 'freebusy' details."
1.460 +
1.461 + pass
1.462 +
1.463 +class JournalBase:
1.464 +
1.465 + "The core operations of a journal system supporting quotas."
1.466 +
1.467 + # Quota and user identity/group discovery.
1.468 +
1.469 + def get_quotas(self):
1.470 +
1.471 + "Return a list of quotas."
1.472 +
1.473 + pass
1.474 +
1.475 + def get_quota_users(self, quota):
1.476 +
1.477 + "Return a list of quota users."
1.478 +
1.479 + pass
1.480 +
1.481 + # Groups of users sharing quotas.
1.482 +
1.483 + def get_groups(self, quota):
1.484 +
1.485 + "Return the identity mappings for the given 'quota' as a dictionary."
1.486 +
1.487 + pass
1.488 +
1.489 + def get_limits(self, quota):
1.490 +
1.491 + """
1.492 + Return the limits for the 'quota' as a dictionary mapping identities or
1.493 + groups to durations.
1.494 + """
1.495 +
1.496 + pass
1.497 +
1.498 + # Free/busy period access for users within quota groups.
1.499 +
1.500 + def get_freebusy(self, quota, user):
1.501 +
1.502 + "Get free/busy details for the given 'quota' and 'user'."
1.503 +
1.504 + pass
1.505 +
1.506 + def set_freebusy(self, quota, user, freebusy):
1.507 +
1.508 + "For the given 'quota' and 'user', set 'freebusy' details."
1.509 +
1.510 + pass
1.511 +
1.512 + # Journal entry methods.
1.513 +
1.514 + def get_entries(self, quota, group):
1.515 +
1.516 + """
1.517 + Return a list of journal entries for the given 'quota' for the indicated
1.518 + 'group'.
1.519 + """
1.520 +
1.521 + pass
1.522 +
1.523 + def set_entries(self, quota, group, entries):
1.524 +
1.525 + """
1.526 + For the given 'quota' and indicated 'group', set the list of journal
1.527 + 'entries'.
1.528 + """
1.529 +
1.530 + pass
1.531 +
1.532 +# vim: tabstop=4 expandtab shiftwidth=4