[CalendarServer-changes] [11101] CalendarServer/branches/users/cdaboo/store-scheduling
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 26 08:54:09 PDT 2013
Revision: 11101
http://trac.calendarserver.org//changeset/11101
Author: cdaboo at apple.com
Date: 2013-04-26 08:54:08 -0700 (Fri, 26 Apr 2013)
Log Message:
-----------
Checkpoint: CLI tools done.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/calverify.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/dbinspect.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/export.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/purge.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_calverify.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_export.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_purge_old_events.py
CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/test/test_collectioncontents.py
CalendarServer/branches/users/cdaboo/store-scheduling/txdav/common/datastore/sql.py
Removed Paths:
-------------
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/doublequotefix.py
CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/fixcalendardata.py
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/calverify.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/calverify.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -70,6 +70,7 @@
from twistedcaldav.util import normalizationLookup
from txdav.base.propertystore.base import PropertyName
+from txdav.caldav.icalendarstore import ComponentUpdateState
from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
from txdav.common.icommondatastore import InternalDataStoreError
@@ -773,7 +774,7 @@
# Write out fix, commit and get a new transaction
# Use _migrating to ignore possible overridden instance errors - we are either correcting or ignoring those
self.txn._migrating = True
- component = yield calendarObj.setComponent(component)
+ component = yield calendarObj._setComponentInternal(component, internal_state=ComponentUpdateState.RAW)
yield self.txn.commit()
self.txn = self.store.newTransaction()
@@ -824,7 +825,7 @@
calendar = yield home.childWithID(calendarID)
calendarObj = yield calendar.objectResourceWithID(resid)
objname = calendarObj.name()
- yield calendarObj.remove()
+ yield calendarObj.remove(implicitly=False)
yield self.txn.commit()
self.txn = self.store.newTransaction()
@@ -1347,7 +1348,7 @@
try:
# Use _migrating to ignore possible overridden instance errors - we are either correcting or ignoring those
self.txn._migrating = True
- component = yield calendarObj.setComponent(component)
+ component = yield calendarObj._setComponentInternal(component, internal_state=ComponentUpdateState.RAW)
except Exception, e:
print(e, component)
print(traceback.print_exc())
@@ -1917,7 +1918,7 @@
calendar = yield home.childWithID(calendarID)
calendarObj = yield calendar.objectResourceWithID(attresid)
calendarObj.scheduleTag = str(uuid.uuid4())
- yield calendarObj.setComponent(attendee_calendar)
+ yield calendarObj._setComponentInternal(attendee_calendar, internal_state=ComponentUpdateState.RAW)
self.results.setdefault("Fix change event", set()).add((home.name(), calendar.name(), attendee_calendar.resourceUID(),))
details["path"] = "/calendars/__uids__/%s/%s/%s" % (home.name(), calendar.name(), calendarObj.name(),)
@@ -1928,7 +1929,7 @@
if defaultCalendar is None:
raise ValueError("Cannot find suitable default calendar")
new_name = str(uuid.uuid4()) + ".ics"
- calendarObj = (yield defaultCalendar.createCalendarObjectWithName(new_name, attendee_calendar, self.metadata))
+ calendarObj = (yield defaultCalendar._createCalendarObjectWithNameInternal(new_name, attendee_calendar, internal_state=ComponentUpdateState.RAW, options=self.metadata))
self.results.setdefault("Fix add event", set()).add((home.name(), defaultCalendar.name(), attendee_calendar.resourceUID(),))
details["path"] = "/calendars/__uids__/%s/%s/%s" % (home.name(), defaultCalendar.name(), new_name,)
@@ -1944,7 +1945,7 @@
details["title"] = instance.component.propertyValue("SUMMARY")
# Write new itip message to attendee inbox
- yield inbox.createCalendarObjectWithName(str(uuid.uuid4()) + ".ics", itipmsg, self.metadata_inbox)
+ yield inbox.createCalendarObjectWithName(str(uuid.uuid4()) + ".ics", itipmsg, options=self.metadata_inbox)
self.results.setdefault("Fix add inbox", set()).add((home.name(), itipmsg.resourceUID(),))
yield self.txn.commit()
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/dbinspect.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/dbinspect.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/dbinspect.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -24,7 +24,6 @@
from caldavclientlibrary.admin.xmlaccounts.recordtypes import recordType_users, \
recordType_locations, recordType_resources, recordType_groups
-from calendarserver.tap.util import directoryFromConfig
from calendarserver.tools import tables
from calendarserver.tools.cmdline import utilityMain
from pycalendar.datetime import PyCalendarDateTime
@@ -33,7 +32,6 @@
from twisted.application.service import Service
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python.filepath import FilePath
-from twisted.python.reflect import namedClass
from twisted.python.text import wordWrap
from twisted.python.usage import Options
from twistedcaldav import caldavxml
@@ -95,7 +93,7 @@
def UserNameFromUID(txn, uid):
- record = txn._directory.recordWithGUID(uid)
+ record = txn.directoryService().recordWithGUID(uid)
return record.shortNames[0] if record else "(%s)" % (uid,)
@@ -106,13 +104,13 @@
except (ValueError, TypeError):
pass
- record = txn._directory.recordWithShortName(recordType_users, value)
+ record = txn.directoryService().recordWithShortName(recordType_users, value)
if record is None:
- record = txn._directory.recordWithShortName(recordType_locations, value)
+ record = txn.directoryService().recordWithShortName(recordType_locations, value)
if record is None:
- record = txn._directory.recordWithShortName(recordType_resources, value)
+ record = txn.directoryService().recordWithShortName(recordType_resources, value)
if record is None:
- record = txn._directory.recordWithShortName(recordType_groups, value)
+ record = txn.directoryService().recordWithShortName(recordType_groups, value)
return record.guid if record else None
@@ -867,7 +865,6 @@
self.options = options
self.reactor = reactor
self.config = config
- self._directory = None
self.commands = []
self.commandMap = {}
@@ -922,7 +919,6 @@
@inlineCallbacks
def runCommand(self, cmd):
txn = self.store.newTransaction()
- txn._directory = self.directoryService()
try:
yield cmd().doIt(txn)
yield txn.commit()
@@ -967,21 +963,6 @@
self.reactor.stop()
- def directoryService(self):
- """
- Get an appropriate directory service for this L{DBInspectService}'s
- configuration, creating one first if necessary.
- """
- if self._directory is None:
- self._directory = directoryFromConfig(self.config)
- proxydbClass = namedClass(config.ProxyDBService.type)
- try:
- calendaruserproxy.ProxyDBService = proxydbClass(**config.ProxyDBService.params)
- except IOError:
- print("Could not start proxydb service")
- return self._directory
-
-
def stopService(self):
"""
Stop the service. Nothing to do; everything should be finished by this
Deleted: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/doublequotefix.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/doublequotefix.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/doublequotefix.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -1,207 +0,0 @@
-#!/usr/bin/env python
-#
-##
-# Copyright (c) 2008-2013 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.
-##
-from __future__ import print_function
-
-import datetime
-import getopt
-import hashlib
-import os
-import sys
-import xattr
-
-ICALSERVER_DOCROOT = "/Library/CalendarServer/Documents"
-DEFAULT_URIS = "uris.txt"
-
-totalProblems = 0
-totalErrors = 0
-totalScanned = 0
-
-def usage(e=None):
- if e:
- print(e)
- print("")
-
- name = os.path.basename(sys.argv[0])
- print("usage: %s [options]" % (name,))
- print("")
- print("Fix double-quote/escape bugs in iCalendar data.")
- print("")
- print("options:")
- print(" -h --help: print this help and exit")
- print(" -p <path>: path to calendar server document root [icalserver default]")
- print(" -u <path>: path to file containing uris to process [uris.txt]")
- print(" --fix: Apply fixes, otherwise only check for problems")
- print("")
- print("uris: list of uris to process")
-
- if e:
- sys.exit(64)
- else:
- sys.exit(0)
-
-def updateEtag(path, caldata):
-
- x = xattr.xattr(path)
- x["WebDAV:{http:%2F%2Ftwistedmatrix.com%2Fxml_namespace%2Fdav%2F}getcontentmd5"] = """<?xml version='1.0' encoding='UTF-8'?>
-<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>%s</getcontentmd5>
-""" % (hashlib.md5(caldata).hexdigest(),)
-
-def updateCtag(path):
-
- x = xattr.xattr(path)
- x["WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag"] = """<?xml version='1.0' encoding='UTF-8'?>
-<getctag xmlns='http://calendarserver.org/ns/'>%s</getctag>
-""" % (str(datetime.datetime.now()),)
-
-def scanURI(uri, basePath, doFix):
-
- global totalProblems
- global totalErrors
- global totalScanned
-
- # Verify we have a valid path
- pathBits = uri.strip("/").rstrip("/").split("/")
- if len(pathBits) != 4 or pathBits[0] != "calendars" or pathBits[1] != "__uids__":
- print("Invalid uri (ignoring): %s" % (uri,))
- totalErrors += 1
- return
-
- # Absolute hashed directory path to calendar collection
- calendarPath = os.path.join(
- basePath,
- pathBits[0],
- pathBits[1],
- pathBits[2][0:2],
- pathBits[2][2:4],
- pathBits[2],
- pathBits[3],
- )
-
- if not os.path.exists(calendarPath):
- print("Calendar path does not exist: %s" % (calendarPath,))
- totalErrors += 1
- return
-
- # Look at each .ics in the calendar collection
- didFix = False
- basePathLength = len(basePath)
- for item in os.listdir(calendarPath):
- if not item.endswith(".ics"):
- continue
- totalScanned += 1
- icsPath = os.path.join(calendarPath, item)
-
- try:
- f = open(icsPath)
- icsData = f.read()
- except Exception, e:
- print("Failed to read file %s due to %s" % (icsPath, str(e),))
- totalErrors += 1
- continue
- finally:
- f.close()
-
- # See whether there is a \" that needs fixing.
- # NB Have to handle the case of a folded line...
- if icsData.find('\\"') != -1 or icsData.find('\\\r\n "') != -1:
- if doFix:
- # Fix by continuously replacing \" with " until no more replacements occur
- while True:
- newIcsData = icsData.replace('\\"', '"').replace('\\\r\n "', '\r\n "')
- if newIcsData == icsData:
- break
- else:
- icsData = newIcsData
-
- try:
- f = open(icsPath, "w")
- f.write(icsData)
- except Exception, e:
- print("Failed to write file %s due to %s" % (icsPath, str(e),))
- totalErrors += 1
- continue
- finally:
- f.close()
-
- # Change ETag on written resource
- updateEtag(icsPath, icsData)
- didFix = True
- print("Problem fixed in: <BasePath>%s" % (icsPath[basePathLength:],))
- else:
- print("Problem found in: <BasePath>%s" % (icsPath[basePathLength:],))
- totalProblems += 1
-
- # Change CTag on calendar collection if any resource was written
- if didFix:
- updateCtag(calendarPath)
-
-def main():
-
- basePath = ICALSERVER_DOCROOT
- urisFile = DEFAULT_URIS
- doFix = False
-
- # Parse command line options
- opts, _ignore_args = getopt.getopt(sys.argv[1:], "hp:u:", ["fix", "help",])
- for option, value in opts:
- if option in ("-h", "--help"):
- usage()
- elif option == "-p":
- basePath = value
- if not os.path.exists(basePath):
- usage("Path does not exist: %s" % (basePath,))
- elif not os.path.isdir(basePath):
- usage("Path is not a directory: %s" % (basePath,))
- elif option == "-u":
- urisFile = value
- elif option == "--fix":
- doFix = True
- else:
- usage("Invalid option")
-
- if not urisFile:
- usage("Need to specify a file listing each URI to process")
-
- # Get all the uris to process
- f = open(urisFile)
- uris = set()
- for line in f:
- pos = line.find("/calendars/")
- if pos == -1:
- print("Ignored log line: %s" % (line,))
- continue
- uris.add(line[pos:].split()[0])
- uris = list(uris)
- uris.sort()
- f.close()
-
- print("Base Path is: %s" % (basePath,))
- print("Number of unique URIs to fix: %d" % (len(uris),))
- print("")
- for uri in uris:
- scanURI(uri, basePath, doFix)
-
- print("")
- print("---------------------")
- print("Total Problems %s: %d of %d" % ("Fixed" if doFix else "Found", totalProblems, totalScanned,))
- if totalErrors:
- print("Total Errors: %s" % (totalErrors,))
-
-if __name__ == '__main__':
-
- main()
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/export.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/export.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/export.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -49,7 +49,6 @@
from twistedcaldav.stdconfig import DEFAULT_CONFIG_FILE
from calendarserver.tools.cmdline import utilityMain
from twisted.application.service import Service
-from calendarserver.tap.util import directoryFromConfig
def usage(e=None):
@@ -272,8 +271,7 @@
for calendar in calendars:
calendar = yield calendar
for obj in (yield calendar.calendarObjects()):
- evt = yield obj.filteredComponent(
- calendar.ownerCalendarHome().uid(), True)
+ evt = yield obj.filteredComponent(calendar.ownerCalendarHome().uid(), True)
for sub in evt.subcomponents():
if sub.name() != 'VTIMEZONE':
# Omit all VTIMEZONE components here - we will include them later
@@ -296,7 +294,7 @@
self.output = output
self.reactor = reactor
self.config = config
- self._directory = None
+ self._directory = self.store.directoryService()
def startService(self):
@@ -332,11 +330,8 @@
def directoryService(self):
"""
- Get an appropriate directory service for this L{ExporterService}'s
- configuration, creating one first if necessary.
+ Get an appropriate directory service.
"""
- if self._directory is None:
- self._directory = directoryFromConfig(self.config)
return self._directory
Deleted: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/fixcalendardata.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/fixcalendardata.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/fixcalendardata.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -1,378 +0,0 @@
-#!/usr/bin/env python
-#
-##
-# Copyright (c) 2009-2013 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.
-##
-from __future__ import print_function
-
-import re
-import datetime
-import getopt
-import hashlib
-import os
-import sys
-import time
-import xattr
-
-from plistlib import readPlist
-
-PLIST_FILE = "/Library/Server/Calendar and Contacts/Config/caldavd.plist"
-SCAN_FILE = "problems.txt"
-
-totalProblems = 0
-totalErrors = 0
-totalScanned = 0
-
-verbose = False
-
-def usage(e=None):
- if e:
- print(e)
- print("")
-
- name = os.path.basename(sys.argv[0])
- print("usage: %s [options]" % (name,))
- print("")
- print("Fix double-quote/escape bugs in iCalendar data.")
- print("Fix incorrect use of TZID in iCalendar data.")
- print("")
- print("options:")
- print(" -h --help: print this help and exit")
- print(" -f --config: Specify caldavd.plist configuration path")
- print(" -o <path>: path to file for scan results [problems.txt]")
- print(" -v: print each calendar home scanned")
- print(" --scan: Scan for problems")
- print(" --fix: Apply fixes")
- print("")
- print("One of --scan or --fix must be specified. Both may be specified")
-
- if e:
- sys.exit(64)
- else:
- sys.exit(0)
-
-def updateEtag(path, caldata):
-
- x = xattr.xattr(path)
- x["WebDAV:{http:%2F%2Ftwistedmatrix.com%2Fxml_namespace%2Fdav%2F}getcontentmd5"] = """<?xml version='1.0' encoding='UTF-8'?>
-<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>%s</getcontentmd5>
-""" % (hashlib.md5(caldata).hexdigest(),)
-
-def updateCtag(path):
-
- x = xattr.xattr(path)
- x["WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag"] = """<?xml version='1.0' encoding='UTF-8'?>
-<getctag xmlns='http://calendarserver.org/ns/'>%s</getctag>
-""" % (str(datetime.datetime.now()),)
-
-def parsePlist(plistPath):
-
- plist = readPlist(plistPath)
-
- try:
- return plist["DocumentRoot"]
- except KeyError:
- raise ValueError("Unable to read DocumentRoot key from plist: %s" % (plistPath,))
-
-def scanData(basePath, scanFile, doFix):
-
- uidsPath = os.path.join(basePath, "calendars", "__uids__")
- for item1 in os.listdir(uidsPath):
- if len(item1) == 2:
- level1Path = os.path.join(uidsPath, item1)
- for item2 in os.listdir(level1Path):
- if len(item2) == 2:
- level2Path = os.path.join(level1Path, item2)
- for item in os.listdir(level2Path):
- calendarHome = os.path.join(level2Path, item)
- if os.path.isdir(calendarHome):
- scanCalendarHome(basePath, calendarHome, scanFile, doFix)
-
-def scanCalendarHome(basePath, calendarHome, scanFile, doFix):
- if verbose:
- print("Scanning: %s" % (calendarHome,))
-
- for item in os.listdir(calendarHome):
- calendarPath = os.path.join(calendarHome, item)
- x = xattr.xattr(calendarPath)
- if x.has_key("WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag"):
- scanCalendar(basePath, calendarPath, scanFile, doFix)
-
-def scanCalendar(basePath, calendarPath, scanFile, doFix):
-
- global totalProblems
- global totalErrors
- global totalScanned
-
- if not os.path.exists(calendarPath):
- print("Calendar path does not exist: %s" % (calendarPath,))
- totalErrors += 1
- return
-
- # Look at each .ics in the calendar collection
- didFix = False
- basePathLength = len(basePath)
- for item in os.listdir(calendarPath):
- if not item.endswith(".ics"):
- continue
- totalScanned += 1
- icsPath = os.path.join(calendarPath, item)
-
- try:
- f = None
- f = open(icsPath)
- icsData = f.read()
- except Exception, e:
- print("Failed to read file %s due to %s" % (icsPath, str(e),))
- totalErrors += 1
- continue
- finally:
- if f:
- f.close()
-
- # See what needs fixing.
- problems = []
- fixQuotes = fixTZIDs = fixMultiVALARMs = False
- if testICSData_DoubleQuotes(icsData):
- problems.append("double quotes")
- fixQuotes = True
- if testICSData_TZIDs(icsData):
- problems.append("tzids")
- fixTZIDs = True
- valarms = testICSData_MultipleVALARMS(icsData)
- if valarms != 0:
- problems.append("multi-valarms-%d" % valarms)
- fixMultiVALARMs = True
- if problems:
- if doFix:
- if fixPath(icsPath, icsData, fixQuotes, fixTZIDs, fixMultiVALARMs):
- didFix = True
- print("Problems %s fixed in: <BasePath>%s" % (",".join(problems), icsPath[basePathLength:],))
- else:
- print("Problem %s found in: <BasePath>%s" % (",".join(problems), icsPath[basePathLength:],))
- scanFile.write(icsPath + "\n")
- totalProblems += 1
-
- # Change CTag on calendar collection if any resource was written
- if didFix:
- updateCtag(calendarPath)
-
-def testICSData_DoubleQuotes(icsData):
-
- # See whether there is a \" that needs fixing.
- # NB Have to handle the case of a folded line...
- return icsData.find('\\"') != -1 or icsData.find('\\\r\n "') != -1 or icsData.find('\r\n \r\n "') != -1
-
-tzidRESearch = re.compile("(.*)TZID=[^;:]+;(VALUE=DATE.*)")
-tzidREReplace = re.compile("(.*)TZID=[^;:]+;(VALUE=DATE.*)", flags=re.S)
-
-def testICSData_TZIDs(icsData):
-
- return tzidRESearch.search(icsData) != None
-
-def testICSData_MultipleVALARMS(icsData):
-
- if icsData.count("END:VALARM\r\nBEGIN:VALARM") > 0:
-
- # More detailed scan
- lines = icsData.split("\r\n")
- badcount = 0
- inevent = False
- for line in lines:
- line = line.upper()
- if line == "BEGIN:VEVENT":
- duplicate_count = 0
- alarm_ids = set()
- inevent = True
- elif line == "END:VEVENT":
- if duplicate_count > badcount:
- badcount = duplicate_count
- inevent = False
- elif inevent and line.startswith("X-WR-ALARMUID"):
- new_id = line
- if new_id in alarm_ids:
- duplicate_count += 1
- else:
- alarm_ids.add(new_id)
- return badcount
- else:
- return 0
-
-def fixData(basePath, scanPath):
-
- global totalProblems
- global totalErrors
- global totalScanned
-
- try:
- f = None
- f = open(scanPath)
- lines = [line[:-1] for line in f]
- except Exception, e:
- print("Failed to read file %s due to %s" % (scanPath, str(e),))
- totalErrors += 1
- return
- finally:
- if f:
- f.close()
-
- lines.sort()
- calendarPaths = {}
- for line in lines:
- calendarPath, icsName = line.rsplit("/", 1)
- calendarPaths.setdefault(calendarPath, []).append(icsName)
- totalScanned += 1
-
- basePathLength = len(basePath)
- for calendarPath, icsNames in sorted(calendarPaths.items(), key=lambda x:x[0]):
- didFix = False
- for icsName in icsNames:
- icsPath = os.path.join(calendarPath, icsName)
- if fixPath(icsPath):
- didFix = True
- print("Problem fixed in: <BasePath>%s" % (icsPath[basePathLength:],))
- totalProblems += 1
-
- # Change CTag on calendar collection if any resource was written
- if didFix:
- updateCtag(calendarPath)
-
-def fixPath(icsPath, icsData=None, doQuotes=True, doTZIDs=True, doMultiVALARMs=True):
-
- global totalProblems
- global totalErrors
- global totalScanned
-
- if icsData is None:
- try:
- f = None
- f = open(icsPath)
- icsData = f.read()
- except Exception, e:
- print("Failed to read file %s due to %s" % (icsPath, str(e),))
- totalErrors += 1
- return False
- finally:
- if f:
- f.close()
-
- # Fix by continuously replacing \" with " until no more replacements occur
- if doQuotes:
- while True:
- newIcsData = icsData.replace('\\"', '"').replace('\\\r\n "', '\r\n "').replace('\r\n \r\n "', '\r\n "')
- if newIcsData == icsData:
- break
- else:
- icsData = newIcsData
-
- # Fix the TZID problem
- if doTZIDs:
- while True:
- icsMatch = tzidREReplace.search(icsData)
- if icsMatch is not None:
- icsData = icsMatch.expand("\\1\\2")
- else:
- break
-
- if doMultiVALARMs:
- lines = icsData.split("BEGIN:")
- newlines = []
- lastalarm = False
- for line in lines:
- isalarm = line.startswith("VALARM")
- if lastalarm and isalarm:
- newlines.pop()
- newlines.append(line)
- lastalarm = isalarm
- icsData = "BEGIN:".join(newlines)
-
- try:
- f = None
- f = open(icsPath, "w")
- f.write(icsData)
- except Exception, e:
- print("Failed to write file %s due to %s" % (icsPath, str(e),))
- totalErrors += 1
- return False
- finally:
- if f:
- f.close()
-
- # Change ETag on written resource
- updateEtag(icsPath, icsData)
-
- return True
-
-def main():
-
- plistPath = PLIST_FILE
- scanPath = SCAN_FILE
- doScan = False
- doFix = False
-
- # Parse command line options
- opts, _ignore_args = getopt.getopt(sys.argv[1:], "f:ho:", ["config", "scan", "fix", "help",])
- for option, value in opts:
- if option in ("-h", "--help"):
- usage()
- elif option in ("-f", "--config"):
- plistPath = value
- if not os.path.exists(plistPath):
- usage("Path does not exist: %s" % (plistPath,))
- elif option == "-o":
- scanPath = value
- elif option == "--scan":
- doScan = True
- elif option == "--fix":
- doFix = True
- else:
- usage("Invalid option")
-
- if not doScan and not doFix:
- usage("Must specify one or both of --scan or --fix")
-
- if not doScan and doFix and not scanPath:
- usage("Need to specify a file listing each path to fix")
-
- basePath = parsePlist(plistPath)
-
- start = time.time()
- print("Base Path is: %s" % (basePath,))
- if doScan:
- if doFix:
- print("Scanning data store and fixing")
- scanFile = None
- else:
- print("Scanning data store and writing results to '%s'" % (scanPath,))
- try:
- scanFile = open(scanPath, "w")
- except Exception, e:
- print("Failed to open file for writing %s due to %s" % (scanPath, str(e),))
- scanData(basePath, scanFile, doFix)
- elif doFix:
- print("Fixing data using results from '%s'" % (scanPath,))
- fixData(basePath, scanPath)
- difftime = time.time() - start
-
- print("")
- print("---------------------")
- print("Total Problems %s: %d of %d" % ("Fixed" if doFix else "Found", totalProblems, totalScanned,))
- if totalErrors:
- print("Total Errors: %s" % (totalErrors,))
- print("Time taken (secs): %.1f" % (difftime,))
-
-if __name__ == '__main__':
-
- main()
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/purge.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/purge.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -27,15 +27,12 @@
from pycalendar.datetime import PyCalendarDateTime
from twext.python.log import Logger
-from twext.web2.responsecode import NO_CONTENT
from twisted.internet.defer import inlineCallbacks, returnValue
from twistedcaldav import caldavxml
from twistedcaldav.caldavxml import TimeRange
-from twistedcaldav.datafilters.peruserdata import PerUserDataFilter
from twistedcaldav.directory.directory import DirectoryRecord
-from twistedcaldav.method.put_common import StoreCalendarObjectResource
from twistedcaldav.query import calendarqueryfilter
from txdav.xml import element as davxml
@@ -773,29 +770,58 @@
# If in "completely" mode, unshare collections, remove notifications
if calHomeProvisioned and self.completely:
+ yield self._cleanHome(txn, storeCalHome)
- # Process shared and shared-to-me calendars
- children = list((yield storeCalHome.children()))
- for child in children:
- if self.verbose:
- if self.dryrun:
- print("Would unshare: %s" % (child.name(),))
- else:
- print("Unsharing: %s" % (child.name(),))
- if not self.dryrun:
- (yield child.unshare())
+ yield txn.commit()
+ count = 0
+ assignments = []
+
+ if calHomeProvisioned:
+ count = (yield self._cancelEvents(txn, uid, cua))
+
+ # Remove empty calendar collections (and calendar home if no more
+ # calendars)
+ yield self._removeCalendarHome(uid)
+
+ # Remove VCards
+ count += (yield self._removeAddressbookHome(uid))
+
+ if self.proxies and not self.dryrun:
+ if self.verbose:
+ print("Deleting any proxy assignments")
+ assignments = (yield self._purgeProxyAssignments(principal))
+
+ returnValue((count, assignments))
+
+
+ @inlineCallbacks
+ def _cleanHome(self, txn, storeCalHome):
+
+ # Process shared and shared-to-me calendars
+ children = list((yield storeCalHome.children()))
+ for child in children:
+ if self.verbose:
+ if self.dryrun:
+ print("Would unshare: %s" % (child.name(),))
+ else:
+ print("Unsharing: %s" % (child.name(),))
if not self.dryrun:
- (yield storeCalHome.removeUnacceptedShares())
- notificationHome = (yield txn.notificationsWithUID(uid))
- if notificationHome is not None:
- (yield notificationHome.remove())
+ (yield child.unshare())
- (yield txn.commit())
+ if not self.dryrun:
+ (yield storeCalHome.removeUnacceptedShares())
+ notificationHome = (yield txn.notificationsWithUID(storeCalHome.uid()))
+ if notificationHome is not None:
+ (yield notificationHome.remove())
+
+ @inlineCallbacks
+ def _cancelEvents(self, txn, uid, cua):
+
# Anything in the past is left alone
whenString = self.when.getText()
- filter = caldavxml.Filter(
+ query_filter = caldavxml.Filter(
caldavxml.ComponentFilter(
caldavxml.ComponentFilter(
TimeRange(start=whenString,),
@@ -804,139 +830,102 @@
name="VCALENDAR",
)
)
- filter = calendarqueryfilter.Filter(filter)
+ query_filter = calendarqueryfilter.Filter(query_filter)
count = 0
- assignments = []
+ txn = self._store.newTransaction()
+ storeCalHome = (yield txn.calendarHomeWithUID(uid))
+ calendarNames = (yield storeCalHome.listCalendars())
+ yield txn.commit()
- perUserFilter = PerUserDataFilter(uid)
+ for calendarName in calendarNames:
- try:
- if calHomeProvisioned:
- calendarHome = yield principal.calendarHome(request)
- for collName in (yield calendarHome.listChildren()):
- collection = (yield calendarHome.getChild(collName))
+ txn = self._store.newTransaction()
+ storeCalHome = (yield txn.calendarHomeWithUID(uid))
+ calendar = (yield storeCalHome.calendarWithName(calendarName))
+ childNames = []
- if collection.isCalendarCollection() or collName == "inbox":
- childNames = []
+ if self.completely:
+ # all events
+ for childName in (yield calendar.listCalendarObjects()):
+ childNames.append(childName)
+ else:
+ # events matching filter
+ for childName, _ignore_childUid, _ignore_childType in (yield calendar._index.indexedSearch(query_filter)):
+ childNames.append(childName)
+ yield txn.commit()
- if self.completely:
- # all events
- for childName in (yield collection.listChildren()):
- childNames.append(childName)
- else:
- # events matching filter
- for childName, _ignore_childUid, _ignore_childType in (yield collection.index().indexedSearch(filter)):
- childNames.append(childName)
+ for childName in childNames:
- for childName in childNames:
+ txn = self._store.newTransaction()
+ storeCalHome = (yield txn.calendarHomeWithUID(uid))
+ calendar = (yield storeCalHome.calendarWithName(calendarName))
- try:
- perresource_request = FakeRequest(self.root, None, None)
- perresource_request.checkedSACL = True
- perresource_request.authnUser = perresource_request.authzUser = davxml.Principal(
- davxml.HRef.fromString("/principals/__uids__/%s/" % (uid,))
- )
- perresource_request._rememberResource(collection,
- "/calendars/__uids__/%s/%s/" % (uid, collName))
+ try:
+ childResource = (yield calendar.calendarObjectWithName(childName))
- childResource = (yield collection.getChild(childName))
+ # Always delete inbox items
+ if self.completely or calendar.isInbox():
+ action = self.CANCELEVENT_SHOULD_DELETE
+ else:
+ event = (yield childResource.componentForUser())
+ action = self._cancelEvent(event, self.when, cua)
- # Allways delete inbox items
- if self.completely or collName == "inbox":
- action = self.CANCELEVENT_SHOULD_DELETE
- else:
- event = (yield childResource.iCalendar())
- event = perUserFilter.filter(event)
- action = self._cancelEvent(event, self.when, cua)
+ uri = "/calendars/__uids__/%s/%s/%s" % (storeCalHome.uid(), calendar.name(), childName)
+ if action == self.CANCELEVENT_MODIFIED:
+ if self.verbose:
+ if self.dryrun:
+ print("Would modify: %s" % (uri,))
+ else:
+ print("Modifying: %s" % (uri,))
+ if not self.dryrun:
+ yield childResource.setComponent(event)
+ count += 1
- uri = "/calendars/__uids__/%s/%s/%s" % (uid, collName, childName)
- perresource_request.path = uri
- if action == self.CANCELEVENT_MODIFIED:
- perresource_request._rememberResource(childResource, uri)
- storer = StoreCalendarObjectResource(
- request=perresource_request,
- destination=childResource,
- destination_uri=uri,
- destinationcal=True,
- destinationparent=collection,
- calendar=str(event),
- )
- if self.verbose:
- if self.dryrun:
- print("Would modify: %s" % (uri,))
- else:
- print("Modifying: %s" % (uri,))
- if not self.dryrun:
- result = (yield storer.run())
- count += 1
+ elif action == self.CANCELEVENT_SHOULD_DELETE:
+ incrementCount = self.dryrun
+ if self.verbose:
+ if self.dryrun:
+ print("Would delete: %s" % (uri,))
+ else:
+ print("Deleting: %s" % (uri,))
+ if not self.dryrun:
+ retry = False
+ try:
+ yield childResource.remove(implicitly=self.doimplicit)
+ incrementCount = True
+ except Exception, e:
+ print("Exception deleting %s: %s" % (uri, str(e)))
+ retry = True
- elif action == self.CANCELEVENT_SHOULD_DELETE:
- incrementCount = self.dryrun
- perresource_request._rememberResource(childResource, uri)
- if self.verbose:
- if self.dryrun:
- print("Would delete: %s" % (uri,))
- else:
- print("Deleting: %s" % (uri,))
- if not self.dryrun:
- retry = False
- try:
- result = (yield childResource.storeRemove(perresource_request, self.doimplicit, uri))
- if result != NO_CONTENT:
- print("Error deleting %s/%s/%s: %s" % (uid,
- collName, childName, result))
- retry = True
- else:
- incrementCount = True
+ if retry and self.doimplicit:
+ # Try again with implicit scheduling off
+ print("Retrying deletion of %s with implicit scheduling turned off" % (uri, childName))
+ try:
+ yield childResource.remove(implicitly=False)
+ incrementCount = True
+ except Exception, e:
+ print("Still couldn't delete %s even with implicit scheduling turned off: %s" % (uri, str(e)))
- except Exception, e:
- print("Exception deleting %s/%s/%s: %s" % (uid,
- collName, childName, str(e)))
- retry = True
+ if incrementCount:
+ count += 1
- if retry and self.doimplicit:
- # Try again with implicit scheduling off
- print("Retrying deletion of %s/%s/%s with implicit scheduling turned off" % (uid, collName, childName))
- try:
- result = (yield childResource.storeRemove(perresource_request, False, uri))
- if result != NO_CONTENT:
- print("Error deleting %s/%s/%s: %s" % (uid,
- collName, childName, result))
- else:
- incrementCount = True
- except Exception, e:
- print("Still couldn't delete %s/%s/%s even with implicit scheduling turned off: %s" % (uid, collName, childName, str(e)))
+ # Commit
+ yield txn.commit()
- if incrementCount:
- count += 1
- txn = getattr(perresource_request, "_newStoreTransaction", None)
- # Commit
- if txn is not None:
- (yield txn.commit())
+ except Exception, e:
+ # Abort
+ yield txn.abort()
+ raise e
- except Exception, e:
- # Abort
- txn = getattr(perresource_request, "_newStoreTransaction", None)
- if txn is not None:
- (yield txn.abort())
- raise e
+ returnValue(count)
- txn = getattr(request, "_newStoreTransaction", None)
- # Commit
- if txn is not None:
- (yield txn.commit())
- except Exception, e:
- # Abort
- txn = getattr(request, "_newStoreTransaction", None)
- if txn is not None:
- (yield txn.abort())
- raise e
+ @inlineCallbacks
+ def _removeCalendarHome(self, uid):
+ txn = self._store.newTransaction()
try:
- txn = self._store.newTransaction()
-
# Remove empty calendar collections (and calendar home if no more
# calendars)
storeCalHome = (yield txn.calendarHomeWithUID(uid))
@@ -964,6 +953,22 @@
if not self.dryrun:
(yield storeCalHome.remove())
+ # Commit
+ yield txn.commit()
+
+ except Exception, e:
+ # Abort
+ yield txn.abort()
+ raise e
+
+
+ @inlineCallbacks
+ def _removeAddressbookHome(self, uid):
+
+ count = 0
+ txn = self._store.newTransaction()
+
+ try:
# Remove VCards
storeAbHome = (yield txn.addressbookHomeWithUID(uid))
if storeAbHome is not None:
@@ -998,20 +1003,15 @@
(yield storeAbHome.remove())
# Commit
- (yield txn.commit())
+ yield txn.commit()
except Exception, e:
# Abort
- (yield txn.abort())
+ yield txn.abort()
raise e
- if self.proxies and not self.dryrun:
- if self.verbose:
- print("Deleting any proxy assignments")
- assignments = (yield self._purgeProxyAssignments(principal))
+ returnValue(count)
- returnValue((count, assignments))
-
CANCELEVENT_SKIPPED = 1
CANCELEVENT_MODIFIED = 2
CANCELEVENT_NOT_MODIFIED = 3
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_calverify.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_calverify.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -23,16 +23,14 @@
SchedulingMismatchService, DoubleBookingService, DarkPurgeService
from StringIO import StringIO
-from calendarserver.tap.util import getRootResource
from pycalendar.datetime import PyCalendarDateTime
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.trial import unittest
from twistedcaldav import caldavxml
from twistedcaldav.config import config
+from twistedcaldav.test.util import StoreTestCase
from txdav.base.propertystore.base import PropertyName
-from txdav.caldav.datastore import util
-from txdav.common.datastore.test.util import buildStore, populateCalendarsFrom, CommonCommonTests
+from txdav.common.datastore.test.util import populateCalendarsFrom
from txdav.xml import element as davxml
import os
@@ -415,7 +413,7 @@
-class CalVerifyDataTests(CommonCommonTests, unittest.TestCase):
+class CalVerifyDataTests(StoreTestCase):
"""
Tests calverify for iCalendar data problems.
"""
@@ -448,12 +446,8 @@
},
}
- @inlineCallbacks
- def setUp(self):
- yield super(CalVerifyDataTests, self).setUp()
- self._sqlCalendarStore = yield buildStore(self, self.notifierFactory)
- yield self.populate()
-
+ def configure(self):
+ super(CalVerifyDataTests, self).configure()
self.patch(config.DirectoryService.params, "xmlFile",
os.path.join(
os.path.dirname(__file__), "calverify", "accounts.xml"
@@ -465,17 +459,12 @@
)
)
- self.rootResource = getRootResource(config, self._sqlCalendarStore)
- self.directory = self.rootResource.getDirectory()
-
@inlineCallbacks
def populate(self):
# Need to bypass normal validation inside the store
- util.validationBypass = True
- yield populateCalendarsFrom(self.requirements, self.storeUnderTest(), migrating=True)
- util.validationBypass = False
+ yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
self.notifierFactory.reset()
@@ -939,7 +928,7 @@
-class CalVerifyMismatchTestsBase(CommonCommonTests, unittest.TestCase):
+class CalVerifyMismatchTestsBase(StoreTestCase):
"""
Tests calverify for iCalendar mismatch problems.
"""
@@ -960,8 +949,6 @@
@inlineCallbacks
def setUp(self):
yield super(CalVerifyMismatchTestsBase, self).setUp()
- self._sqlCalendarStore = yield buildStore(self, self.notifierFactory)
- yield self.populate()
inbox = (yield self.calendarUnderTest(self.uuid3, "inbox"))
inbox.properties()[PropertyName.fromElement(caldavxml.ScheduleDefaultCalendarURL)] = caldavxml.ScheduleDefaultCalendarURL(
@@ -969,6 +956,9 @@
)
yield self.commit()
+
+ def configure(self):
+ super(CalVerifyMismatchTestsBase, self).configure()
self.patch(config.DirectoryService.params, "xmlFile",
os.path.join(
os.path.dirname(__file__), "calverify", "accounts.xml"
@@ -984,17 +974,13 @@
os.path.dirname(__file__), "calverify", "augments.xml"
), ]
)
- self.rootResource = getRootResource(config, self._sqlCalendarStore)
- self.directory = self.rootResource.getDirectory()
@inlineCallbacks
def populate(self):
# Need to bypass normal validation inside the store
- util.validationBypass = True
- yield populateCalendarsFrom(self.requirements, self.storeUnderTest(), migrating=True)
- util.validationBypass = False
+ yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
self.notifierFactory.reset()
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_export.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_export.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_export.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-from twistedcaldav.config import config
"""
Unit tests for L{calendarsever.tools.export}.
@@ -33,6 +32,7 @@
from twistedcaldav.ical import Component
from twistedcaldav.datafilters.test.test_peruserdata import dataForTwoUsers
from twistedcaldav.datafilters.test.test_peruserdata import resultForUser2
+from twistedcaldav.test.util import StoreTestCase
from calendarserver.tools import export
from calendarserver.tools.export import ExportOptions, main
@@ -41,7 +41,6 @@
from twisted.python.filepath import FilePath
from twisted.internet.defer import Deferred
-from txdav.common.datastore.test.util import buildStore
from txdav.common.datastore.test.util import populateCalendarsFrom
from calendarserver.tools.export import usage, exportToFile
@@ -177,14 +176,11 @@
-class IntegrationTests(TestCase):
+class IntegrationTests(StoreTestCase):
"""
Tests for exporting data from a live store.
"""
- accountsFile = 'no-accounts.xml'
- augmentsFile = 'no-augments.xml'
-
@inlineCallbacks
def setUp(self):
"""
@@ -197,7 +193,8 @@
self.mainCalled = False
self.patch(export, "utilityMain", self.fakeUtilityMain)
- self.store = yield buildStore(self, None)
+ yield super(IntegrationTests, self).setUp()
+ self.store = self.storeUnderTest()
self.waitToStop = Deferred()
@@ -217,24 +214,6 @@
raise RuntimeError(
"Main called twice during this test; duplicate reactor run.")
- self.patch(config, "DirectoryService", dict(
- type="twistedcaldav.directory.xmlfile.XMLDirectoryService",
- params=dict(
- xmlFile=self.accountsFile
- )
- ))
- self.patch(config, "ResourceService", dict(
- Enabled=False,
- type="twistedcaldav.directory.xmlfile.XMLDirectoryService",
- params=dict()
- ))
- self.patch(config, "AugmentService", dict(
- type="twistedcaldav.directory.augment.AugmentXMLDB",
- params=dict(
- xmlFiles=[self.augmentsFile]
- )
- ))
-
self.mainCalled = True
self.usedConfigFile = configFileName
self.usedReactor = reactor
@@ -448,36 +427,9 @@
}, self.store
)
- augmentsData = """
- <augments>
- <record>
- <uid>Default</uid>
- <enable>true</enable>
- <enable-calendar>true</enable-calendar>
- <enable-addressbook>true</enable-addressbook>
- </record>
- </augments>
- """
- augments = FilePath(self.mktemp())
- augments.setContent(augmentsData)
-
- accountsData = """
- <accounts realm="Test Realm">
- <user>
- <uid>user-under-test</uid>
- <guid>user02</guid>
- <name>Not Interesting</name>
- <password>very-secret</password>
- </user>
- </accounts>
- """
- accounts = FilePath(self.mktemp())
- accounts.setContent(accountsData)
output = FilePath(self.mktemp())
- self.accountsFile = accounts.path
- self.augmentsFile = augments.path
main(['calendarserver_export', '--output',
- output.path, '--user', 'user-under-test'], reactor=self)
+ output.path, '--user', 'user02'], reactor=self)
yield self.waitToStop
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_purge_old_events.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_purge_old_events.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tools/test/test_purge_old_events.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -18,7 +18,6 @@
Tests for calendarserver.tools.purge
"""
-from calendarserver.tap.util import getRootResource
from calendarserver.tools.purge import PurgeOldEventsService, PurgeAttachmentsService, \
PurgePrincipalService
@@ -29,13 +28,13 @@
from twext.web2.http_headers import MimeType
from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.trial import unittest
from twistedcaldav.config import config
+from twistedcaldav.test.util import StoreTestCase
from twistedcaldav.vcard import Component as VCardComponent
from txdav.common.datastore.sql_tables import schema
-from txdav.common.datastore.test.util import buildStore, populateCalendarsFrom, CommonCommonTests
+from txdav.common.datastore.test.util import populateCalendarsFrom
import os
@@ -365,7 +364,7 @@
""".replace("\n", "\r\n")
-class PurgeOldEventsTests(CommonCommonTests, unittest.TestCase):
+class PurgeOldEventsTests(StoreTestCase):
"""
Tests for deleting events older than a given date
"""
@@ -410,15 +409,12 @@
}
}
- @inlineCallbacks
- def setUp(self):
+ def configure(self):
+ super(PurgeOldEventsTests, self).configure()
+
# Turn off delayed indexing option so we can have some useful tests
self.patch(config, "FreeBusyIndexDelayedExpand", False)
- yield super(PurgeOldEventsTests, self).setUp()
- self._sqlCalendarStore = yield buildStore(self, self.notifierFactory)
- yield self.populate()
-
self.patch(config.DirectoryService.params, "xmlFile",
os.path.join(
os.path.dirname(__file__), "purge", "accounts.xml"
@@ -429,8 +425,6 @@
os.path.dirname(__file__), "purge", "resources.xml"
)
)
- self.rootResource = getRootResource(config, self._sqlCalendarStore)
- self.directory = self.rootResource.getDirectory()
@inlineCallbacks
@@ -447,13 +441,6 @@
(yield txn.commit())
- def storeUnderTest(self):
- """
- Create and return a L{CalendarStore} for testing.
- """
- return self._sqlCalendarStore
-
-
@inlineCallbacks
def test_eventsOlderThan(self):
cutoff = PyCalendarDateTime(now, 4, 1, 0, 0, 0)
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/test/test_collectioncontents.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/test/test_collectioncontents.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/test/test_collectioncontents.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -24,11 +24,11 @@
from twistedcaldav.ical import Component
from twistedcaldav.memcachelock import MemcacheLock
from twistedcaldav.memcacher import Memcacher
-from twistedcaldav.method.put_common import StoreCalendarObjectResource
from twistedcaldav.test.util import StoreTestCase, SimpleStoreRequest
from twext.web2.dav.util import joinURL
+from txdav.caldav.datastore.sql import CalendarObject
class CollectionContents(StoreTestCase):
"""
@@ -49,10 +49,10 @@
_getFakeMemcacheProtocol)
# Need to not do implicit behavior during these tests
- def _fakeDoImplicitScheduling(self):
- return False, False, False
+ def _fakeDoImplicitScheduling(self, component, inserting, internal_state):
+ return False, None, False
- self.patch(StoreCalendarObjectResource , "doImplicitScheduling",
+ self.patch(CalendarObject , "doImplicitScheduling",
_fakeDoImplicitScheduling)
# Tests in this suite assume that the root resource is a calendar home.
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/common/datastore/sql.py 2013-04-25 18:25:14 UTC (rev 11100)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/common/datastore/sql.py 2013-04-26 15:54:08 UTC (rev 11101)
@@ -1107,7 +1107,6 @@
many were removed.
"""
- assert "This needs to be moved into txdav.caldav as it needs to call _removeInternal"
# Make sure cut off is after any lower limit truncation in the DB
if config.FreeBusyIndexLowerLimitDays:
truncateLowerLimit = PyCalendarDateTime.getToday()
@@ -1121,7 +1120,7 @@
home = (yield self.calendarHomeWithUID(uid))
calendar = (yield home.childWithName(calendarName))
resource = (yield calendar.objectResourceWithName(eventName))
- yield resource._removeInternal()
+ yield resource.remove(implicitly=False)
count += 1
returnValue(count)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130426/74984737/attachment-0001.html>
More information about the calendarserver-changes
mailing list