Exemplo n.º 1
0
 def _remove_todo(self, uid: str, todo: iCalendar) -> None:
     logger.info('SYNCING removing todo for Task(%s)', uid)
     self._cache.del_todo(uid)  # cleaning cache
     try:  # deleting through caldav
         todo.delete()
     except caldav.lib.error.DAVError:
         logger.exception('Something went wrong while deleting %r => %r',
                          uid, todo)
Exemplo n.º 2
0
    def _import_calendar_todos(self, calendar: iCalendar,
                               import_started_on: datetime, counts: dict):
        todos = calendar.todos(include_completed=not self._cache.initialized)
        todo_uids = {UID_FIELD.get_dav(todo) for todo in todos}

        # browsing all task linked to current calendar,
        # removing missed ones we don't see in fetched todos
        calendar_tasks = dict(self._get_calendar_tasks(calendar))
        for uid in set(calendar_tasks).difference(todo_uids):
            self._clean_task_missing_from_backend(uid, calendar_tasks, counts,
                                                  import_started_on)

        self._denorm_children_on_vtodos(todos)

        for todo in self.__sort_todos(todos):
            uid = UID_FIELD.get_dav(todo)
            self._cache.set_todo(todo, uid)
            # Updating and creating task according to todos
            task = self.datastore.get_task(uid)
            if not task:  # not found, creating it
                task = self.datastore.task_factory(uid)
                with DisabledSyncCtx(task):
                    Translator.fill_task(todo, task, self.namespace)
                    self.datastore.push_task(task)
                counts['created'] += 1
            else:
                result = self._update_task(task, todo)
                counts[result] += 1
            if logger.isEnabledFor(logging.DEBUG):
                if Translator.should_sync(task, self.namespace, todo):
                    logger.warning("Shouldn't be diff for %r", uid)
Exemplo n.º 3
0
 def _create_todo(self, task: Task, calendar: iCalendar):
     logger.info('SYNCING creating todo for %r', task)
     new_todo, new_vtodo = None, Translator.fill_vtodo(
         task, calendar.name, self.namespace)
     try:
         new_todo = calendar.add_todo(new_vtodo.serialize())
     except caldav.lib.error.DAVError:
         logger.exception('Something went wrong while creating '
                          '%r => %r', task, new_todo)
         return
     uid = UID_FIELD.get_dav(todo=new_todo)
     self._cache.set_todo(new_todo, uid)
Exemplo n.º 4
0
 def write_dav(self, vtodo: iCalendar, value: tuple):
     enabled, term = value
     self.clean_dav(vtodo)
     if not enabled:
         return
     assert term in {'day', 'other-day', 'week', 'month', 'year'}
     rrule = vtodo.add(self.dav_name)
     if term == 'other-day':
         rrule.params['FREQ'] = ['DAILY']
         rrule.params['INTERVAL'] = ['2']
     else:
         rrule.params['FREQ'] = [term.upper() + 'LY']
         start_date = DTSTART.get_dav(vtodo=vtodo)
         if term == 'week' and start_date:
             index = int(start_date.dt_value.strftime('%w'))
             rrule.params['BYDAY'] = self.DAV_DAYS[index]
Exemplo n.º 5
0
 def write_dav(self, vtodo: iCalendar, value):
     self.clean_dav(vtodo)
     for related_uid in value:
         related = vtodo.add(self.dav_name)
         related.value = related_uid
         related.params['RELTYPE'] = [self.reltype]
Exemplo n.º 6
0
 def write_dav(self, vtodo: iCalendar, value):
     self.clean_dav(vtodo)
     vtodo.add(self.dav_name).value = value
Exemplo n.º 7
0
 def write_dav(self, vtodo: iCalendar, value):
     """will clean and write new value to vtodo object"""
     self.clean_dav(vtodo)
     vtodo_val = vtodo.add(self.dav_name)
     vtodo_val.value = value
     return vtodo_val