[CalendarServer-changes] [1823] CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav /admin/util.py

source_changes at macosforge.org source_changes at macosforge.org
Fri Aug 24 12:24:35 PDT 2007


Revision: 1823
          http://trac.macosforge.org/projects/calendarserver/changeset/1823
Author:   cdaboo at apple.com
Date:     2007-08-24 12:24:35 -0700 (Fri, 24 Aug 2007)

Log Message:
-----------
Pulled up r1819.

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/admin/util.py

Modified: CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/admin/util.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/admin/util.py	2007-08-24 18:34:42 UTC (rev 1822)
+++ CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/admin/util.py	2007-08-24 19:24:35 UTC (rev 1823)
@@ -23,7 +23,8 @@
 from twisted.web import microdom
 
 from twistedcaldav import ical
-from twistedcaldav.sql import db_prefix
+from twistedcaldav.sql import db_prefix, AbstractSQLDatabase
+from twistedcaldav.index import schema_version, collection_types
 
 def prepareByteValue(config, value):
     if config.get('human', None):
@@ -109,6 +110,28 @@
     return (collection, type)
 
 
+class EventCountingDatabase(AbstractSQLDatabase):
+    def __init__(self, fp):
+        super(EventCountingDatabase, self).__init__(fp.path)
+
+    def _db_version(self):
+        return schema_version
+
+    def _db_type(self):
+        return collection_types['Calendar']
+
+    def _countType(self, type):
+        return self._db_value_for_sql(
+                    "SELECT COUNT(UID) FROM RESOURCE WHERE TYPE = (?)",
+                    type)
+
+    def countEvents(self):
+        return self._countType('VEVENT')
+
+    def countTodos(self):
+        return self._countType('VTODO')
+
+
 def getCalendarDataCounts(calendarCollection):
     calCount = 0
     eventCount = 0
@@ -119,18 +142,11 @@
             if getResourceType(child) == (True, 'calendar'):
                 calCount += 1
 
-        elif child.isfile():
-            try:
-                component = ical.Component.fromStream(child.open())
-            except ValueError:
-                # not a calendar file
-                continue
+                db = EventCountingDatabase(child.child(db_prefix+'sqlite'))
 
-            if component.resourceType() == 'VEVENT':
-                eventCount += 1
+                eventCount += db.countEvents()
 
-            elif component.resourceType() == 'VTODO':
-                todoCount += 1
+                todoCount += db.countTodos()
 
     return {'calendarCount': calCount,
             'eventCount': eventCount,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070824/191084ad/attachment.html


More information about the calendarserver-changes mailing list