本文整理汇总了Python中twistedcaldav.ical.Component.componentsFromComponent方法的典型用法代码示例。如果您正苦于以下问题:Python Component.componentsFromComponent方法的具体用法?Python Component.componentsFromComponent怎么用?Python Component.componentsFromComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twistedcaldav.ical.Component
的用法示例。
在下文中一共展示了Component.componentsFromComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: importCollectionComponent
# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import componentsFromComponent [as 别名]
def importCollectionComponent(store, component):
"""
Import a component representing a collection (e.g. VCALENDAR) into the
store.
The homeUID and collection resource name the component will be imported
into is derived from the SOURCE property on the VCALENDAR (which must
be present). The code assumes it will be a URI with slash-separated parts
with the penultimate part specifying the homeUID and the last part
specifying the calendar resource name. The NAME property will be used
to set the DAV:display-name, while the COLOR property will be used to set
calendar-color.
Subcomponents (e.g. VEVENTs) are grouped into resources by UID. Objects
which have a UID already in use within the home will be skipped.
@param store: The db store to add the component to
@type store: L{IDataStore}
@param component: The component to store
@type component: L{twistedcaldav.ical.Component}
"""
sourceURI = component.propertyValue("SOURCE")
if not sourceURI:
raise ImportException("Calendar is missing SOURCE property")
ownerUID, collectionResourceName = sourceURI.strip("/").split("/")[-2:]
dir = store.directoryService()
ownerRecord = yield dir.recordWithUID(ownerUID)
if not ownerRecord:
raise ImportException("{} is not in the directory".format(ownerUID))
# Set properties on the collection
txn = store.newTransaction()
home = yield txn.calendarHomeWithUID(ownerUID, create=True)
collection = yield home.childWithName(collectionResourceName)
if not collection:
print("Creating calendar: {}".format(collectionResourceName))
collection = yield home.createChildWithName(collectionResourceName)
for propertyName, element in (
("NAME", davxml.DisplayName),
("COLOR", customxml.CalendarColor),
):
value = component.propertyValue(propertyName)
if value is not None:
setCollectionPropertyValue(collection, element, value)
print(
"Setting {name} to {value}".format(name=propertyName, value=value)
)
yield txn.commit()
# Populate the collection; NB we use a txn for each object, and we might
# want to batch them?
groupedComponents = Component.componentsFromComponent(component)
for groupedComponent in groupedComponents:
try:
uid = list(groupedComponent.subcomponents())[0].propertyValue("UID")
except:
continue
# If event is unscheduled or the organizer matches homeUID, store the
# component
print("Event UID: {}".format(uid))
storeDirectly = True
organizer = groupedComponent.getOrganizer()
if organizer is not None:
organizerRecord = yield dir.recordWithCalendarUserAddress(organizer)
if organizerRecord is None:
# Organizer does not exist, so skip this event
continue
else:
if ownerRecord.uid != organizerRecord.uid:
# Owner is not the organizer
storeDirectly = False
if storeDirectly:
resourceName = "{}.ics".format(str(uuid.uuid4()))
try:
yield storeComponentInHomeAndCalendar(
store, groupedComponent, ownerUID, collectionResourceName,
resourceName
)
print("Imported: {}".format(uid))
except UIDExistsError:
# That event is already in the home
print("Skipping since UID already exists: {}".format(uid))
except Exception, e:
print(
"Failed to import due to: {error}\n{comp}".format(
error=e,
comp=groupedComponent
)
)
else:
# Owner is an attendee, not the organizer
#.........这里部分代码省略.........