[CalendarServer-changes] [8212] CalendarServer/trunk/calendarserver/tools/dbinspect.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 20 07:35:34 PDT 2011
Revision: 8212
http://trac.macosforge.org/projects/calendarserver/changeset/8212
Author: cdaboo at apple.com
Date: 2011-10-20 07:35:33 -0700 (Thu, 20 Oct 2011)
Log Message:
-----------
New command to summarize calendar and resource counts in each calendar home.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/dbinspect.py
Modified: CalendarServer/trunk/calendarserver/tools/dbinspect.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/dbinspect.py 2011-10-19 16:27:05 UTC (rev 8211)
+++ CalendarServer/trunk/calendarserver/tools/dbinspect.py 2011-10-20 14:35:33 UTC (rev 8212)
@@ -137,6 +137,59 @@
returnValue(tuple([row[0] for row in rows]))
+class CalendarHomesSummary(Cmd):
+
+ _name = "List Calendar Homes with summary information"
+
+ @inlineCallbacks
+ def doIt(self, txn):
+
+ uids = yield self.getCalendars(txn)
+
+ results = {}
+ for uid, calname, count in sorted(uids, key=lambda x:x[0]):
+ totalname, totalcount = results.get(uid, (0, 0,))
+ if calname != "inbox":
+ totalname += 1
+ totalcount += count
+ results[uid] = (totalname, totalcount,)
+
+ # Print table of results
+ table = tables.Table()
+ table.addHeader(("Owner UID", "Short Name", "Calendars", "Resources"))
+ for uid in sorted(results.keys()):
+ shortname = UserNameFromUID(txn, uid)
+ table.addRow((
+ uid,
+ shortname,
+ results[uid][0],
+ results[uid][1],
+ ))
+
+ print "\n"
+ print "Calendars with resource count (total=%d):\n" % (len(results),)
+ table.printTable()
+
+ @inlineCallbacks
+ def getCalendars(self, txn):
+ ch = schema.CALENDAR_HOME
+ cb = schema.CALENDAR_BIND
+ co = schema.CALENDAR_OBJECT
+ rows = (yield Select(
+ [
+ ch.OWNER_UID,
+ cb.CALENDAR_RESOURCE_NAME,
+ Count(co.RESOURCE_ID),
+ ],
+ From=ch.join(
+ cb, type="inner", on=(ch.RESOURCE_ID == cb.CALENDAR_HOME_RESOURCE_ID).And(
+ cb.BIND_MODE == _BIND_MODE_OWN)).join(
+ co, type="left", on=(cb.CALENDAR_RESOURCE_ID == co.CALENDAR_RESOURCE_ID)),
+ GroupBy=(ch.OWNER_UID, cb.CALENDAR_RESOURCE_NAME)
+ ).on(txn))
+ returnValue(tuple(rows))
+
+
class Calendars(Cmd):
_name = "List Calendars"
@@ -699,6 +752,7 @@
# Register commands
self.registerCommand(CalendarHomes)
+ self.registerCommand(CalendarHomesSummary)
self.registerCommand(Calendars)
self.registerCommand(Events)
self.registerCommand(Event)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111020/d6a4d037/attachment.html>
More information about the calendarserver-changes
mailing list