[CalendarServer-changes] [548] CalendarServer/branches/caladmin-tool/caladmin

source_changes at macosforge.org source_changes at macosforge.org
Tue Nov 21 22:41:42 PST 2006


Revision: 548
          http://trac.macosforge.org/projects/calendarserver/changeset/548
Author:   dreid at apple.com
Date:     2006-11-21 22:41:41 -0800 (Tue, 21 Nov 2006)

Log Message:
-----------
don't load action until postOptions has been reached, add h k and m options to quotas

Modified Paths:
--------------
    CalendarServer/branches/caladmin-tool/caladmin/commands.py
    CalendarServer/branches/caladmin-tool/caladmin/quotas.py

Modified: CalendarServer/branches/caladmin-tool/caladmin/commands.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/commands.py	2006-11-22 06:32:44 UTC (rev 547)
+++ CalendarServer/branches/caladmin-tool/caladmin/commands.py	2006-11-22 06:41:41 UTC (rev 548)
@@ -48,21 +48,23 @@
 
     params = ()
 
-    def __init__(self):
-        self._action = reflect.namedAny(self.action)
-        usage.Options.__init__(self)
-
     def parseArgs(self, *rest):
         self.params += rest
 
     def postOptions(self):
-        self._action(self).run()
+        reflect.namedAny(self.action)(self).run()
 
 
 class QuotaOptions(SubCommand):
     name = 'quotas'
     help = 'Retrieve quota information for principals'
     action = 'caladmin.quotas.QuotaAction'
+
+    optFlags = [
+        ['human', 'h', 'Display quota values in a human readable form.'],
+        ['megabytes', 'm', 'Display quota values in megabytes'],
+        ['kilobytes', 'k', 'Display quota values in kilobytes'],
+        ]
          
     def __init__(self):
         SubCommand.__init__(self)
@@ -129,15 +131,32 @@
 
 registerCommand(StatsOptions)
 
+from twisted.python import filepath
 
 class LogOptions(SubCommand):
     name = 'logs'
     help = ('Gather and report useful information from the logfiles.')
     action = 'caladmin.logs.LogAction'
 
-    optParameters = [
-        ['logfile', 'L', '/var/caldavd/server.log', 
-         'Path to the log file to analyze'],
-        ]
+    def __init__(self):
+        SubCommand.__init__(self)
 
+        self['logfile'] = None
+
+    def opt_logfile(self, logfile):
+        """Path to the log file to be analyzed.
+        [default: /var/log/caldavd/server.log]
+        """ 
+
+        self['logfile'] = filepath.FilePath(logfile)
+
+    opt_l = opt_logfile
+
+    def postOptions(self):
+        if not self['logfile']:
+            self['logfile'] = filepath.FilePath(
+                self.parent.config['ServerLogFile'])
+
+        SubCommand.postOptions(self)
+
 registerCommand(LogOptions)

Modified: CalendarServer/branches/caladmin-tool/caladmin/quotas.py
===================================================================
--- CalendarServer/branches/caladmin-tool/caladmin/quotas.py	2006-11-22 06:32:44 UTC (rev 547)
+++ CalendarServer/branches/caladmin-tool/caladmin/quotas.py	2006-11-22 06:41:41 UTC (rev 548)
@@ -56,6 +56,29 @@
         self.principalCollection = config.parent.principalCollection
         self.formatter = config.parent.formatter
 
+    def prepareValue(self, value):
+        if self.config['human']:
+            h = value/1024.0
+            if h < 1:
+                return '%d' % (value,)
+
+            h2 = h/1024.0
+            if h2 < 1:
+                return '%5.2fKB' % (h,)
+
+            return '%5.2fMB' % (h2,)
+
+        elif self.config['megabytes']:
+            M = value/1024.0/1024.0
+
+            return '%5.2fMB' % (M,)
+
+        elif self.config['kilobytes']:
+            K = value/1024.0
+            return '%5.2fKB' % (K,)
+
+        return value
+
     def getQuotaStats(self):
 
         defaultQuota = getQuotaRoot(self.calendarCollection)
@@ -93,9 +116,9 @@
 
                 yield (child.basename(),
                        type,
-                       childQuota,
-                       childUsed,
-                       childAvailable)
+                       self.prepareValue(childQuota),
+                       self.prepareValue(childUsed),
+                       self.prepareValue(childAvailable))
     
     def run(self):
         if not self.config['types']:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061121/9d46ffba/attachment.html


More information about the calendarserver-changes mailing list