[CalendarServer-changes] [3931] CalendarServer/branches/users/wsanchez/deployment/bin
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 27 12:29:18 PDT 2009
Revision: 3931
http://trac.macosforge.org/projects/calendarserver/changeset/3931
Author: wsanchez at apple.com
Date: 2009-03-27 12:29:18 -0700 (Fri, 27 Mar 2009)
Log Message:
-----------
Put these where I won't lose them
Added Paths:
-----------
CalendarServer/branches/users/wsanchez/deployment/bin/caldav_warmup
CalendarServer/branches/users/wsanchez/deployment/bin/do_warmup
Added: CalendarServer/branches/users/wsanchez/deployment/bin/caldav_warmup
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/bin/caldav_warmup (rev 0)
+++ CalendarServer/branches/users/wsanchez/deployment/bin/caldav_warmup 2009-03-27 19:29:18 UTC (rev 3931)
@@ -0,0 +1,282 @@
+#!/usr/bin/env python
+
+##
+# Copyright (c) 2006-2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+This tool trawls through the server's data store, reading data.
+
+This is useful for ensuring that any on-demand data format upgrades
+are done.
+
+This tool requires access to the calendar server's configuration and
+data storage.
+"""
+
+import sys
+
+sys.path.insert(0, "/usr/share/caldavd/lib/python")
+
+import os
+import sqlite3
+from getopt import getopt, GetoptError
+from os.path import dirname, abspath
+
+from twisted.python import log
+from twisted.python.reflect import namedClass
+
+from twistedcaldav.resource import isPseudoCalendarCollectionResource
+from twistedcaldav.static import CalDAVFile, CalendarHomeFile
+from twistedcaldav.config import config, defaultConfigFile
+from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
+
+def loadConfig(configFileName):
+ if configFileName is None:
+ configFileName = defaultConfigFile
+
+ if not os.path.isfile(configFileName):
+ sys.stderr.write("No config file: %s\n" % (configFileName,))
+ sys.exit(1)
+
+ config.loadConfig(configFileName)
+
+ return config
+
+def getDirectory():
+ BaseDirectoryService = namedClass(config.DirectoryService["type"])
+
+ class MyDirectoryService (BaseDirectoryService):
+ def getPrincipalCollection(self):
+ if not hasattr(self, "_principalCollection"):
+ #
+ # Instantiating a CalendarHomeProvisioningResource with a directory
+ # will register it with the directory (still smells like a hack).
+ #
+ # We need that in order to locate calendar homes via the directory.
+ #
+ from twistedcaldav.static import CalendarHomeProvisioningFile
+ CalendarHomeProvisioningFile(os.path.join(config.DocumentRoot, "calendars"), self, "/calendars/")
+
+ from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+ self._principalCollection = DirectoryPrincipalProvisioningResource("/principals/", self)
+
+ return self._principalCollection
+
+ def setPrincipalCollection(self, coll):
+ # See principal.py line 237: self.directory.principalCollection = self
+ pass
+
+ principalCollection = property(getPrincipalCollection, setPrincipalCollection)
+
+ def calendarHomeForRecord(self, record):
+ principal = self.principalCollection.principalForRecord(record)
+ if principal:
+ try:
+ return principal._calendarHome()
+ except AttributeError:
+ pass
+ return None
+
+ def calendarHomeForShortName(self, recordType, shortName):
+ principal = self.principalCollection.principalForShortName(recordType, shortName)
+ if principal:
+ try:
+ return principal._calendarHome()
+ except AttributeError:
+ pass
+ return None
+
+ def principalForCalendarUserAddress(self, cua):
+ return self.principalCollection.principalForCalendarUserAddress(cua)
+
+
+ return MyDirectoryService(**config.DirectoryService["params"])
+
+class DummyDirectoryService (DirectoryService):
+ realmName = ""
+ baseGUID = "51856FD4-5023-4890-94FE-4356C4AAC3E4"
+ def recordTypes(self): return ()
+ def listRecords(self): return ()
+ def recordWithShortName(self): return None
+
+dummyDirectoryRecord = DirectoryRecord(
+ service = DummyDirectoryService(),
+ recordType = "dummy",
+ guid = "8EF0892F-7CB6-4B8E-B294-7C5A5321136A",
+ shortName = "dummy",
+ fullName = "Dummy McDummerson",
+ calendarUserAddresses = set(),
+ autoSchedule = False,
+)
+
+class UsageError (StandardError):
+ pass
+
+def usage(e=None):
+ if e:
+ print e
+ print ""
+
+ name = os.path.basename(sys.argv[0])
+ print "usage: %s [options] [input_specifiers]" % (name,)
+ print ""
+ print "Warm up data store by reading everything once."
+ print __doc__
+ print "options:"
+ print " -h --help: print this help and exit"
+ print " -f --config: Specify caldavd.plist configuration path"
+ print ""
+ print "input specifiers:"
+ print " -a --all: add all calendar homes"
+ print " -H --home: add a calendar home (and all calendars within it)"
+ print " -r --record: add a directory record's calendar home (format: 'recordType:shortName')"
+ print " -u --user: add a user's calendar home (shorthand for '-r users:shortName')"
+
+ if e:
+ sys.exit(64)
+ else:
+ sys.exit(0)
+
+def main():
+ try:
+ (optargs, args) = getopt(
+ sys.argv[1:], "hf:o:aH:r:u:F", [
+ "config=",
+ "output=",
+ "help",
+ "all", "home=", "record=", "user=",
+ ],
+ )
+ except GetoptError, e:
+ usage(e)
+
+ configFileName = None
+ outputFileName = None
+
+ calendarHomes = set()
+ records = set()
+ allRecords = False
+ readCalendarData = True
+
+ observer = log.FileLogObserver(open("/ngs/app/icalt/warmup/warmup.log", "a"))
+ log.addObserver(observer.emit)
+
+ def checkExists(resource):
+ if not resource.exists():
+ sys.stderr.write("No such file: %s\n" % (resource.fp.path,))
+ sys.exit(1)
+
+ for opt, arg in optargs:
+ if opt in ("-h", "--help"):
+ usage()
+
+ elif opt in ("-f", "--config"):
+ configFileName = arg
+
+ elif opt in ("-a", "--all"):
+ allRecords = True
+
+ elif opt in ("-F",):
+ readCalendarData = False
+
+ elif opt in ("-H", "--home"):
+ path = abspath(arg)
+ parent = CalDAVFile(dirname(abspath(path)))
+ calendarHome = CalendarHomeFile(arg, parent, dummyDirectoryRecord)
+ checkExists(calendarHome)
+ calendarHomes.add(calendarHome)
+
+ elif opt in ("-r", "--record"):
+ try:
+ recordType, shortName = arg.split(":", 1)
+ if not recordType or not shortName:
+ raise ValueError()
+ except ValueError:
+ sys.stderr.write("Invalid record identifier: %r\n" % (arg,))
+ sys.exit(1)
+
+ records.add((recordType, shortName))
+
+ elif opt in ("-u", "--user"):
+ records.add((DirectoryService.recordType_users, arg))
+
+ if args:
+ usage("Too many arguments: %s" % (" ".join(args),))
+
+ if records or allRecords:
+ config = loadConfig(configFileName)
+ directory = getDirectory()
+
+ for record in records:
+ recordType, shortName = record
+ calendarHome = directory.calendarHomeForShortName(recordType, shortName)
+ if not calendarHome:
+ sys.stderr.write("No calendar home found for record: (%s)%s\n" % (recordType, shortName))
+ sys.exit(1)
+ calendarHomes.add(calendarHome)
+
+ if allRecords:
+ for record in directory.allRecords():
+ calendarHome = directory.calendarHomeForRecord(record)
+ if not calendarHome:
+ pass
+ else:
+ calendarHomes.add(calendarHome)
+
+ n = 0
+ N = len(calendarHomes)
+ for calendarHome in calendarHomes:
+ n += 1
+ log.msg("%.2f%% (%d of %d)" % (100.0 * n/N, n, N))
+ processCalendarHome(calendarHome, readCalendarData=readCalendarData)
+
+def processCalendarHome(calendarHome, readCalendarData=True):
+ readProperties(calendarHome)
+
+ for childName in calendarHome.listChildren():
+ child = calendarHome.getChild(childName)
+ if isPseudoCalendarCollectionResource(child):
+ if childName in ("inbox", "outbox"):
+ child.provision()
+ processCalendar(child, readCalendarData=readCalendarData)
+
+def processCalendar(calendarCollection, readCalendarData=True):
+ readProperties(calendarCollection)
+
+ try:
+ for name, uid, type in calendarCollection.index().search(None):
+ child = calendarCollection.getChild(name)
+
+ if readCalendarData:
+ childCalendar = child.iCalendarText()
+ readProperties(child)
+
+ except sqlite3.OperationalError:
+ # Outbox doesn't live on disk
+ if calendarCollection.fp.basename() != "outbox":
+ raise
+
+def readProperties(resource):
+ log.msg(resource)
+ for qname in tuple(resource.deadProperties().list()):
+ try:
+ property = resource.readDeadProperty(qname)
+ except Exception, e:
+ log.err("Error reading {%s}%s property on resource %s\n%s\n" % (qname[0], qname[1], resource, e))
+ resource.removeDeadProperty(qname)
+
+if __name__ == "__main__":
+ main()
Property changes on: CalendarServer/branches/users/wsanchez/deployment/bin/caldav_warmup
___________________________________________________________________
Added: svn:executable
+ *
Added: CalendarServer/branches/users/wsanchez/deployment/bin/do_warmup
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/bin/do_warmup (rev 0)
+++ CalendarServer/branches/users/wsanchez/deployment/bin/do_warmup 2009-03-27 19:29:18 UTC (rev 3931)
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+set -e
+set -u
+
+if [ "$(whoami)" != "_calendar" ]; then
+ echo "Must be calendar user, not $(whoami).";
+ exit 1;
+fi;
+
+cd /Library/CalendarServer/Documents/calendars/__uids__;
+
+for d in $(find . -depth 1); do
+ args="";
+ for h in "${d}"/*/*; do
+ args="${args} --home ${h}";
+ done;
+ /ngs/app/icalt/caldav_warmup ${args} &
+done;
Property changes on: CalendarServer/branches/users/wsanchez/deployment/bin/do_warmup
___________________________________________________________________
Added: svn:executable
+ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090327/92534252/attachment-0001.html>
More information about the calendarserver-changes
mailing list