[CalendarServer-changes] [553]
CalendarServer/branches/caladmin-tool/caladmin
source_changes at macosforge.org
source_changes at macosforge.org
Wed Nov 22 10:47:24 PST 2006
Revision: 553
http://trac.macosforge.org/projects/calendarserver/changeset/553
Author: dreid at apple.com
Date: 2006-11-22 10:47:23 -0800 (Wed, 22 Nov 2006)
Log Message:
-----------
move a bunch of stats stuff into util, and add support for principal type statistics, users, groups, resources etc.
Modified Paths:
--------------
CalendarServer/branches/caladmin-tool/caladmin/options.py
CalendarServer/branches/caladmin-tool/caladmin/script.py
CalendarServer/branches/caladmin-tool/caladmin/stats.py
CalendarServer/branches/caladmin-tool/caladmin/util.py
Modified: CalendarServer/branches/caladmin-tool/caladmin/options.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/options.py 2006-11-22 17:49:58 UTC (rev 552)
+++ CalendarServer/branches/caladmin-tool/caladmin/options.py 2006-11-22 18:47:23 UTC (rev 553)
@@ -103,20 +103,6 @@
registerCommand(QuotaOptions)
-class UserOptions(SubCommand):
- name = 'users'
- help = 'Retrieve information about and perform actions on users.'
- action = 'caladmin.users.UserAction'
-
- optFlags = [
- ['list', '1', 'List only usernames, one per line.'],
- ['disabled', 'd', 'Limit display to disabled users.'],
- ['detailed', None, 'Detailed statistics for each account.'],
- ]
-
-registerCommand(UserOptions)
-
-
class PurgeOptions(SubCommand):
name = 'purge'
help = ('Keep your store from becoming unnecessarily large by purging '
@@ -144,6 +130,7 @@
registerCommand(StatsOptions)
+
from twisted.python import filepath
class LogOptions(SubCommand):
@@ -173,3 +160,42 @@
SubCommand.postOptions(self)
registerCommand(LogOptions)
+
+
+class PrincipalOptions(SubCommand):
+ name = None
+ help = ("Gather statistics and act on %s")
+ action = 'caladmin.principals.PrincipalAction'
+
+ optFlags = [
+ PARAM_HUMAN,
+ PARAM_KILO,
+ PARAM_MEGA,
+ PARAM_GIGA,
+ ]
+
+ def postOptions(self):
+ reflect.namedAny(self.action)(self, self.name).run()
+
+
+class UserOptions(PrincipalOptions):
+ name = "users"
+ help = PrincipalOptions.help % (name,)
+
+registerCommand(UserOptions)
+
+
+class GroupOptions(PrincipalOptions):
+ name = "groups"
+ help = PrincipalOptions.help % (name,)
+
+registerCommand(GroupOptions)
+
+
+class ResourceOptions(PrincipalOptions):
+ name = "resources"
+ help = PrincipalOptions.help % (name,)
+
+registerCommand(ResourceOptions)
+
+
Modified: CalendarServer/branches/caladmin-tool/caladmin/script.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/script.py 2006-11-22 17:49:58 UTC (rev 552)
+++ CalendarServer/branches/caladmin-tool/caladmin/script.py 2006-11-22 18:47:23 UTC (rev 553)
@@ -58,14 +58,14 @@
def parseArgs(self, *rest):
self.params += rest
- def parseOptions(self, options=None):
- if not options:
- options = ['--help']
+ def parseOptions(self, opts=None):
+ if not opts:
+ opts = ['--help']
- if options == ['--help']:
+ if opts == ['--help']:
self.subCommands = options.genSubCommandsDef()
- usage.Options.parseOptions(self, options)
+ usage.Options.parseOptions(self, opts)
def postOptions(self):
if self.recursing:
Modified: CalendarServer/branches/caladmin-tool/caladmin/stats.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/stats.py 2006-11-22 17:49:58 UTC (rev 552)
+++ CalendarServer/branches/caladmin-tool/caladmin/stats.py 2006-11-22 18:47:23 UTC (rev 553)
@@ -45,30 +45,8 @@
from twistedcaldav import ical
-from caladmin.util import prepareByteValue
+from caladmin import util
-def getResourceType(fp):
- rt = 'WebDAV:{DAV:}resourcetype'
- x = xattr.xattr(fp.path)
- if not x.has_key(rt):
- return None
-
- collection = False
-
- type = None
-
- dom = microdom.parseString(x[rt])
- rt = microdom.getElementsByTagName(dom, 'resourcetype')
-
- for child in rt[0].childNodes:
- if child.tagName == 'collection':
- collection = True
- else:
- type = child.tagName
-
- return (collection, type)
-
-
class StatsAction(object):
def __init__(self, config):
self.config = config
@@ -91,58 +69,28 @@
self.getDiskUsage]
def getDiskUsage(self):
- output = commands.getoutput(' '.join(
- ['/usr/bin/du', '-s', self.root.path]))
+ return ("Disk Usage",
+ util.prepareByteValue(self.config,
+ util.getDiskUsage(self.root)))
- return ("Disk Usage", prepareByteValue(self.config,
- int(output.split()[0])))
-
- def _getPrincipalList(self, type):
- typeRoot = self.principalCollection.child(type)
- assert typeRoot.exists()
-
- pl = []
-
- for child in typeRoot.listdir():
- if child not in ['.db.sqlite']:
- pl.append(child)
-
- return pl
-
def getAccountCount(self):
- return ("# Accounts", len(self._getPrincipalList('users')))
+ return ("# Accounts",
+ len(util.getPrincipalList(
+ self.principalCollection,
+ 'users')))
def getGroupCount(self):
- return ("# Groups", len(self._getPrincipalList('groups')))
+ return ("# Groups",
+ len(util.getPrincipalList(
+ self.principalCollection,
+ 'groups')))
def getResourceCount(self):
- return ("# Resources", len(self._getPrincipalList('resources')))
+ return ("# Resources",
+ len(util.getPrincipalList(
+ self.principalCollection,
+ 'resources')))
- def _getDataCounts(self):
- calCount = 0
- eventCount = 0
- todoCount = 0
-
- for child in self.calendarCollection.walk():
- if child.isdir():
- if getResourceType(child) == (True, 'calendar'):
- calCount += 1
-
- 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)
@@ -162,7 +110,9 @@
assert self.root.exists()
stats = []
- self.calCount, self.eventCount, self.todoCount = self._getDataCounts()
+ (self.calCount,
+ self.eventCount,
+ self.todoCount) = util.getCalendarDataCounts(self.calendarCollection)
for gatherer in self.gatherers:
stats.append(gatherer())
Modified: CalendarServer/branches/caladmin-tool/caladmin/util.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/util.py 2006-11-22 17:49:58 UTC (rev 552)
+++ CalendarServer/branches/caladmin-tool/caladmin/util.py 2006-11-22 18:47:23 UTC (rev 553)
@@ -16,6 +16,14 @@
# DRI: David Reid, dreid at apple.com
##
+import xattr
+
+import commands
+
+from twisted.web import microdom
+
+from twistedcaldav import ical
+
def prepareByteValue(config, value):
if config['human']:
KB = value/1024.0
@@ -47,3 +55,75 @@
return '%5.2fKB' % (K,)
return value
+
+
+def getPrincipalList(principalCollection, type):
+ typeRoot = principalCollection.child(type)
+ assert typeRoot.exists()
+
+ pl = []
+
+ for child in typeRoot.listdir():
+ if child not in ['.db.sqlite']:
+ pl.append(typeRoot.child(child))
+
+ return pl
+
+
+def getDiskUsage(fp):
+
+ status, output = commands.getstatusoutput(
+ ' '.join(['/usr/bin/du', '-s', fp.path]))
+
+ if status != 0:
+ return 0
+
+ return int(output.split()[0])
+
+
+def getResourceType(fp):
+ rt = 'WebDAV:{DAV:}resourcetype'
+ x = xattr.xattr(fp.path)
+ if not x.has_key(rt):
+ return None
+
+ collection = False
+
+ type = None
+
+ dom = microdom.parseString(x[rt])
+ rt = microdom.getElementsByTagName(dom, 'resourcetype')
+
+ for child in rt[0].childNodes:
+ if child.tagName == 'collection':
+ collection = True
+ else:
+ type = child.tagName
+
+ return (collection, type)
+
+
+def getCalendarDataCounts(calendarCollection):
+ calCount = 0
+ eventCount = 0
+ todoCount = 0
+
+ for child in calendarCollection.walk():
+ if child.isdir():
+ if getResourceType(child) == (True, 'calendar'):
+ calCount += 1
+
+ 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061122/85d73a33/attachment.html
More information about the calendarserver-changes
mailing list