Esempio n. 1
0
 def delete_event(self, record):
     uuid, recurrence_id = splitUUID(record.uuid)
     item = eim.get_item_for_uuid(uuid)
     if item is not None and item.isLive() and pim.has_stamp(item,
         EventStamp):
         if recurrence_id:
             occurrence = EventStamp(item).getRecurrenceID(recurrence_id)
             occurrence.unmodify(partial=True)
         else:
             EventStamp(item).remove()
Esempio n. 2
0
 def delete_event(self, record):
     uuid, recurrence_id = splitUUID(record.uuid)
     item = eim.get_item_for_uuid(uuid)
     if item is not None and item.isLive() and pim.has_stamp(
             item, EventStamp):
         if recurrence_id:
             occurrence = EventStamp(item).getRecurrenceID(recurrence_id)
             occurrence.unmodify(partial=True)
         else:
             EventStamp(item).remove()
Esempio n. 3
0
    def getItemForAlias(self, alias):
        if str(alias).startswith("@"):
            # a well-known-name
            return super(SharingTranslator, self).getItemForAlias(alias)

        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator, self).getItemForAlias(alias)

        # a modification
        master = eim.item_for_uuid(uuid)
        return Recurrence(master).get_occurrence(recurrence_id)
Esempio n. 4
0
    def getItemForAlias(self, alias):
        if str(alias).startswith("@"):
            # a well-known-name
            return super(SharingTranslator, self).getItemForAlias(alias)

        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator, self).getItemForAlias(alias)

        # a modification
        master = eim.item_for_uuid(uuid)
        return Recurrence(master).get_occurrence(recurrence_id)
Esempio n. 5
0
    def withItemForUUID(self, alias, itype=Item, **attrs):
        """Handle recurrence modification aliases."""
        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator,
                         self).withItemForUUID(uuid, itype, **attrs)

        occurrence = self.getItemForAlias(alias)
        master = self.getItemForAlias(uuid)
        master_recur = Recurrence(master)

        add_on = itype if itype is not Item else None

        # recurrence triage is a special case
        if add_on is Triage and 'manual' in attrs and 'manual_timestamp' in attrs:
            status, timestamp = attrs['manual'], attrs['manual_timestamp']
            if status is eim.Inherit:
                master_recur.clear_occurrence_triage(recurrence_id)
            else:
                master_recur.triage_occurrence(recurrence_id, timestamp,
                                               status)
            del attrs['manual']
            del attrs['manual_timestamp']

        for name, value in attrs.items():
            if value is eim.Inherit:
                occurrence.remove_change(add_on, name)
            elif value is not eim.NoChange:
                occurrence.modify(add_on, name, value)

        value = occurrence if add_on is None else add_on(occurrence)
        if issubclass(itype, Extension):
            if not itype.installed_on(occurrence) and attrs:
                value.add()

        def decorator(func):
            try:
                return func(value)
            except Exception, e:
                self.recordFailure(e)
Esempio n. 6
0
    def withItemForUUID(self, alias, itype=Item, **attrs):
        """Handle recurrence modification aliases."""
        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator, self).withItemForUUID(uuid, itype, **attrs)

        occurrence = self.getItemForAlias(alias)
        master = self.getItemForAlias(uuid)
        master_recur = Recurrence(master)

        add_on = itype if itype is not Item else None

        # recurrence triage is a special case
        if add_on is Triage and 'manual' in attrs and 'manual_timestamp' in attrs:
            status, timestamp = attrs['manual'], attrs['manual_timestamp']
            if status is eim.Inherit:
                master_recur.clear_occurrence_triage(recurrence_id)
            else:
                master_recur.triage_occurrence(recurrence_id, timestamp, status)
            del attrs['manual']
            del attrs['manual_timestamp']

        for name, value in attrs.items():
            if value is eim.Inherit:
                occurrence.remove_change(add_on, name)
            elif value is not eim.NoChange:
                occurrence.modify(add_on, name, value)

        value = occurrence if add_on is None else add_on(occurrence)
        if issubclass(itype, Extension):
            if not itype.installed_on(occurrence) and attrs:
                value.add()

        def decorator(func):
            try:
                return func(value)
            except Exception, e:
                self.recordFailure(e)
Esempio n. 7
0
    def import_event(self, record):
        start, all_day, any_time = getTimeValues(record)
        uuid, recurrence_id = splitUUID(record.uuid)

        @self.withItemForUUID(record.uuid, Event,
            base_start=start,
            tzinfo=start.tzinfo if start not in emptyValues else eim.NoChange,
            all_day=all_day,
            base_any_time=any_time,
            base_duration=with_nochange(record.duration, fromICalendarDuration),
            location=record.location,
            base_transparency=with_nochange(record.status, from_transparency),
        )
        def do(event):
            if recurrence_id:
                return
            add_recurrence = not all_empty(record, 'rdate', 'rrule')
            recurrence_installed = Recurrence.installed_on(event.item)
            if not recurrence_installed and not add_recurrence:
                pass # no recurrence, nothing to do
            elif recurrence_id:
                pass # modification, no rules to set
            else:
                recur = Recurrence(event.item)
                if add_recurrence and not recurrence_installed:
                    recur.add()
                for datetype in 'rdate', 'exdate':
                    record_field = getattr(record, datetype)
                    if record_field is not eim.NoChange:
                        if record_field is None:
                            dates = ()
                        else:
                            dates = fromICalendarDateTime(record_field, multivalued=True)[0]
                        date_set = getattr(recur, datetype + 's')
                        if date_set.symmetric_difference(dates):
                            date_set.clear()
                            date_set.update(dates)

                if record.rrule is not eim.NoChange:
                    if record.rrule in emptyValues:
                        recur.frequency = None
                    else:
                        # EIM serializes multiple RRULEs colon separated,
                        # ignoring all but the first for now.
                        rule_dict = {}
                        first_rule, sep, later_rules = record.rrule.upper().partition(':')
                        for key_value_string in first_rule.split(';'):
                            key, sep, value = key_value_string.partition('=')
                            rule_dict[key] = value

                        # count and until are mutually exclusive, special case
                        if 'COUNT' in rule_dict:
                            recur.count = int(rule_dict['COUNT'])
                        elif 'UNTIL' in rule_dict:
                            recur.until = fromICalendarDateTime(rule_dict['UNTIL'])[0]
                        else:
                            recur.until = None

                        for attr, tup in rrule_attr_dispatch.items():
                            rule_key, convert = tup
                            if rule_key in rule_dict:
                                setattr(recur, attr, convert(rule_dict[rule_key]))
                            else:
                                reset_cell_default(recur, attr)

                if not recur.frequency and not recur.rdates:
                    if recurrence_installed:
                        recur.remove()
Esempio n. 8
0
    def import_event(self, record):
        start, all_day, any_time = getTimeValues(record)
        uuid, recurrence_id = splitUUID(record.uuid)

        @self.withItemForUUID(
            record.uuid,
            Event,
            base_start=start,
            tzinfo=start.tzinfo if start not in emptyValues else eim.NoChange,
            all_day=all_day,
            base_any_time=any_time,
            base_duration=with_nochange(record.duration,
                                        fromICalendarDuration),
            location=record.location,
            base_transparency=with_nochange(record.status, from_transparency),
        )
        def do(event):
            if recurrence_id:
                return
            add_recurrence = not all_empty(record, 'rdate', 'rrule')
            recurrence_installed = Recurrence.installed_on(event.item)
            if not recurrence_installed and not add_recurrence:
                pass  # no recurrence, nothing to do
            elif recurrence_id:
                pass  # modification, no rules to set
            else:
                recur = Recurrence(event.item)
                if add_recurrence and not recurrence_installed:
                    recur.add()
                for datetype in 'rdate', 'exdate':
                    record_field = getattr(record, datetype)
                    if record_field is not eim.NoChange:
                        if record_field is None:
                            dates = ()
                        else:
                            dates = fromICalendarDateTime(record_field,
                                                          multivalued=True)[0]
                        date_set = getattr(recur, datetype + 's')
                        if date_set.symmetric_difference(dates):
                            date_set.clear()
                            date_set.update(dates)

                if record.rrule is not eim.NoChange:
                    if record.rrule in emptyValues:
                        recur.frequency = None
                    else:
                        # EIM serializes multiple RRULEs colon separated,
                        # ignoring all but the first for now.
                        rule_dict = {}
                        first_rule, sep, later_rules = record.rrule.upper(
                        ).partition(':')
                        for key_value_string in first_rule.split(';'):
                            key, sep, value = key_value_string.partition('=')
                            rule_dict[key] = value

                        # count and until are mutually exclusive, special case
                        if 'COUNT' in rule_dict:
                            recur.count = int(rule_dict['COUNT'])
                        elif 'UNTIL' in rule_dict:
                            recur.until = fromICalendarDateTime(
                                rule_dict['UNTIL'])[0]
                        else:
                            recur.until = None

                        for attr, tup in rrule_attr_dispatch.items():
                            rule_key, convert = tup
                            if rule_key in rule_dict:
                                setattr(recur, attr,
                                        convert(rule_dict[rule_key]))
                            else:
                                reset_cell_default(recur, attr)

                if not recur.frequency and not recur.rdates:
                    if recurrence_installed:
                        recur.remove()