Example #1
0
    def visit_any(self,eci):
        """Copy the entire tree from here"""
        if eci.name == 'TimeZone':
            new_name = 'MeetingTimeZone'
        else:
            new_name = eci.name

        ci = CNode(name=new_name)

        for k,v in eci.attr.iteritems():
            ci.attr[k] = v

        if eci.content != None:
            ci.content = str(eci.content)
        else:
            ci.content = None

        for c in eci.children:
            ci.add_child(self.visit(c))

        return ci
Example #2
0
    def visit_any(self,eci):
        """Copy the entire tree from here"""
        if eci.name == 'MeetingTimeZone':
            new_name = 'TimeZone'
        else:
            new_name = eci.name

        ci = CNode(name=new_name)
        ci.content = eci.content

        for c in eci.children:
            ci.add_child(self.visit(c))

        return ci
Example #3
0
def xml2cnode(xml):
    """Convert an arbitrary xml structure to a tree of cnodes

    xml: xml.etree.ElementTree.Element type
    return: CNode
    """
    
    r = CNode(name=xml.tag)
    r.content = xml.text

    for k,v in xml.attrib.iteritems():
        r.attr[k] = v

    for c in xml.getchildren():
        e = xml2cnode(c)
        r.add_child(e)

    return r
Example #4
0
def rrule2recurrence(rrule, starttime):
    freq = rrule['freq'][0]
    
    if rrule.has_key('INTERVAL'):
        interval = rrule['INTERVAL'][0]
    else:
        interval = 1

    interval_e = CNode(name='Interval', content=interval)
    recurrence_e = CNode(name='Recurrence')

    if freq == 'YEARLY':
        recpattern_e = rrule2yearly_recpattern(rrule, interval_e, starttime)
        recurrence_e.add_child(recpattern_e)
        
    elif freq == 'MONTHLY':
        if  rrule.has_key('BYDAY'):
            # When more than one day, it is impossible to do in
            # Exchange (except if all days are in the same week)
            day = rrule['byday'][0]

            recpattern_e = CNode(name='RelativeMonthlyRecurrence')
            dow_e, weekindex_e = byday2rel_month(day)

            recpattern_e.add_child(interval_e)
            recpattern_e.add_child(dow_e)
            recpattern_e.add_child(weekindex_e)

            recurrence_e.add_child(recpattern_e)
        else:
            recpattern_e = CNode(name='AbsoluteMonthlyRecurrence')

            if rrule.has_key('BYMONTHDAY'):
                mday = str(rrule['BYMONTHDAY'][0])
            else:
                mday = str(starttime.day)

            dayofmonth = CNode(name='DayOfMonth',content=mday)

            recpattern_e.add_child(dayofmonth)
            recurrence_e.add_child(recpattern_e)

    elif freq == 'WEEKLY' or \
         (freq == 'DAILY' and rrule.has_key('BYDAY')):

        recpattern_e = CNode(name='WeeklyRecurrence')
        daysofweek_e = CNode(name='DaysOfWeek')

        if rrule.has_key('WKST') or rrule.has_key('BYDAY'):
            if rrule.has_key('WKST'): # TODO: really?
                ical_days = rrule['WKST']
            else:
                ical_days = rrule['BYDAY']

            days = [weekday_ical2xml(w) for w in ical_days]
            daysofweek_e.content = " ".join(days)

        else:
            wkday = dt2xml_weekday(starttime)
            daysofweek_e.content = wkday

        recpattern_e.add_child(interval_e)
        recpattern_e.add_child(daysofweek_e)

        recurrence_e.add_child(recpattern_e)


    elif freq == 'DAILY':
        recpattern_e = CNode(name='DailyRecurrence')
        recpattern_e.add_child(interval_e)
        
        recurrence_e.add_child(recpattern_e)

    return recurrence_e