[CalendarServer-changes] [552]
CalendarServer/branches/caladmin-tool/caladmin/stats.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Nov 22 09:49:59 PST 2006
Revision: 552
http://trac.macosforge.org/projects/calendarserver/changeset/552
Author: dreid at apple.com
Date: 2006-11-22 09:49:58 -0800 (Wed, 22 Nov 2006)
Log Message:
-----------
refactor calendar count to do event and todo count in a single pass.
Modified Paths:
--------------
CalendarServer/branches/caladmin-tool/caladmin/stats.py
Modified: CalendarServer/branches/caladmin-tool/caladmin/stats.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/stats.py 2006-11-22 17:38:15 UTC (rev 551)
+++ CalendarServer/branches/caladmin-tool/caladmin/stats.py 2006-11-22 17:49:58 UTC (rev 552)
@@ -43,6 +43,8 @@
from twisted.web import microdom
+from twistedcaldav import ical
+
from caladmin.util import prepareByteValue
def getResourceType(fp):
@@ -75,12 +77,17 @@
self.calendarCollection = self.config.parent.calendarCollection
self.principalCollection = self.config.parent.principalCollection
+ self.calCount = 0
+ self.eventCount = 0
+ self.todoCount = 0
+
self.gatherers = [
self.getAccountCount,
self.getGroupCount,
self.getResourceCount,
self.getCalendarCount,
self.getEventCount,
+ self.getTodoCount,
self.getDiskUsage]
def getDiskUsage(self):
@@ -111,18 +118,40 @@
def getResourceCount(self):
return ("# Resources", len(self._getPrincipalList('resources')))
- def getEventCount(self):
- return ("# Events", 0)
+ def _getDataCounts(self):
+ calCount = 0
+ eventCount = 0
+ todoCount = 0
- def getCalendarCount(self):
- count = 0
for child in self.calendarCollection.walk():
if child.isdir():
if getResourceType(child) == (True, 'calendar'):
- count += 1
+ calCount += 1
- return ("# Calendars", count)
+ elif child.isfile():
+ try:
+ component = ical.Component.fromStream(child.open())
+ except ValueError:
+ # not a calendar file
+ continue
+
+ if component.resourceType() == 'VEVENT':
+ eventCount += 1
+ elif component.resourceType() == 'VTODO':
+ todoCount += 1
+
+ return (calCount, eventCount, todoCount)
+
+ def getEventCount(self):
+ return ("# Events", self.eventCount)
+
+ def getTodoCount(self):
+ return ("# Todos", self.todoCount)
+
+ def getCalendarCount(self):
+ return ("# Calendars", self.calCount)
+
def printStatistics(self, head, stats):
self.formatter.printRow([head], 16)
@@ -133,6 +162,8 @@
assert self.root.exists()
stats = []
+ self.calCount, self.eventCount, self.todoCount = self._getDataCounts()
+
for gatherer in self.gatherers:
stats.append(gatherer())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061122/bb65533f/attachment.html
More information about the calendarserver-changes
mailing list