[CalendarServer-changes] [4991] CalendarServer/trunk/txcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 29 17:32:56 PST 2010
Revision: 4991
http://trac.macosforge.org/projects/calendarserver/changeset/4991
Author: wsanchez at apple.com
Date: 2010-01-29 17:32:55 -0800 (Fri, 29 Jan 2010)
Log Message:
-----------
More calendar store implementation
Modified Paths:
--------------
CalendarServer/trunk/txcaldav/calendarstore/file.py
CalendarServer/trunk/txcaldav/calendarstore/test/file.py
CalendarServer/trunk/txcaldav/icalendarstore.py
Added Paths:
-----------
CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1.ics
CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2.ics
CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/3.ics
Removed Paths:
-------------
CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1b5b7348a80950dcf567e904943949d3.ics
CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2dc69bdb048b56b81697c87093f4d115.ics
CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/6d9700c01f2f360adb285ce7b4c0dab3.ics
Modified: CalendarServer/trunk/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-01-30 01:32:27 UTC (rev 4990)
+++ CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-01-30 01:32:55 UTC (rev 4991)
@@ -25,11 +25,14 @@
"CalendarObject",
]
+import errno
+
from zope.interface import implements
from twisted.python.filepath import FilePath
from twext.log import LoggingMixIn
+from twext.python.icalendar import Component as iComponent, InvalidICalendarDataError
from txcaldav.icalendarstore import ICalendarHome, ICalendar, ICalendarObject
#from txcaldav.icalendarstore import CalendarStoreError
@@ -39,8 +42,9 @@
#from txcaldav.icalendarstore import CalendarObjectUIDAlreadyExistsError
from txcaldav.icalendarstore import NotFoundError
#from txcaldav.icalendarstore import NoSuchCalendarError
-#from txcaldav.icalendarstore import NoSuchCalendarObjectError
+from txcaldav.icalendarstore import NoSuchCalendarObjectError
#from txcaldav.icalendarstore import InvalidCalendarComponentError
+from txcaldav.icalendarstore import InternalDataStoreError
class CalendarStore(LoggingMixIn):
@@ -52,6 +56,8 @@
"""
@param path: a L{FilePath}
"""
+ assert isinstance(path, FilePath)
+
self.path = path
if not path.isdir():
@@ -135,10 +141,10 @@
def createCalendarObjectWithName(self, name, component):
raise NotImplementedError()
- def removeCalendarComponentWithName(self, name):
+ def removeCalendarObjectWithName(self, name):
raise NotImplementedError()
- def removeCalendarComponentWithUID(self, uid):
+ def removeCalendarObjectWithUID(self, uid):
raise NotImplementedError()
def syncToken(self):
@@ -171,16 +177,60 @@
raise NotImplementedError()
def component(self):
- raise NotImplementedError()
+ if not hasattr(self, "_component"):
+ text = self.iCalendarText()
+ try:
+ component = iComponent.fromString(text)
+ except InvalidICalendarDataError, e:
+ raise InternalDataStoreError(
+ "File corruption detected (%s) in file: %s"
+ % (e, self.path.path)
+ )
+
+ del self._text
+ self._component = component
+
+ return self._component
+
def iCalendarText(self):
- raise NotImplementedError()
+ if not hasattr(self, "_text"):
+ if hasattr(self, "_component"):
+ return str(self._component)
+ try:
+ fh = self.path.open()
+ except IOError, e:
+ if e[0] == errno.ENOENT:
+ raise NoSuchCalendarObjectError(self)
+
+ try:
+ text = fh.read()
+ finally:
+ fh.close()
+
+ if not (
+ text.startswith("BEGIN:VCALENDAR\r\n") or
+ text.endswith("\r\nEND:VCALENDAR\r\n")
+ ):
+ raise InternalDataStoreError(
+ "File corruption detected (improper start) in file: %s"
+ % (self.path.path,)
+ )
+
+ self._text = text
+
+ return self._text
+
def uid(self):
- raise NotImplementedError()
+ if not hasattr(self, "_uid"):
+ self._uid = self.component().resourceUID()
+ return self._uid
def componentType(self):
- raise NotImplementedError()
+ if not hasattr(self, "_componentType"):
+ self._componentType = self.component().mainType()
+ return self._componentType
def organizer(self):
# FIXME: Ideally should return a URI object
Copied: CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1.ics (from rev 4989, CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1b5b7348a80950dcf567e904943949d3.ics)
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1.ics (rev 0)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1.ics 2010-01-30 01:32:55 UTC (rev 4991)
@@ -0,0 +1,48 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:uid1
+DTSTART;TZID=US/Eastern:20060102T180000
+DURATION:PT1H
+CREATED:20060102T230000Z
+DTSTAMP:20051222T210507Z
+RRULE:FREQ=DAILY;COUNT=5
+SUMMARY:event 7-%ctr
+BEGIN:VALARM
+ACTION:AUDIO
+TRIGGER;RELATED=START:-PT10M
+X-MULBERRY-ALARM-STATUS:PENDING
+X-MULBERRY-SPEAK-TEXT:
+END:VALARM
+END:VEVENT
+BEGIN:VEVENT
+UID:uid1
+RECURRENCE-ID;TZID=US/Eastern;RANGE=THISANDFUTURE:20060104T180000
+DTSTART;TZID=US/Eastern:20060104T200000
+DURATION:PT1H
+CREATED:20060102T230000Z
+DESCRIPTION:Some notes
+DTSTAMP:20051222T210507Z
+SUMMARY:event 7-%ctr changed
+END:VEVENT
+END:VCALENDAR
Deleted: CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1b5b7348a80950dcf567e904943949d3.ics
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1b5b7348a80950dcf567e904943949d3.ics 2010-01-30 01:32:27 UTC (rev 4990)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/1b5b7348a80950dcf567e904943949d3.ics 2010-01-30 01:32:55 UTC (rev 4991)
@@ -1,48 +0,0 @@
-BEGIN:VCALENDAR
-VERSION:2.0
-CALSCALE:GREGORIAN
-PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
-BEGIN:VTIMEZONE
-TZID:US/Eastern
-LAST-MODIFIED:20040110T032845Z
-BEGIN:STANDARD
-DTSTART:20001026T020000
-RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
-TZNAME:EST
-TZOFFSETFROM:-0400
-TZOFFSETTO:-0500
-END:STANDARD
-BEGIN:DAYLIGHT
-DTSTART:20000404T020000
-RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
-TZNAME:EDT
-TZOFFSETFROM:-0500
-TZOFFSETTO:-0400
-END:DAYLIGHT
-END:VTIMEZONE
-BEGIN:VEVENT
-UID:F5B811E00073B22BA6B87562-%ctr at ninevah.local
-DTSTART;TZID=US/Eastern:20060102T180000
-DURATION:PT1H
-CREATED:20060102T230000Z
-DTSTAMP:20051222T210507Z
-RRULE:FREQ=DAILY;COUNT=5
-SUMMARY:event 7-%ctr
-BEGIN:VALARM
-ACTION:AUDIO
-TRIGGER;RELATED=START:-PT10M
-X-MULBERRY-ALARM-STATUS:PENDING
-X-MULBERRY-SPEAK-TEXT:
-END:VALARM
-END:VEVENT
-BEGIN:VEVENT
-UID:F5B811E00073B22BA6B87562-%ctr at ninevah.local
-RECURRENCE-ID;TZID=US/Eastern;RANGE=THISANDFUTURE:20060104T180000
-DTSTART;TZID=US/Eastern:20060104T200000
-DURATION:PT1H
-CREATED:20060102T230000Z
-DESCRIPTION:Some notes
-DTSTAMP:20051222T210507Z
-SUMMARY:event 7-%ctr changed
-END:VEVENT
-END:VCALENDAR
Copied: CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2.ics (from rev 4989, CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2dc69bdb048b56b81697c87093f4d115.ics)
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2.ics (rev 0)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2.ics 2010-01-30 01:32:55 UTC (rev 4991)
@@ -0,0 +1,48 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:uid2
+DTSTART;TZID=US/Eastern:20060102T140000
+DURATION:PT1H
+CREATED:20060102T190000Z
+DTSTAMP:20051222T210507Z
+RRULE:FREQ=DAILY;COUNT=5
+SUMMARY:event 6-%ctr
+END:VEVENT
+BEGIN:VEVENT
+UID:uid2
+RECURRENCE-ID;TZID=US/Eastern:20060104T140000
+DTSTART;TZID=US/Eastern:20060104T160000
+DURATION:PT1H
+CREATED:20060102T190000Z
+DESCRIPTION:Some notes
+DTSTAMP:20051222T210507Z
+SUMMARY:event 6-%ctr changed
+BEGIN:VALARM
+ACTION:AUDIO
+TRIGGER;RELATED=START:-PT10M
+X-MULBERRY-ALARM-STATUS:PENDING
+X-MULBERRY-SPEAK-TEXT:
+END:VALARM
+END:VEVENT
+END:VCALENDAR
Deleted: CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2dc69bdb048b56b81697c87093f4d115.ics
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2dc69bdb048b56b81697c87093f4d115.ics 2010-01-30 01:32:27 UTC (rev 4990)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/2dc69bdb048b56b81697c87093f4d115.ics 2010-01-30 01:32:55 UTC (rev 4991)
@@ -1,48 +0,0 @@
-BEGIN:VCALENDAR
-VERSION:2.0
-CALSCALE:GREGORIAN
-PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
-BEGIN:VTIMEZONE
-TZID:US/Eastern
-LAST-MODIFIED:20040110T032845Z
-BEGIN:STANDARD
-DTSTART:20001026T020000
-RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
-TZNAME:EST
-TZOFFSETFROM:-0400
-TZOFFSETTO:-0500
-END:STANDARD
-BEGIN:DAYLIGHT
-DTSTART:20000404T020000
-RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
-TZNAME:EDT
-TZOFFSETFROM:-0500
-TZOFFSETTO:-0400
-END:DAYLIGHT
-END:VTIMEZONE
-BEGIN:VEVENT
-UID:F5B811E00073B22BA6B87551-%ctr at ninevah.local
-DTSTART;TZID=US/Eastern:20060102T140000
-DURATION:PT1H
-CREATED:20060102T190000Z
-DTSTAMP:20051222T210507Z
-RRULE:FREQ=DAILY;COUNT=5
-SUMMARY:event 6-%ctr
-END:VEVENT
-BEGIN:VEVENT
-UID:F5B811E00073B22BA6B87551-%ctr at ninevah.local
-RECURRENCE-ID;TZID=US/Eastern:20060104T140000
-DTSTART;TZID=US/Eastern:20060104T160000
-DURATION:PT1H
-CREATED:20060102T190000Z
-DESCRIPTION:Some notes
-DTSTAMP:20051222T210507Z
-SUMMARY:event 6-%ctr changed
-BEGIN:VALARM
-ACTION:AUDIO
-TRIGGER;RELATED=START:-PT10M
-X-MULBERRY-ALARM-STATUS:PENDING
-X-MULBERRY-SPEAK-TEXT:
-END:VALARM
-END:VEVENT
-END:VCALENDAR
Copied: CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/3.ics (from rev 4989, CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/6d9700c01f2f360adb285ce7b4c0dab3.ics)
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/3.ics (rev 0)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/3.ics 2010-01-30 01:32:55 UTC (rev 4991)
@@ -0,0 +1,33 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
+BEGIN:VTIMEZONE
+TZID:US/Pacific
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:uid3
+DTSTART;TZID=US/Pacific:20060101T130000
+DURATION:PT1H
+CREATED:20060101T210000Z
+DTSTAMP:20051222T210146Z
+LAST-MODIFIED:20051222T210203Z
+SEQUENCE:1
+SUMMARY:event 3-%ctr
+END:VEVENT
+END:VCALENDAR
Deleted: CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/6d9700c01f2f360adb285ce7b4c0dab3.ics
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/6d9700c01f2f360adb285ce7b4c0dab3.ics 2010-01-30 01:32:27 UTC (rev 4990)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/calendar_store/home1/calendar_1/6d9700c01f2f360adb285ce7b4c0dab3.ics 2010-01-30 01:32:55 UTC (rev 4991)
@@ -1,33 +0,0 @@
-BEGIN:VCALENDAR
-VERSION:2.0
-CALSCALE:GREGORIAN
-PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
-BEGIN:VTIMEZONE
-TZID:US/Pacific
-LAST-MODIFIED:20040110T032845Z
-BEGIN:STANDARD
-DTSTART:20001026T020000
-RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
-TZNAME:PST
-TZOFFSETFROM:-0700
-TZOFFSETTO:-0800
-END:STANDARD
-BEGIN:DAYLIGHT
-DTSTART:20000404T020000
-RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
-TZNAME:PDT
-TZOFFSETFROM:-0800
-TZOFFSETTO:-0700
-END:DAYLIGHT
-END:VTIMEZONE
-BEGIN:VEVENT
-UID:DB3F97EF10A051730E2F752E-%ctr at ninevah.local
-DTSTART;TZID=US/Pacific:20060101T130000
-DURATION:PT1H
-CREATED:20060101T210000Z
-DTSTAMP:20051222T210146Z
-LAST-MODIFIED:20051222T210203Z
-SEQUENCE:1
-SUMMARY:event 3-%ctr
-END:VEVENT
-END:VCALENDAR
Modified: CalendarServer/trunk/txcaldav/calendarstore/test/file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/file.py 2010-01-30 01:32:27 UTC (rev 4990)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/file.py 2010-01-30 01:32:55 UTC (rev 4991)
@@ -18,13 +18,13 @@
File calendar store tests.
"""
-import os
-
from zope.interface.verify import verifyObject, BrokenMethodImplementation
from twisted.python.filepath import FilePath
from twisted.trial import unittest
+from twext.python.icalendar import Component as iComponent
+
from txdav.idav import IPropertyStore
from txcaldav.icalendarstore import ICalendarHome
@@ -45,9 +45,9 @@
)
calendar1_objectNames = (
- "1b5b7348a80950dcf567e904943949d3.ics",
- "2dc69bdb048b56b81697c87093f4d115.ics",
- "6d9700c01f2f360adb285ce7b4c0dab3.ics",
+ "1.ics",
+ "2.ics",
+ "3.ics",
)
class CalendarStoreTest(unittest.TestCase):
@@ -207,3 +207,68 @@
def test_properties(self):
raise NotImplementedError()
test_properties.todo = "Unimplemented"
+
+
+class CalendarObjectTest(unittest.TestCase):
+ def setUp(self):
+ self.calendarStore = CalendarStore(storePath)
+ self.home1 = self.calendarStore.calendarHomeWithUID("home1")
+ self.calendar1 = self.home1.calendarWithName("calendar_1")
+ self.object1 = self.calendar1.calendarObjectWithName("1.ics")
+
+ def test_interface(self):
+ try:
+ verifyObject(ICalendarObject, self.object1)
+ except BrokenMethodImplementation, e:
+ self.fail(e)
+
+ def test_init(self):
+ self.failUnless(
+ isinstance(self.object1.path, FilePath),
+ self.object1.path
+ )
+ self.failUnless(
+ isinstance(self.object1.calendar, Calendar),
+ self.object1.calendar
+ )
+
+ def test_name(self):
+ self.assertEquals(self.object1.name(), "1.ics")
+
+ def test_setComponent(self):
+ raise NotImplementedError()
+ test_setComponent.todo = "Unimplemented"
+
+ def test_component(self):
+ component = self.object1.component()
+
+ self.failUnless(
+ isinstance(component, iComponent),
+ component
+ )
+
+ self.assertEquals(component.name(), "VCALENDAR")
+ self.assertEquals(component.mainType(), "VEVENT")
+ self.assertEquals(component.resourceUID(), "uid1")
+
+ def text_iCalendarText(self):
+ text = self.object1.iCalendarText()
+
+ self.failUnless(isinstance(text, str), text)
+ self.failUnless(text.startswith("BEGIN:VCALENDAR\r\n"))
+ self.failUnless("\r\nUID:uid-1\r\n" in text)
+ self.failUnless(text.endswith("\r\nEND:VCALENDAR\r\n"))
+
+ def test_uid(self):
+ self.assertEquals(self.object1.uid(), "uid1")
+
+ def test_componentType(self):
+ self.assertEquals(self.object1.componentType(), "VEVENT")
+
+ def test_organizer(self):
+ raise NotImplementedError()
+ test_organizer.todo = "Unimplemented"
+
+ def test_properties(self):
+ raise NotImplementedError()
+ test_properties.todo = "Unimplemented"
Modified: CalendarServer/trunk/txcaldav/icalendarstore.py
===================================================================
--- CalendarServer/trunk/txcaldav/icalendarstore.py 2010-01-30 01:32:27 UTC (rev 4990)
+++ CalendarServer/trunk/txcaldav/icalendarstore.py 2010-01-30 01:32:55 UTC (rev 4991)
@@ -32,6 +32,7 @@
"NoSuchCalendarError",
"NoSuchCalendarObjectError",
"InvalidCalendarComponentError",
+ "InternalDataStoreError",
# Classes
"ICalendarHome",
@@ -109,6 +110,11 @@
Invalid calendar component.
"""
+class InternalDataStoreError(CalendarStoreError):
+ """
+ Uh, oh.
+ """
+
#
# Interfaces
#
@@ -225,9 +231,9 @@
a calendar object.
"""
- def removeCalendarComponentWithName(name):
+ def removeCalendarObjectWithName(name):
"""
- Remove the calendar component with the given C{name} from this
+ Remove the calendar object with the given C{name} from this
calendar.
@param name: a string.
@@ -235,9 +241,9 @@
exists.
"""
- def removeCalendarComponentWithUID(uid):
+ def removeCalendarObjectWithUID(uid):
"""
- Remove the calendar component with the given C{uid} from this
+ Remove the calendar object with the given C{uid} from this
calendar.
@param uid: a string.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100129/8513ce4c/attachment-0001.html>
More information about the calendarserver-changes
mailing list