[CalendarServer-changes] [12995] CalendarServer/branches/users/sagen/move2who-4/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 25 16:19:18 PDT 2014
Revision: 12995
http://trac.calendarserver.org//changeset/12995
Author: sagen at apple.com
Date: 2014-03-25 16:19:18 -0700 (Tue, 25 Mar 2014)
Log Message:
-----------
Delegate assignments are loaded from XML to sqlite to store
Modified Paths:
--------------
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py 2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py 2014-03-25 23:19:18 UTC (rev 12995)
@@ -29,7 +29,6 @@
from twext.python.log import Logger
from twistedcaldav.config import config, fullServerPath
-from twistedcaldav.directory import calendaruserproxy
from twistedcaldav.xmlutil import readXML
log = Logger()
@@ -44,6 +43,7 @@
ATTRIBUTE_REPEAT = "repeat"
+
class XMLCalendarUserProxyLoader(object):
"""
XML calendar user proxy configuration file parser and loader.
@@ -52,10 +52,11 @@
return "<%s %r>" % (self.__class__.__name__, self.xmlFile)
- def __init__(self, xmlFile):
+ def __init__(self, xmlFile, service):
self.items = []
self.xmlFile = fullServerPath(config.DataRoot, xmlFile)
+ self.service = service
# Read in XML
try:
@@ -131,7 +132,7 @@
@inlineCallbacks
def updateProxyDB(self):
- db = calendaruserproxy.ProxyDBService
+ db = self.service
for item in self.items:
guid, write_proxies, read_proxies = item
yield db.setGroupMembers("%s#%s" % (guid, "calendar-proxy-write"), write_proxies)
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml 2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml 2014-03-25 23:19:18 UTC (rev 12995)
@@ -19,4 +19,60 @@
<!DOCTYPE accounts SYSTEM "../../../conf/auth/accounts.dtd">
<directory realm="Test">
+ <record type="location">
+ <uid>mercury</uid>
+ <short-name>mercury</short-name>
+ <password>mercury</password>
+ <full-name>Mercury Seven</full-name>
+ <email>mercury at example.com</email>
+ </record>
+ <record type="location">
+ <uid>gemini</uid>
+ <short-name>gemini</short-name>
+ <password>gemini</password>
+ <full-name>Gemini Twelve</full-name>
+ <email>gemini at example.com</email>
+ </record>
+ <record type="location">
+ <uid>apollo</uid>
+ <short-name>apollo</short-name>
+ <password>apollo</password>
+ <full-name>Apollo Eleven</full-name>
+ <email>apollo at example.com</email>
+ </record>
+ <record type="location">
+ <uid>orion</uid>
+ <short-name>orion</short-name>
+ <password>orion</password>
+ <full-name>Orion</full-name>
+ <email>orion at example.com</email>
+ </record>
+ <record type="resource">
+ <uid>transporter</uid>
+ <short-name>transporter</short-name>
+ <password>transporter</password>
+ <full-name>Mass Transporter</full-name>
+ <email>transporter at example.com</email>
+ </record>
+ <record type="resource">
+ <uid>ftlcpu</uid>
+ <short-name>ftlcpu</short-name>
+ <password>ftlcpu</password>
+ <full-name>Faster-Than-Light Microprocessor</full-name>
+ <email>ftlcpu at example.com</email>
+ </record>
+ <record type="resource">
+ <uid>non_calendar_proxy</uid>
+ <short-name>non_calendar_proxy</short-name>
+ <password>non_calendar_proxy</password>
+ <full-name>Non-calendar proxy</full-name>
+ <email>non_calendar_proxy at example.com</email>
+ </record>
+ <record type="resource">
+ <uid>disabled</uid>
+ <short-name>disabled</short-name>
+ <password>disabled</password>
+ <full-name>Disabled Record</full-name>
+ <email>disabled at example.com</email>
+ </record>
</directory>
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py 2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py 2014-03-25 23:19:18 UTC (rev 12995)
@@ -26,14 +26,16 @@
from txdav.caldav.datastore.index_file import db_basename
from twistedcaldav.config import config
-# from twistedcaldav.directory.xmlfile import XMLDirectoryService
from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
from twistedcaldav.upgrade import (
xattrname, upgradeData, updateFreeBusySet,
- removeIllegalCharacters, normalizeCUAddrs
+ removeIllegalCharacters, normalizeCUAddrs,
+ loadDelegatesFromXML, migrateDelegatesToStore
)
from twistedcaldav.test.util import StoreTestCase
+from txdav.who.delegates import delegatesOf
+from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
@@ -54,21 +56,6 @@
class UpgradeTests(StoreTestCase):
- # def setUpXMLDirectory(self):
- # xmlFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
- # "directory", "test", "accounts.xml")
- # config.DirectoryService.params.xmlFile = xmlFile
-
- # xmlAugmentsFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
- # "directory", "test", "augments.xml")
- # config.AugmentService.type = "twistedcaldav.directory.augment.AugmentXMLDB"
- # config.AugmentService.params.xmlFiles = (xmlAugmentsFile,)
-
- # resourceFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
- # "directory", "test", "resources.xml")
- # config.ResourceService.params.xmlFile = resourceFile
-
-
def doUpgrade(self, config):
"""
Perform the actual upgrade. (Hook for parallel tests.)
@@ -1566,6 +1553,46 @@
self.assertEquals(directory.count, 3)
+ @inlineCallbacks
+ def test_migrateDelegates(self):
+ store = self.storeUnderTest()
+ record = yield self.directory.recordWithUID(u"mercury")
+ txn = store.newTransaction()
+ writeDelegates = yield delegatesOf(txn, record, True)
+ self.assertEquals(len(writeDelegates), 0)
+ yield txn.commit()
+
+ # Load delegates from xml into sqlite
+ sqliteProxyService = ProxySqliteDB("proxies.sqlite")
+ proxyFile = os.path.join(config.DataRoot, "proxies.xml")
+ yield loadDelegatesFromXML(proxyFile, sqliteProxyService)
+
+ # Load delegates from sqlite into store
+ yield migrateDelegatesToStore(sqliteProxyService, store)
+
+ # Check delegates in store
+ txn = store.newTransaction()
+ writeDelegates = yield delegatesOf(txn, record, True)
+ self.assertEquals(len(writeDelegates), 1)
+ self.assertEquals(
+ set([d.uid for d in writeDelegates]),
+ set([u"left_coast"])
+ )
+
+ record = yield self.directory.recordWithUID(u"non_calendar_proxy")
+
+ readDelegates = yield delegatesOf(txn, record, False)
+ self.assertEquals(len(readDelegates), 1)
+ self.assertEquals(
+ set([d.uid for d in readDelegates]),
+ set([u"recursive2_coasts"])
+ )
+
+ yield txn.commit()
+
+
+
+
normalizeEvent = """BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py 2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py 2014-03-25 23:19:18 UTC (rev 12995)
@@ -186,7 +186,11 @@
augments = FilePath(config.DataRoot).child("augments.xml")
augments.setContent(augmentsFile.getContent())
+ proxies = FilePath(config.DataRoot).child("proxies.xml")
+ proxies.setContent(proxiesFile.getContent())
+
+
def createHierarchy(self, structure, root=None):
if root is None:
root = os.path.abspath(self.mktemp())
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py 2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py 2014-03-25 23:19:18 UTC (rev 12995)
@@ -36,7 +36,6 @@
from txweb2.dav.fileop import rmdir
from twistedcaldav import caldavxml
-from twistedcaldav.directory import calendaruserproxy
from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
@@ -63,9 +62,9 @@
from twext.who.idirectory import RecordType
from txdav.who.idirectory import RecordType as CalRecordType
from txdav.who.delegates import addDelegate
+from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
-
deadPropertyXattrPrefix = namedAny(
"txdav.base.propertystore.xattr.PropertyStore.deadPropertyXattrPrefix"
)
@@ -1009,35 +1008,17 @@
log.warn("Migrated %d auto-schedule settings" % (len(augmentRecords),))
- at inlineCallbacks
-def migrateDelegatesToStore(config, store):
- """
- If there is an sqlite file of delegates, migrate them into the store.
- """
- if config.ProxyDBService.type != "twistedcaldav.directory.calendaruserproxy.ProxySqliteDB":
- returnValue(None)
+def loadDelegatesFromXML(xmlFile, service):
+ loader = XMLCalendarUserProxyLoader(xmlFile, service)
+ return loader.updateProxyDB()
- dbPath = os.path.join(config.DataRoot, config.ProxyDBService.params.dbpath)
- if not os.path.exists(dbPath):
- returnValue(None)
- proxyClass = namedClass(config.ProxyDBService.type)
- try:
- proxyService = proxyClass(**config.ProxyDBService.params)
- except:
- log.error("Could not migrate delegates to store")
- returnValue(None)
-
- yield _migrateDelegatesToStore(proxyService, store)
- os.remove(dbPath)
-
-
@inlineCallbacks
-def _migrateDelegatesToStore(oldProxyService, store):
+def migrateDelegatesToStore(service, store):
directory = store.directoryService()
txn = store.newTransaction()
for groupName, memberUID in (
- yield oldProxyService.query(
+ yield service.query(
"select GROUPNAME, MEMBER from GROUPS"
)
):
@@ -1132,13 +1113,24 @@
# directory = self.store.directoryService()
# Load proxy assignments from XML if specified
- if self.config.ProxyLoadFromFile:
- proxydbClass = namedClass(self.config.ProxyDBService.type)
- calendaruserproxy.ProxyDBService = proxydbClass(
- **self.config.ProxyDBService.params)
- loader = XMLCalendarUserProxyLoader(self.config.ProxyLoadFromFile)
- yield loader.updateProxyDB()
+ if (
+ self.config.ProxyLoadFromFile and
+ os.path.exists(self.config.ProxyLoadFromFile) and
+ not os.path.exists(
+ os.path.join(
+ self.config.DataRoot, "proxies.sqlite"
+ )
+ )
+ ):
+ sqliteProxyService = ProxySqliteDB("proxies.sqlite")
+ yield loadDelegatesFromXML(
+ self.config.ProxyLoadFromFile,
+ sqliteProxyService
+ )
+ else:
+ sqliteProxyService = None
+
# # Populate the group membership cache
# if (self.config.GroupCaching.Enabled and
# self.config.GroupCaching.EnableUpdater):
@@ -1171,7 +1163,9 @@
yield migrateTokensToStore(self.config.DataRoot, self.store)
# Migrate delegate assignments from sqlite to store
- yield migrateDelegatesToStore(self.config, self.store)
+ if sqliteProxyService is None:
+ sqliteProxyService = ProxySqliteDB("proxies.sqlite")
+ yield migrateDelegatesToStore(sqliteProxyService, self.store)
@inlineCallbacks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140325/97ad56f4/attachment-0001.html>
More information about the calendarserver-changes
mailing list