def getFromICalendar(self, component): """ Returns a calendar component object containing the data in the given component which is specified by this CalendarComponent. """ if self.type != component.name(): raise ValueError( "%s of type %r can't get data from component of type %r" % (self.sname(), self.type, component.name())) result = iComponent(self.type) xml_components = self.components xml_properties = self.properties # Empty element means do all properties and components if xml_components is None and xml_properties is None: xml_components = AllComponents() xml_properties = AllProperties() if xml_components is not None: if xml_components == AllComponents(): for ical_subcomponent in component.subcomponents(): result.addComponent(ical_subcomponent) else: for xml_subcomponent in xml_components: for ical_subcomponent in component.subcomponents(): if ical_subcomponent.name() == xml_subcomponent.type: result.addComponent( xml_subcomponent.getFromICalendar( ical_subcomponent)) if xml_properties is not None: if xml_properties == AllProperties(): for ical_property in component.properties(): result.addProperty(ical_property) else: for xml_property in xml_properties: name = xml_property.property_name for ical_property in component.properties(name): result.addProperty(ical_property) return result
def getFromICalendar(self, component): """ Returns a calendar component object containing the data in the given component which is specified by this CalendarComponent. """ if self.type != component.name(): raise ValueError( "%s of type %r can't get data from component of type %r" % (self.sname(), self.type, component.name()) ) result = iComponent(self.type) xml_components = self.components xml_properties = self.properties # Empty element means do all properties and components if xml_components is None and xml_properties is None: xml_components = AllComponents() xml_properties = AllProperties() if xml_components is not None: if xml_components == AllComponents(): for ical_subcomponent in component.subcomponents(): result.addComponent(ical_subcomponent) else: for xml_subcomponent in xml_components: for ical_subcomponent in component.subcomponents(): if ical_subcomponent.name() == xml_subcomponent.type: result.addComponent(xml_subcomponent.getFromICalendar(ical_subcomponent)) if xml_properties is not None: if xml_properties == AllProperties(): for ical_property in component.properties(): result.addProperty(ical_property) else: for xml_property in xml_properties: name = xml_property.property_name for ical_property in component.properties(name): result.addProperty(ical_property) return result
def splitICalendarFile(inputFileName, outputDirectory): """ Reads iCalendar data from a file and outputs a separate file for each iCalendar component into a directory. This is useful for converting a monolithic iCalendar object into a set of objects that comply with CalDAV's requirements on resources. """ inputFile = open(inputFileName) try: calendar = iComponent.fromStream(inputFile) finally: inputFile.close() assert calendar.name() == "VCALENDAR" topLevelProperties = tuple(calendar.properties()) for subcomponent in calendar.subcomponents(): subcalendar = iComponent("VCALENDAR") # # Add top-level properties from monolithic calendar to # top-level properties of subcalendar. # for property in topLevelProperties: subcalendar.addProperty(property) subcalendar.addComponent(subcomponent) uid = subcalendar.resourceUID() subFileName = os.path.join(outputDirectory, uid + ".ics") print("Writing %s" % (subFileName,)) subcalendar_file = file(subFileName, "w") try: subcalendar_file.write(str(subcalendar)) finally: subcalendar_file.close()
def splitICalendarFile(inputFileName, outputDirectory): """ Reads iCalendar data from a file and outputs a separate file for each iCalendar component into a directory. This is useful for converting a monolithic iCalendar object into a set of objects that comply with CalDAV's requirements on resources. """ inputFile = open(inputFileName) try: calendar = iComponent.fromStream(inputFile) finally: inputFile.close() assert calendar.name() == "VCALENDAR" topLevelProperties = tuple(calendar.properties()) for subcomponent in calendar.subcomponents(): subcalendar = iComponent("VCALENDAR") # # Add top-level properties from monolithic calendar to # top-level properties of subcalendar. # for property in topLevelProperties: subcalendar.addProperty(property) subcalendar.addComponent(subcomponent) uid = subcalendar.resourceUID() subFileName = os.path.join(outputDirectory, uid + ".ics") print("Writing %s" % (subFileName, )) subcalendar_file = file(subFileName, "w") try: subcalendar_file.write(str(subcalendar)) finally: subcalendar_file.close()
for record in records: recordType, shortName = record calendarHome = config.directory.calendarHomeForShortName(recordType, shortName) if not calendarHome: sys.stderr.write("No calendar home found for record: (%s)%s\n" % (recordType, shortName)) sys.exit(1) calendarHomes.add(calendarHome) for calendarHome in calendarHomes: for childName in calendarHome.listChildren(): child = calendarHome.getChild(childName) if isCalendarCollectionResource(child): collections.add(child) try: calendar = iComponent("VCALENDAR") calendar.addProperty(iProperty("VERSION", "2.0")) calendar.addProperty(iProperty("PRODID", iCalendarProductID)) uids = set() tzids = set() for collection in collections: for name, uid, type in collection.index().indexedSearch(None): child = collection.getChild(name) childData = child.iCalendarText() try: childCalendar = iComponent.fromString(childData) except ValueError: continue