[CalendarServer-changes] [645] CalendarServer/branches/caladmin-tool-2

source_changes at macosforge.org source_changes at macosforge.org
Fri Dec 1 14:27:37 PST 2006


Revision: 645
          http://trac.macosforge.org/projects/calendarserver/changeset/645
Author:   dreid at apple.com
Date:     2006-12-01 14:27:37 -0800 (Fri, 01 Dec 2006)

Log Message:
-----------
Merge changes for caldavd and comply with various changes to the default data store layout

Modified Paths:
--------------
    CalendarServer/branches/caladmin-tool-2/caladmin/formatters.py
    CalendarServer/branches/caladmin-tool-2/caladmin/logs.py
    CalendarServer/branches/caladmin-tool-2/caladmin/options.py
    CalendarServer/branches/caladmin-tool-2/caladmin/purge.py
    CalendarServer/branches/caladmin-tool-2/caladmin/script.py
    CalendarServer/branches/caladmin-tool-2/caladmin/stats.py
    CalendarServer/branches/caladmin-tool-2/conf/caldavd.plist
    CalendarServer/branches/caladmin-tool-2/twistedcaldav/caldavd.py

Modified: CalendarServer/branches/caladmin-tool-2/caladmin/formatters.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/caladmin/formatters.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/caladmin/formatters.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -133,7 +133,7 @@
 
         self.writeTable(report, fields, headings)
 
-    report_users = report_groups = report_resources = report_principals
+    report_user = report_group = report_resource = report_principals
 
     def report_stats(self, report):
         fields = ('accountCount', 'groupCount', 'calendarCount', 'eventCount', 
@@ -199,7 +199,7 @@
         self.writeDict(self.options['fieldnames'],
                        report['records'])
         
-    report_users = report_groups = report_resources = report_principals
+    report_user = report_group = report_resource = report_principals
 
     def report_stats(self, report):
         if 'fieldnames' not in self.options:
@@ -225,7 +225,7 @@
 
         plistlib.writePlist(plist, self.dest)
 
-    report_users = report_groups = report_resources = report_principals
+    report_user = report_group = report_resource = report_principals
 
     def report_stats(self, report):
         plist = plistlib.Dict()

Modified: CalendarServer/branches/caladmin-tool-2/caladmin/logs.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/caladmin/logs.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/caladmin/logs.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -31,7 +31,6 @@
 statsTemplate = plistlib.Dict(
     bytesOut=0, 
     requestCounts=plistlib.Dict(
-        PROPFIND=0,
         ), 
     invitations=plistlib.Dict(
         day=0, 
@@ -41,7 +40,6 @@
     userAgents=plistlib.Dict(),
     )
 
-
 class Stats(object):
     def __init__(self, fp):
         self.fp = fp
@@ -130,7 +128,7 @@
         self.readOnly = self.config['readonly']
 
         self.logfile = self.config['logfile']
-        self.stats = Stats(self.config['stats'])
+        self.stats = Stats(self.config['statsfile'])
 
     def run(self):
 

Modified: CalendarServer/branches/caladmin-tool-2/caladmin/options.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/caladmin/options.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/caladmin/options.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -94,7 +94,7 @@
 
 
 from twisted.python import filepath
-from twistedcaldav.caldavd import caldavd_defaults
+from twistedcaldav.caldavd import DEFAULTS
 
 class LogOptions(SubCommand):
     name = 'logs'
@@ -110,16 +110,11 @@
         PARAM_GIGA,
         ]
     
-    optParameters = [
-        ['stats', 's', caldavd_defaults['ServerStatsFile'],
-         ('Path to destination file for statistics. Note: Stats will be '
-          'updated if this file already exists.')],
-        ]
-
     def __init__(self):
         SubCommand.__init__(self)
 
         self['logfile'] = None
+        self['statsfile'] = None
 
     def opt_logfile(self, path):
         """Path to input logfile
@@ -127,6 +122,11 @@
 
         self['logfile'] = path
 
+    def opt_statsfile(self, path):
+        """Path to destination statistics plist
+        """
+        self['statsfile'] = path
+
     def postOptions(self):
         if not self['logfile']:
             self['logfile'] = filepath.FilePath(
@@ -134,7 +134,11 @@
         else:
             self['logfile'] = filepath.FilePath(self['logfile'])
 
-        self['stats'] = filepath.FilePath(self['stats'])
+        if not self['statsfile']:
+            self['statsfile'] = filepath.FilePath(
+                self.parent.config['ServerStatsFile'])
+        else:
+            self['statsfile'] = filepath.FilePath(self['statsfile'])
 
         SubCommand.postOptions(self)
 
@@ -161,21 +165,21 @@
 
 
 class UserOptions(PrincipalOptions):
-    name = "users"
+    name = "user"
     help = PrincipalOptions.help % (name,)
 
 registerCommand(UserOptions)
 
 
 class GroupOptions(PrincipalOptions):
-    name = "groups"
+    name = "group"
     help = PrincipalOptions.help % (name,)
 
 registerCommand(GroupOptions)
 
 
 class ResourceOptions(PrincipalOptions):
-    name = "resources"
+    name = "resource"
     help = PrincipalOptions.help % (name,)
 
 registerCommand(ResourceOptions)

Modified: CalendarServer/branches/caladmin-tool-2/caladmin/purge.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/caladmin/purge.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/caladmin/purge.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -93,7 +93,7 @@
                 collections.extend(type.children())
                     
         purgeDate = datetime.date.today()
-        purgeDate = purgeDate - datetime.timedelta(self.config['days'])
+        purgeDate = purgeDate - datetime.timedelta(int(self.config['days']))
 
         for collection in collections:
             purgeEvents(collection, purgeDate)

Modified: CalendarServer/branches/caladmin-tool-2/caladmin/script.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/caladmin/script.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/caladmin/script.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -38,7 +38,7 @@
 from caladmin import options
 from caladmin import formatters
 
-from twistedcaldav.caldavd import caldavd_defaults, caldavd
+from twistedcaldav.caldavd import DEFAULTS, caldavd
 
 class AdminOptions(usage.Options):
     recursing = 0
@@ -92,7 +92,7 @@
                                        err.strerror))
                 sys.stderr.flush()
 
-                self.config = caldavd_defaults
+                self.config = DEFAULTS
 
         self.root = filepath.FilePath(self.config['DocumentRoot'])
         self.calendarCollection = self.root.child('calendars')

Modified: CalendarServer/branches/caladmin-tool-2/caladmin/stats.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/caladmin/stats.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/caladmin/stats.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -61,19 +61,19 @@
         return ("accountCount", 
                 len(util.getPrincipalList(
                     self.principalCollection,
-                    'users')))
+                    'user')))
 
     def getGroupCount(self):
         return ("groupCount", 
                 len(util.getPrincipalList(
                     self.principalCollection,
-                    'groups')))
+                    'group')))
 
     def getResourceCount(self):
         return ("resourceCount", 
                 len(util.getPrincipalList(
                     self.principalCollection,
-                    'resources')))
+                    'resource')))
 
     def run(self):
         assert self.root.exists()

Modified: CalendarServer/branches/caladmin-tool-2/conf/caldavd.plist
===================================================================
--- CalendarServer/branches/caladmin-tool-2/conf/caldavd.plist	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/conf/caldavd.plist	2006-12-01 22:27:37 UTC (rev 645)
@@ -51,7 +51,7 @@
   <string>/var/log/caldavd/server.log</string>
 
   <key>ServerStatsFile</key>
-  <string>/Library/CalendarServer/Documents</string>
+  <string>/Library/CalendarServer/Documents/stats.plist</string>
 
   <key>ErrorLogFile</key>
   <string>/var/log/caldavd/error.log</string>

Modified: CalendarServer/branches/caladmin-tool-2/twistedcaldav/caldavd.py
===================================================================
--- CalendarServer/branches/caladmin-tool-2/twistedcaldav/caldavd.py	2006-12-01 21:58:59 UTC (rev 644)
+++ CalendarServer/branches/caladmin-tool-2/twistedcaldav/caldavd.py	2006-12-01 22:27:37 UTC (rev 645)
@@ -40,34 +40,36 @@
 Parse the command line and read in a configuration file and then launch the server.
 """
 
-caldavd_defaults = {
+DEFAULTS = {
+    'CreateAccounts': False,
+    'DirectoryService': {'params': {'node': '/Search'},
+                         'type': 'OpenDirectoryService'},
+    'DocumentRoot': '/Library/CalendarServer/Documents',
+    'DropBoxEnabled': True,
+    'DropBoxInheritedACLs': True,
+    'DropBoxName': 'dropbox',
+    'ErrorLogFile': '/var/log/caldavd/error.log',
+    'ManholePort': 0,
+    'MaximumAttachmentSizeBytes': 1048576,
+    'NotificationCollectionName': 'notifications',
+    'NotificationsEnabled': False,
+    'PIDFile': '/var/run/caldavd.pid',
+    'Port': 8008,
+    'Repository': '/etc/caldavd/repository.xml',
+    'ResetAccountACLs': False,
+    'RunStandalone': True,
+    'SSLCertificate': '/etc/certificates/Default.crt',
+    'SSLEnable': False,
+    'SSLOnly': False,
+    'SSLPort': 8443,
+    'SSLPrivateKey': '/etc/certificates/Default.key',
+    'ServerLogFile': '/var/log/caldavd/server.log',
+    'ServerStatsFile': '/Library/CalendarServer/Documents/stats.plist',
+    'UserQuotaBytes': 104857600,
     'Verbose': False,
-    "RunStandalone": True,
-    "DocumentRoot": "/Library/CalendarServer/Documents",
-    "Port": 8008,
-    "SSLEnable": False,
-    "SSLPort": 8443,
-    "SSLOnly": False,
-    "SSLPrivateKey": "/etc/certificates/Default.key",
-    "SSLCertificate": "/etc/certificates/Default.crt",
-    "ManholePort": 0,           
-    "DropBoxEnabled": True,
-    "DropBoxName": "dropbox",
-    "DropBoxInheritedACLs": True,
-    "NotificationsEnabled": False,
-    "NotificationCollectionName": "notifications",
-    "ServerLogFile": "/var/log/caldavd/server.log",
-    "ServerStatsFile": "/Library/CalendarServer/stats.plist",
-    "ErrorLogFile": "/var/log/caldavd/error.log",
-    "PIDFile": "/var/run/caldavd.pid",
-    "Repository": "etc/caldavd/repository.xml",
-    "CreateAccounts": False,
-    "ResetAccountACLs": False,
-    "twistdLocation": "/usr/share/caldavd/bin/twistd",
-    "MaximumAttachmentSizeBytes": 1048576,
-    "UserQuotaBytes": 104857600,
-    }
+    'twistdLocation': '/usr/share/caldavd/bin/twistd'}
 
+
 class caldavd(object):
     """
     Runs the caldav server.
@@ -76,6 +78,9 @@
     def __init__(self):
         # Option defaults
         self.plistfile = "/etc/caldavd/caldavd.plist"
+
+        self.config = DEFAULTS.copy()
+
         self.action = None
     
     def printit(self):
@@ -87,28 +92,30 @@
         print ""
         print "Configuration File:               %s" % (self.plistfile,)
         print ""
-        print "Run as daemon:                    %s" % (self.daemonize,)
-        print "Document Root:                    %s" % (self.docroot,)
-        print "Repository Configuration:         %s" % (self.repo,)
-        print "Generate Accounts in Repository:  %s" % (self.doacct,)
-        print "Reset ACLs on Generated Accounts: %s" % (self.doacl,)
-        print "Non-ssl Port:                     %s" % (self.port,)
-        print "Use SSL:                          %s" % (self.dossl,)
-        print "SSL Port:                         %s" % (self.sslport,)
-        print "Only Use SSL:                     %s" % (self.onlyssl,)
-        print "SSL Private Key File:             %s" % (self.keyfile,)
-        print "SSL Certificate File:             %s" % (self.certfile,)
-        print "Drop Box Enabled:                 %s" % (self.dropbox,)
-        print "Drop Box Name:                    %s" % (self.dropboxName,)
-        print "Drop Box ACLs are Inherited       %s" % (self.dropboxACLs,)
-        print "Notifications Enabled:            %s" % (self.notifications,)
-        print "Notification Collection Name:     %s" % (self.notifcationName,)
-        print "Server Log File:                  %s" % (self.serverlogfile,)
-        print "Error Log File:                   %s" % (self.errorlogfile,)
-        print "PID File:                         %s" % (self.pidfile,)
-        print "twistd Location:                  %s" % (self.twistd,)
-        print "Maximum Calendar Resource Size:   %d bytes" % (self.maxsize,)
-        print "Global per-user quota limit:      %d bytes" % (self.quota,)
+        print "Run as daemon:                    %s" % (self.config['RunStandalone'],)
+        print "Document Root:                    %s" % (self.config['DocumentRoot'],)
+        print "Repository Configuration:         %s" % (self.config['Repository'],)
+        print "Generate Accounts in Repository:  %s" % (self.config['CreateAccounts'],)
+        print "Reset ACLs on Generated Accounts: %s" % (self.config['ResetAccountACLs'],)
+        print "Non-ssl Port:                     %s" % (self.config['Port'],)
+        print "Use SSL:                          %s" % (self.config['SSLEnable'],)
+        print "SSL Port:                         %s" % (self.config['SSLPort'],)
+        print "Only Use SSL:                     %s" % (self.config['SSLOnly'],)
+        print "SSL Private Key File:             %s" % (self.config['SSLPrivateKey'],)
+        print "SSL Certificate File:             %s" % (self.config['SSLCertificate'],)
+        print "Directory Service:                %s" % (self.config['DirectoryService']["type"],)
+        print "Directory Service Parameters:     %r" % (self.config['DirectoryService']["params"],)
+        print "Drop Box Enabled:                 %s" % (self.config['DropBoxEnabled'],)
+        print "Drop Box Name:                    %s" % (self.config['DropBoxName'],)
+        print "Drop Box ACLs are Inherited       %s" % (self.config['DropBoxInheritedACLs'],)
+        print "Notifications Enabled:            %s" % (self.config['NotificationsEnabled'],)
+        print "Notification Collection Name:     %s" % (self.config['NotificationCollectionName'],)
+        print "Server Log File:                  %s" % (self.config['ServerLogFile'],)
+        print "Error Log File:                   %s" % (self.config['ErrorLogFile'],)
+        print "PID File:                         %s" % (self.config['PIDFile'],)
+        print "twistd Location:                  %s" % (self.config['twistdLocation'],)
+        print "Maximum Calendar Resource Size:   %d bytes" % (self.config['MaximumAttachmentSizeBytes'],)
+        print "Global per-user quota limit:      %d bytes" % (self.config['UserQuotaBytes'],)
 
     def run(self):
         """
@@ -145,11 +152,11 @@
         
         # Create arguments for twistd
         args = [os.path.basename(sys.executable)]
-        args.append(self.twistd)
-        if not self.daemonize:
+        args.append(self.config['twistdLocation'])
+        if not self.config['RunStandalone']:
             args.append("-n")
-        args.append("--logfile=%s" % (self.errorlogfile,))
-        args.append("--pidfile=%s" % (self.pidfile,))
+        args.append("--logfile=%s" % (self.config['ErrorLogFile'],))
+        args.append("--pidfile=%s" % (self.config['PIDFile'],))
         args.append("-y")
         args.append(tac)
 
@@ -176,11 +183,11 @@
         Stop the caldavd server.
         """
         
-        if os.path.exists(self.pidfile):
+        if os.path.exists(self.config['PIDFile']):
             try:
-                pid = int(open(self.pidfile).read())
+                pid = int(open(self.config['PIDFile']).read())
             except ValueError:
-                sys.exit("Pidfile %s contains non-numeric value" % self.pidfile)
+                sys.exit("Pidfile %s contains non-numeric value" % self.config['PIDFile'])
             try:
                 print "Stopping CalDAV Server",
                 os.kill(pid, signal.SIGTERM)
@@ -225,14 +232,14 @@
                 self.usage()
                 return
             elif option == "-v":
-                self.verbose = True
+                self.config['Verbose'] = True
             elif option == "-f":
                 # We should have handled this already
                 pass
             elif option == "-X":
-                self.daemonize = False
+                self.config['RunStandalone'] = False
             elif option == "-T":
-                self.twistd = value
+                self.config['twistdLocation'] = value
             elif option == "-p":
                 do_print = True
             else:
@@ -266,43 +273,13 @@
         self.action = args[0]
     
     def parsePlist(self):
-    	print "Reading configuration file %s." % (self.plistfile,)
+        print "Reading configuration file %s." % (self.plistfile,)
 
         root = readPlist(self.plistfile)
         
-        # dict that maps between plist keys and class attributes
-        mapper = {
-                   "Verbose":                    "verbose",
-                   "RunStandalone":              "daemonize",
-                   "DocumentRoot":               "docroot",
-                   "Port":                       "port",
-                   "SSLEnable":                  "dossl",
-                   "SSLPort":                    "sslport",
-                   "SSLOnly":                    "onlyssl",
-                   "SSLPrivateKey":              "keyfile",
-                   "SSLCertificate":             "certfile",
-                   "ManholePort":                "manhole",
-                   "DropBoxEnabled":             "dropbox",
-                   "DropBoxName":                "dropboxName",
-                   "DropBoxInheritedACLs":       "dropboxACLs",
-                   "NotificationsEnabled":       "notifications",
-                   "NotificationCollectionName": "notifcationName",
-                   "ServerLogFile":              "serverlogfile",
-                   "ErrorLogFile":               "errorlogfile",
-                   "PIDFile":                    "pidfile",
-                   "Repository":                 "repo",
-                   "CreateAccounts":             "doacct",
-                   "ResetAccountACLs":           "doacl",
-                   "twistdLocation":             "twistd",
-                   "MaximumAttachmentSizeBytes": "maxsize",
-                   "UserQuotaBytes":             "quota",
-                  }
-        
         for k,v in root.items():
-            if mapper.has_key(k) and hasattr(self, mapper[k]):
-                setattr(self, mapper[k], v)
-            elif caldavd_defaults.has_key(k) and hasattr(self, mapper[k]):
-                setattr(self, mapper[k], caldavd_defaults[k])
+            if k in self.config:
+                self.config[k] = v
             else:
                 print "Unknown option: %s" % (k,)
 
@@ -310,30 +287,30 @@
         
         result = True
 
-        if not os.path.exists(self.docroot):
-            print "Document Root does not exist: %s" % (self.docroot,)
+        if not os.path.exists(self.config['DocumentRoot']):
+            print "Document Root does not exist: %s" % (self.config['DocumentRoot'],)
             result = False
 
-        if not os.path.exists(self.repo):
-            print "Repository File does not exist: %s" % (self.repo,)
+        if not os.path.exists(self.config['Repository']):
+            print "Repository File does not exist: %s" % (self.config['Repository'],)
             result = False
 
-        if self.dossl and not os.path.exists(self.keyfile):
-            print "SSL Private Key File does not exist: %s" % (self.keyfile,)
+        if self.config['SSLEnable'] and not os.path.exists(self.config['SSLPrivateKey']):
+            print "SSL Private Key File does not exist: %s" % (self.config['SSLPrivateKey'],)
             result = False
 
-        if self.dossl and not os.path.exists(self.certfile):
-            print "SSL Certificate File does not exist: %s" % (self.certfile,)
+        if self.config['SSLEnable'] and not os.path.exists(self.config['SSLCertificate']):
+            print "SSL Certificate File does not exist: %s" % (self.config['SSLCertificate'],)
             result = False
 
-        if not self.dossl and self.onlyssl:
-            self.dossl = True
+        if not self.config['SSLEnable'] and self.config['SSLOnly']:
+            self.config['SSLEnable'] = True
 
-        if not self.daemonize:
-            self.errorlogfile = "-"
+        if not self.config['RunStandalone']:
+            self.config['ErrorLogFile'] = "-"
 
-        if not os.path.exists(self.twistd):
-            print "twistd does not exist: %s" % (self.twistd,)
+        if not os.path.exists(self.config['twistdLocation']):
+            print "twistd does not exist: %s" % (self.config['twistdLocation'],)
             result = False
             
         return result
@@ -354,45 +331,33 @@
         return """
 from twistedcaldav.repository import startServer
 
-application, site = startServer(%(docroot)s,
-                                %(repo)s,
-                                %(doacct)s,
-                                %(doacl)s,
-                                %(dossl)s,
-                                %(keyfile)s,
-                                %(certfile)s,
-                                %(onlyssl)s,
-                                %(port)d,
-                                %(sslport)d,
-                                %(maxsize)d,
-                                %(quota)s=d,
-                                %(serverlogfile)s,
-                                %(dropbox)s,
-                                %(dropboxName)s,
-                                %(dropboxACLs)s,
-                                %(notifications)s,
-                                %(notifcationName)s,
-                                %(manhole)d)
+application, site = startServer(
+    %(DocumentRoot)r,
+    %(Repository)r,
+    %(CreateAccounts)s,
+    %(ResetAccountACLs)s,
+    %(SSLEnable)s,
+    %(SSLPrivateKey)r,
+    %(SSLCertificate)r,
+    %(SSLOnly)s,
+    %(Port)d,
+    %(SSLPort)d,
+    %(MaximumAttachmentSizeBytes)d,
+    %(UserQuotaBytes)d,
+    %(ServerLogFile)r,
+    %(DirectoryService)r,
+    %(DropBoxEnabled)r,
+    %(DropBoxName)r,
+    %(DropBoxInheritedACLs)r,
+    %(NotificationsEnabled)r,
+    %(NotificationCollectionName)r,
+    %(ManholePort)d,
+)
+""" % self.config
 
-""" % {
-    "docroot":         self.docroot,
-    "repo":            self.repo,
-    "doacct":          self.doacct,
-    "doacl":           self.doacl,
-    "dossl":           self.dossl,
-    "keyfile":         self.keyfile,
-    "certfile":        self.certfile,
-    "onlyssl":         self.onlyssl,
-    "port":            self.port,
-    "sslport":         self.sslport,
-    "maxsize":         self.maxsize,
-    "quota":           self.quota,
-    "serverlogfile":   self.serverlogfile,
-    "dropbox":         self.dropbox,
-    "dropboxName":     self.dropboxName,
-    "dropboxACLs":     self.dropboxACLs,
-    "notifications":   self.notifications,
-    "notifcationName": self.notifcationName,
-    "manhole":         self.manhole,
-    
-}
+
+if __name__ == "__main__":
+    try:
+        caldavd().run()
+    except Exception, e:
+        sys.exit(str(e))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061201/00ceb7c1/attachment.html


More information about the calendarserver-changes mailing list