1 #!/usr/bin/env python 2 3 """ 4 Handlers for a person for whom scheduling is performed, inspecting outgoing 5 messages to obtain scheduling done externally. 6 """ 7 8 from imiptools.content import Handler, uri_item 9 from vCalendar import to_node 10 11 class PersonHandler(Handler): 12 13 "Handling mechanisms specific to people." 14 15 def _get_identity(self, objtype, from_organiser=True): 16 17 """ 18 Get the identity of interest in a usable form for any unprocessed 19 object. 20 """ 21 22 identity, attr = item = uri_item(self.get_item(from_organiser and "ORGANIZER" or "ATTENDEE")) 23 24 # Check for event using UID. 25 26 if not self.have_new_object(identity, objtype): 27 return None 28 29 return item 30 31 def _record(self, objtype, from_organiser=True, update_freebusy=False): 32 33 "Record free/busy and object information." 34 35 item = self._get_identity(objtype, from_organiser) 36 if not item: 37 return False 38 39 identity, attr = item 40 41 # Store the object. 42 43 self.store.set_event(identity, self.uid, to_node( 44 {objtype : [(self.details, {})]} 45 )) 46 47 # Update free/busy information. 48 49 if update_freebusy: 50 51 # If newer than any old version, discard old details from the 52 # free/busy record and check for suitability. 53 54 periods = self.get_periods() 55 freebusy = self.store.get_freebusy(identity) or [] 56 57 if from_organiser or attr.get("PARTSTAT") != "DECLINED": 58 self.update_freebusy(freebusy, identity, periods) 59 else: 60 self.remove_from_freebusy(freebusy, identity) 61 62 if self.publisher: 63 self.publisher.set_freebusy(identity, freebusy) 64 65 return True 66 67 def _remove(self, objtype, from_organiser=True): 68 69 "Remove free/busy information for any unprocessed object." 70 71 item = self._get_identity(objtype, from_organiser) 72 if not item: 73 return False 74 75 identity, attr = item 76 77 freebusy = self.store.get_freebusy(identity) or [] 78 self.remove_from_freebusy(freebusy, identity) 79 80 return True 81 82 class Event(PersonHandler): 83 84 "An event handler." 85 86 def add(self): 87 pass 88 89 def cancel(self): 90 self._remove("VEVENT", True) 91 92 def counter(self): 93 pass 94 95 def declinecounter(self): 96 pass 97 98 def publish(self): 99 self._record("VEVENT", True, True) 100 101 def refresh(self): 102 self._record("VEVENT", True, True) 103 104 def reply(self): 105 self._record("VEVENT", False, True) 106 107 def request(self): 108 self._record("VEVENT", True, True) 109 110 class Freebusy(PersonHandler): 111 112 "A free/busy handler." 113 114 def publish(self): 115 pass 116 117 def reply(self): 118 pass 119 120 def request(self): 121 pass 122 123 class Journal(PersonHandler): 124 125 "A journal entry handler." 126 127 def add(self): 128 pass 129 130 def cancel(self): 131 self._remove("VJOURNAL", True) 132 133 def publish(self): 134 self._record("VJOURNAL", True) 135 136 class Todo(PersonHandler): 137 138 "A to-do item handler." 139 140 def add(self): 141 pass 142 143 def cancel(self): 144 self._remove("VTODO", True) 145 146 def counter(self): 147 pass 148 149 def declinecounter(self): 150 pass 151 152 def publish(self): 153 self._record("VTODO", True) 154 155 def refresh(self): 156 self._record("VTODO", True) 157 158 def reply(self): 159 self._record("VTODO", False) 160 161 def request(self): 162 self._record("VTODO", True) 163 164 # Handler registry. 165 166 handlers = [ 167 ("VFREEBUSY", Freebusy), 168 ("VEVENT", Event), 169 ("VTODO", Todo), 170 ("VJOURNAL", Journal), 171 ] 172 173 # vim: tabstop=4 expandtab shiftwidth=4