def getcalendar(self,result): res={} # Read exceptions file first try: buf=prototypes.buffer(self.getfilecontents(self.calendarexceptionlocation)) ex=self.protocolclass.scheduleexceptionfile() ex.readfrombuffer(buf, logtitle="Calendar exceptions") exceptions={} for i in ex.items: try: exceptions[i.pos].append( (i.year,i.month,i.day) ) except KeyError: exceptions[i.pos]=[ (i.year,i.month,i.day) ] except com_brew.BrewNoSuchFileException: exceptions={} # Now read schedule try: buf=prototypes.buffer(self.getfilecontents(self.calendarlocation)) if len(buf.getdata())<3: # file is empty, and hence same as non-existent raise com_brew.BrewNoSuchFileException() sc=self.protocolclass.schedulefile() sc.readfrombuffer(buf, logtitle="Calendar") for event in sc.events: # the vx8100 has a bad entry when the calender is empty # stop processing the calender when we hit this record if event.pos==0: #invalid entry continue entry=bpcalendar.CalendarEntry() entry.desc_loc=event.description try: # delete events are still in the calender file but have garbage dates entry.start=event.start entry.end=event.end except ValueError: continue if event.alarmindex_vibrate&0x1: entry.vibrate=0 # vibarate bit is inverted in phone 0=on, 1=off else: entry.vibrate=1 entry.repeat = self.makerepeat(event.repeat, event.start) min=event.alarmminutes hour=event.alarmhours if min==0x64 or hour==0x64: entry.alarm=None # no alarm set else: entry.alarm=hour*60+min entry.ringtone=result['ringtone-index'][event.ringtone]['name'] entry.snoozedelay=0 # check for exceptions and remove them if event.repeat[3] and exceptions.has_key(event.pos): for year, month, day in exceptions[event.pos]: entry.suppress_repeat_entry(year, month, day) res[entry.id]=entry assert sc.numactiveitems==len(res) except com_brew.BrewNoSuchFileException: pass # do nothing if file doesn't exist result['calendar']=res return result
def _accept(self, entry): # start & end time within specified filter if entry.get('repeat', False): # repeat event # need to populate to get an accurate end date ce = bpcalendar.CalendarEntry() self._populate_entry(entry, ce) if self._filter['start'] is not None and \ ce.end[:3]<self._filter['start'][:3]: # event ends before our rannge return False if self._filter['end'] is not None and \ ce.start[:3]>self._filter['end'][:3]: # event starts after our range return False else: # single event if self._filter['start'] is not None and \ entry['start'][:3]<self._filter['start'][:3]: return False if self._filter['end'] is not None and \ entry['end'][:3]>self._filter['end'][:3] and \ entry['end'][:3]!=common_calendar.no_end_date[:3]: return False # check the catefory c = self._filter['categories'] if c is None or not len(c): # no categories specified => all catefories allowed. return True if len([x for x in entry['categories'] if x in c]): return True return False
def getcalendar(self, result): entries = {} self.log("Getting calendar entries") self.setmode(self.MODEPHONEBOOK) req = self.protocolclass.eventrequest() cal_cnt = 0 for slot in range(self.protocolclass.NUMCALENDAREVENTS): req.slot = slot res = self.sendpbcommand(req, self.protocolclass.eventresponse) if len(res) > 0: self.progress(slot + 1, self.protocolclass.NUMCALENDAREVENTS, res[0].eventname) # build a calendar entry entry = bpcalendar.CalendarEntry() # start time date entry.start = res[0].start[0:5] if res[0].end: # valid end time entry.end = res[0].start[0:5] else: entry.end = entry.start # description entry.description = res[0].eventname try: alarm = self.__cal_alarm_values[res[0].alarm] except: alarm = None entry.alarm = alarm # update calendar dict entries[entry.id] = entry cal_cnt += 1 result['calendar'] = entries self.setmode(self.MODEMODEM) return result
def getcalendar(self, result): res = {} # Read exceptions file first exceptions = self.getexceptions() # Now read schedule try: buf = prototypes.buffer(self.getfilecontents( self.calendarlocation)) if len(buf.getdata()) < 3: # file is empty, and hence same as non-existent raise com_brew.BrewNoSuchFileException() sc = self.protocolclass.schedulefile() sc.readfrombuffer(buf, logtitle="Calendar") for event in sc.events: # the vx8100 has a bad entry when the calender is empty # stop processing the calender when we hit this record if event.pos == 0: #invalid entry continue entry = bpcalendar.CalendarEntry() try: # delete events are still in the calender file but have garbage dates self.getcalendarcommon(entry, event) except ValueError: continue if self.protocolclass.CALENDAR_HAS_SEPARATE_END_TIME_AND_DATE: # MIC Unlike previous phones, the VX8300 passes the ringtone # via both the index, and a path. If the index is set to 100 # (0x64), then the ringtone information will be found in the # "ringpath", the last 256 bytes of the calendar packet. If # the index is between 0 and 15, inclusive, then it is using # one of the builtin ringers, and the ringpath is set to # null. try: if (event.ringtone == 100 ): # MIC Ringer is downloaded to phone or microSD entry.ringtone = common.basename(event.ringpath) else: # MIC Ringer is built-in entry.ringtone = self.builtinringtones[ event.ringtone] except: # hack, not having a phone makes it hard to figure out the best approach if entry.alarm == None: entry.ringtone = 'No Ring' else: entry.ringtone = 'Loud Beeps' else: entry.ringtone = result['ringtone-index'][ event.ringtone]['name'] # check for exceptions and remove them if event.repeat[3] and exceptions.has_key(event.pos): for year, month, day in exceptions[event.pos]: entry.suppress_repeat_entry(year, month, day) res[entry.id] = entry assert sc.numactiveitems == len(res) except com_brew.BrewNoSuchFileException: pass # do nothing if file doesn't exist result['calendar'] = res return result
def getcalendar(self, result): res = {} # Read exceptions file first exceptions = self.getexceptions() try: buf = prototypes.buffer( self.getfilecontents(self.calendarringerlocation)) ringersf = self.protocolclass.scheduleringerfile() ringersf.readfrombuffer(buf) except: self.log("unable to read schedule ringer path file") # Now read schedule try: buf = prototypes.buffer(self.getfilecontents( self.calendarlocation)) if len(buf.getdata()) < 3: # file is empty, and hence same as non-existent raise com_brew.BrewNoSuchFileException() sc = self.protocolclass.schedulefile() sc.readfrombuffer(buf, logtitle="Calendar") for event in sc.events: # the vx8100 has a bad entry when the calender is empty # stop processing the calender when we hit this record if event.pos == 0: #invalid entry continue entry = bpcalendar.CalendarEntry() try: # delete events are still in the calender file but have garbage dates self.getcalendarcommon(entry, event) except ValueError: continue try: if (event.ringtone >= 100 ): # MIC Ringer is downloaded to phone or microSD entry.ringtone = common.basename( ringersf.ringerpaths[event.ringtone - 100].path) else: # MIC Ringer is built-in entry.ringtone = self.builtinringtones[event.ringtone] except: self.log("Setting default ringer for event\n") # hack, not having a phone makes it hard to figure out the best approach if entry.alarm == None: entry.ringtone = 'No Ring' else: entry.ringtone = 'Loud Beeps' # check for exceptions and remove them if event.repeat[3] and exceptions.has_key(event.pos): for year, month, day in exceptions[event.pos]: entry.suppress_repeat_entry(year, month, day) res[entry.id] = entry assert sc.numactiveitems == len(res) except com_brew.BrewNoSuchFileException: pass # do nothing if file doesn't exist result['calendar'] = res return result
def getvalue(self): # return a BitPim calendar entry equivalence _entry = bpcalendar.CalendarEntry() _entry.desc_loc = self.cal.title _entry.start = self.cal.start _entry.end = self._extract_end() _entry.alarm = self._extract_alarm() _entry.ringtone = self._extract_ringtone() _entry.vibrate = self.cal.alert == self.ALERT_VIBRATE return _entry
def get(self): res = {} single_rpt = self._filter.get('rpt_events', False) for k in self._data: if self._accept(k): if k.get('repeat', False) and single_rpt: d = self._generate_repeat_events(k) else: d = [k] for n in d: ce = bpcalendar.CalendarEntry() self._populate_entry(n, ce) res[ce.id] = ce return res
def _build_bpcalendar_entry(self, phone_entry): entry = bpcalendar.CalendarEntry() entry.start = phone_entry.date + phone_entry.time entry.end = phone_entry.date + phone_entry.time entry.description = phone_entry.description entry.serials.append({'sourcetype': 'phone', 'id': phone_entry.index}) entry.alarm = self.protocolclass.CAL_ALARM_VALUE.get( phone_entry.alarm, -1) _rpt_type = self.cal_repeat_value.get(phone_entry.repeat, None) if _rpt_type: # this is a recurrent event rpt = bpcalendar.RepeatEntry(_rpt_type) if _rpt_type != bpcalendar.RepeatEntry.yearly: rpt.interval = 1 # repeat forever entry.end = bpcalendar.CalendarEntry.no_end_date entry.repeat = rpt return entry
def getcalendar(self, result): self.log("Getting calendar entries") self.setmode(self.MODEPHONEBOOK) res={} l=len(self._cal_entries_range) cal_cnt=0 for k in self._cal_entries_range: r=self.get_calendar_entry(k) if not len(r): # blank, no entry self.progress(k+1, l, "Getting blank entry: %d"%k) continue self.progress(k+1, l, "Getting "+r[self._cal_read_name]) # build a calendar entry entry=bpcalendar.CalendarEntry() # start time date entry.start=self.extract_timedate(r[self._cal_start_datetime]) if self._cal_end_datetime_value is None: # valid end time entry.end=self.extract_timedate(r[self._cal_end_datetime]) else: # no end time, end time=start time entry.end=entry.start # description entry.description=r[self._cal_read_name] # alarm try: alarm=self._cal_alarm_values[r[self._cal_alarm_type]] except: alarm=None entry.alarm=alarm # update calendar dict res[entry.id]=entry cal_cnt += 1 result['calendar']=res self.setmode(self.MODEMODEM) return result
def _build_regular_cal_entry(self, entry, calendar, fundamentals): """ Build a regular BitPim entry frm phone data""" _bp_entry=bpcalendar.CalendarEntry() _bp_entry.id=`entry.index` _bp_entry.desc_loc=entry.title _bp_entry.start=entry.start_date+entry.start_time _t0=datetime.datetime(*_bp_entry.start) _t1=_t0+datetime.timedelta(minutes=entry.duration) _bp_entry.end=(_t1.year, _t1.month, _t1.day, _t1.hour, _t1.minute) if entry.alarm_timed and entry.alarm_enabled: _t3=datetime.datetime(*(entry.alarm_date+entry.alarm_time)) if _t0>=_t3: _bp_entry.alarm=(_t0-_t3).seconds/60 # repeat _rep=self._build_repeat_part(entry, calendar, fundamentals) if _rep: # this is a recurrent event, adjust the end date _bp_entry.repeat=_rep _bp_entry.end=bpcalendar.CalendarEntry.no_end_date+_bp_entry.end[3:] calendar[_bp_entry.id]=_bp_entry
def _generate_repeat_events(self, e): # generate multiple single events from this repeat event ce = bpcalendar.CalendarEntry() self._populate_entry(e, ce) l = [] new_e = e.copy() new_e['repeat'] = False for k in ('repeat_type', 'repeat_interval', 'repeat_dow'): if new_e.has_key(k): del new_e[k] s_date = datetime.datetime(*self._filter['start']) e_date = datetime.datetime(*self._filter['end']) one_day = datetime.timedelta(1) this_date = s_date while this_date <= e_date: date_l = (this_date.year, this_date.month, this_date.day) if ce.is_active(*date_l): new_e['start'] = date_l + new_e['start'][3:] new_e['end'] = date_l + new_e['end'][3:] l.append(new_e.copy()) this_date += one_day return l
def getcalendar(self, result): res = {} # Read exceptions file first try: buf = prototypes.buffer( self.getfilecontents(self.calendarexceptionlocation)) ex = self.protocolclass.scheduleexceptionfile() ex.readfrombuffer(buf, logtitle="Calendar exceptions") exceptions = {} for i in ex.items: try: exceptions[i.pos].append((i.year, i.month, i.day)) except KeyError: exceptions[i.pos] = [(i.year, i.month, i.day)] except com_brew.BrewNoSuchFileException: exceptions = {} # Now read schedule try: buf = prototypes.buffer(self.getfilecontents( self.calendarlocation)) if len(buf.getdata()) < 3: # file is empty, and hence same as non-existent raise com_brew.BrewNoSuchFileException() sc = self.protocolclass.schedulefile() sc.readfrombuffer(buf, logtitle="Calendar") for event in sc.events: # the vx8100 has a bad entry when the calender is empty # stop processing the calender when we hit this record if event.pos == 0: #invalid entry continue entry = bpcalendar.CalendarEntry() entry.desc_loc = event.description try: # delete events are still in the calender file but have garbage dates entry.start = event.start if self.protocolclass.CALENDAR_HAS_SEPARATE_END_TIME_AND_DATE: if event.repeat[ 0] == 0: # MIC: If non-repeating event entry.end = event.end_time # MIC: Set entry.end to full end_time else: _, _, _, hour, minute = event.end_time year, month, day, _, _ = event.end_date entry.end = (year, month, day, hour, minute) else: entry.end = event.end except ValueError: continue if event.alarmindex_vibrate & 0x1: entry.vibrate = 0 # vibarate bit is inverted in phone 0=on, 1=off else: entry.vibrate = 1 entry.repeat = self.makerepeat(event.repeat) min = event.alarmminutes hour = event.alarmhours if min == 0x64 or hour == 0x64: entry.alarm = None # no alarm set else: entry.alarm = hour * 60 + min if self.protocolclass.CALENDAR_HAS_SEPARATE_END_TIME_AND_DATE: # MIC Unlike previous phones, the VX8300 passes the ringtone # via both the index, and a path. If the index is set to 100 # (0x64), then the ringtone information will be found in the # "ringpath", the last 256 bytes of the calendar packet. If # the index is between 0 and 15, inclusive, then it is using # one of the builtin ringers, and the ringpath is set to # null. try: if (event.ringtone == 100 ): # MIC Ringer is downloaded to phone or microSD entry.ringtone = common.basename(event.ringpath) else: # MIC Ringer is built-in entry.ringtone = self.builtinringtones[ event.ringtone] except: # hack, not having a phone makes it hard to figure out the best approach if entry.alarm == None: entry.ringtone = 'No Ring' else: entry.ringtone = 'Loud Beeps' else: #hack for alltel if entry.alarm == None: entry.ringtone = 'No Ring' else: entry.ringtone = 'Loud Beeps' # entry.ringtone=result['ringtone-index'][event.ringtone]['name'] ## This doesn't work on alltel entry.snoozedelay = 0 # check for exceptions and remove them if event.repeat[3] and exceptions.has_key(event.pos): for year, month, day in exceptions[event.pos]: entry.suppress_repeat_entry(year, month, day) res[entry.id] = entry assert sc.numactiveitems == len(res) except com_brew.BrewNoSuchFileException: pass # do nothing if file doesn't exist result['calendar'] = res return result