[CalendarServer-changes] [3879] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 17 16:11:30 PDT 2009
Revision: 3879
http://trac.macosforge.org/projects/calendarserver/changeset/3879
Author: wsanchez at apple.com
Date: 2009-03-17 16:11:30 -0700 (Tue, 17 Mar 2009)
Log Message:
-----------
Add warmup tool
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/util.py
Added Paths:
-----------
CalendarServer/trunk/bin/caldav_warmup
CalendarServer/trunk/calendarserver/tools/warmup.py
Copied: CalendarServer/trunk/bin/caldav_warmup (from rev 3878, CalendarServer/trunk/bin/caldav_export)
===================================================================
--- CalendarServer/trunk/bin/caldav_warmup (rev 0)
+++ CalendarServer/trunk/bin/caldav_warmup 2009-03-17 23:11:30 UTC (rev 3879)
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+##
+# Copyright (c) 2006-2007 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.
+##
+
+import sys
+
+#PYTHONPATH
+
+if __name__ == "__main__":
+ if "PYTHONPATH" in globals():
+ sys.path.insert(0, PYTHONPATH)
+ else:
+ from os.path import dirname, abspath, join
+ from subprocess import Popen, PIPE
+
+ home = dirname(dirname(abspath(__file__)))
+ run = join(home, "run")
+
+ child = Popen((run, "-p"), stdout=PIPE)
+ path, stderr = child.communicate()
+
+ if child.wait() == 0:
+ sys.path[0:0] = path.split(":")
+
+ from calendarserver.tools.warmup import main
+ main()
Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py 2009-03-17 18:38:57 UTC (rev 3878)
+++ CalendarServer/trunk/calendarserver/tools/util.py 2009-03-17 23:11:30 UTC (rev 3879)
@@ -66,6 +66,15 @@
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:
Added: CalendarServer/trunk/calendarserver/tools/warmup.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/warmup.py (rev 0)
+++ CalendarServer/trunk/calendarserver/tools/warmup.py 2009-03-17 23:11:30 UTC (rev 3879)
@@ -0,0 +1,183 @@
+#!/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 os
+import sys
+import sqlite3
+from getopt import getopt, GetoptError
+from os.path import dirname, abspath
+
+from twistedcaldav.resource import isPseudoCalendarCollectionResource
+from twistedcaldav.static import CalDAVFile, CalendarHomeFile
+from twistedcaldav.directory.directory import DirectoryService
+
+from calendarserver.tools.util import loadConfig, getDirectory, dummyDirectoryRecord
+
+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 " -c --collection: add a calendar collection"
+ 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:ac:H:r:u:", [
+ "config=",
+ "output=",
+ "help",
+ "all", "collection=", "home=", "record=", "user=",
+ ],
+ )
+ except GetoptError, e:
+ usage(e)
+
+ configFileName = None
+ outputFileName = None
+
+ calendarHomes = set()
+ records = set()
+ allRecords = False
+
+ 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 ("-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)
+
+ calendarCollections = set()
+
+ for calendarHome in calendarHomes:
+ #print calendarHome
+ #sys.stdout.write("*")
+ readProperties(calendarHome)
+
+ for childName in calendarHome.listChildren():
+ child = calendarHome.getChild(childName)
+ if isPseudoCalendarCollectionResource(child):
+ calendarCollections.add(child)
+
+ for calendarCollection in calendarCollections:
+ try:
+ for name, uid, type in calendarCollection.index().indexedSearch(None):
+ child = calendarCollection.getChild(name)
+
+ #sys.stdout.write("+")
+ childCalendar = child.iCalendarText()
+
+ readProperties(child)
+
+ except sqlite3.OperationalError:
+ # Outbox doesn't live on disk
+ if calendarCollection.fp.basename() != "outbox":
+ raise
+
+def readProperties(resource):
+ #sys.stdout.write("-")
+ for qname in resource.deadProperties().list():
+ property = resource.readDeadProperty(qname)
+ #sys.stdout.write(".")
+
+if __name__ == "__main__":
+ main()
Property changes on: CalendarServer/trunk/calendarserver/tools/warmup.py
___________________________________________________________________
Added: svn:executable
+ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090317/7e92678a/attachment-0001.html>
More information about the calendarserver-changes
mailing list