[CalendarServer-changes] [14031] CalendarServer/branches/release/CalendarServer-6.0-dev/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 30 09:22:02 PDT 2014


Revision: 14031
          http://trac.calendarserver.org//changeset/14031
Author:   sagen at apple.com
Date:     2014-09-30 09:22:02 -0700 (Tue, 30 Sep 2014)
Log Message:
-----------
Update augments.xml during upgrade

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/augment.py
    CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_augment.py
    CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_principal.py
    CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/stdconfig.py
    CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/test/test_upgrade.py
    CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/upgrade.py

Modified: CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/augment.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/augment.py	2014-09-30 14:24:55 UTC (rev 14030)
+++ CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/augment.py	2014-09-30 16:22:02 UTC (rev 14031)
@@ -25,8 +25,6 @@
 from twext.python.log import Logger
 
 from twistedcaldav.config import fullServerPath, config
-from twistedcaldav.database import AbstractADBAPIDatabase, ADBAPISqliteMixin, \
-    ADBAPIPostgreSQLMixin
 from twistedcaldav.directory import xmlaugmentsparser
 from twistedcaldav.directory.xmlaugmentsparser import XMLAugmentsParser
 from twistedcaldav.xmlutil import newElementTreeWithRoot, addSubElement, \
@@ -469,13 +467,11 @@
     def _updateRecordInXMLDB(self, record, recordNode):
         del recordNode[:]
         addSubElement(recordNode, xmlaugmentsparser.ELEMENT_UID, record.uid)
-        addSubElement(recordNode, xmlaugmentsparser.ELEMENT_ENABLE, "true" if record.enabled else "false")
         if record.serverID:
             addSubElement(recordNode, xmlaugmentsparser.ELEMENT_SERVERID, record.serverID)
         addSubElement(recordNode, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true" if record.enabledForCalendaring else "false")
         addSubElement(recordNode, xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK, "true" if record.enabledForAddressBooks else "false")
         addSubElement(recordNode, xmlaugmentsparser.ELEMENT_ENABLELOGIN, "true" if record.enabledForLogin else "false")
-        addSubElement(recordNode, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE, "true" if record.autoSchedule else "false")
         if record.autoScheduleMode:
             addSubElement(recordNode, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE_MODE, record.autoScheduleMode)
         if record.autoAcceptGroup:
@@ -556,235 +552,3 @@
                     self.xmlFileStats[xmlFile] = (newModTime, newSize)
 
         return results
-
-
-
-class AugmentADAPI(AugmentDB, AbstractADBAPIDatabase):
-    """
-    DBAPI based augment database implementation.
-    """
-
-    schema_version = "3"
-    schema_type = "AugmentDB"
-
-    def __init__(self, dbID, dbapiName, dbapiArgs, **kwargs):
-
-        AugmentDB.__init__(self)
-        AbstractADBAPIDatabase.__init__(self, dbID, dbapiName, dbapiArgs, True, **kwargs)
-
-
-    @inlineCallbacks
-    def getAllUIDs(self):
-        """
-        Get all AugmentRecord UIDs.
-
-        @return: L{Deferred}
-        """
-
-        # Query for the record information
-        results = (yield self.queryList("select UID from AUGMENTS", ()))
-        returnValue(results)
-
-
-    @inlineCallbacks
-    def _lookupAugmentRecord(self, uid):
-        """
-        Get an AugmentRecord for the specified UID.
-
-        @param uid: directory UID to lookup
-        @type uid: C{str}
-
-        @return: L{Deferred}
-        """
-
-        # Query for the record information
-        results = (yield self.query("select UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED from AUGMENTS where UID = :1", (uid,)))
-        if not results:
-            returnValue(None)
-        else:
-            uid, enabled, serverid, enabledForCalendaring, enabledForAddressBooks, autoSchedule, autoScheduleMode, autoAcceptGroup, enabledForLogin = results[0]
-
-            record = AugmentRecord(
-                uid=uid,
-                enabled=enabled == "T",
-                serverID=serverid,
-                enabledForCalendaring=enabledForCalendaring == "T",
-                enabledForAddressBooks=enabledForAddressBooks == "T",
-                enabledForLogin=enabledForLogin == "T",
-                autoSchedule=autoSchedule == "T",
-                autoScheduleMode=autoScheduleMode,
-                autoAcceptGroup=autoAcceptGroup,
-            )
-
-            returnValue(record)
-
-
-    @inlineCallbacks
-    def addAugmentRecords(self, records):
-
-        for record in records:
-
-            results = (yield self.query("select UID from AUGMENTS where UID = :1", (record.uid,)))
-            update = len(results) > 0
-
-            if update:
-                yield self._modifyRecord(record)
-            else:
-                yield self._addRecord(record)
-
-
-    @inlineCallbacks
-    def removeAugmentRecords(self, uids):
-        """
-        Remove AugmentRecords with the specified UIDs.
-
-        @param uids: list of uids to remove
-        @type uids: C{list} of C{str}
-
-        @return: L{Deferred}
-        """
-
-        for uid in uids:
-            yield self.execute("delete from AUGMENTS where UID = :1", (uid,))
-
-
-    def clean(self):
-        """
-        Remove all records.
-        """
-
-        return self.execute("delete from AUGMENTS", ())
-
-
-    def _db_version(self):
-        """
-        @return: the schema version assigned to this index.
-        """
-        return AugmentADAPI.schema_version
-
-
-    def _db_type(self):
-        """
-        @return: the collection type assigned to this index.
-        """
-        return AugmentADAPI.schema_type
-
-
-    @inlineCallbacks
-    def _db_init_data_tables(self):
-        """
-        Initialize the underlying database tables.
-        """
-
-        #
-        # AUGMENTS table
-        #
-        yield self._create_table(
-            "AUGMENTS",
-            (
-                ("UID", "text unique"),
-                ("ENABLED", "text(1)"),
-                ("SERVERID", "text"),
-                ("CALENDARING", "text(1)"),
-                ("ADDRESSBOOKS", "text(1)"),
-                ("AUTOSCHEDULE", "text(1)"),
-                ("AUTOSCHEDULEMODE", "text"),
-                ("AUTOACCEPTGROUP", "text"),
-                ("LOGINENABLED", "text(1)"),
-            ),
-            ifnotexists=True,
-        )
-
-
-    @inlineCallbacks
-    def _db_empty_data_tables(self):
-        yield self._db_execute("delete from AUGMENTS")
-
-
-
-class AugmentSqliteDB(ADBAPISqliteMixin, AugmentADAPI):
-    """
-    Sqlite based augment database implementation.
-    """
-
-    def __init__(self, dbpath):
-
-        ADBAPISqliteMixin.__init__(self)
-        AugmentADAPI.__init__(self, "Augments", "sqlite3", (fullServerPath(config.DataRoot, dbpath),))
-
-
-    @inlineCallbacks
-    def _addRecord(self, record):
-        yield self.execute(
-            """insert or replace into AUGMENTS
-            (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED)
-            values (:1, :2, :3, :4, :5, :6, :7, :8, :9)""",
-            (
-                record.uid,
-                "T" if record.enabled else "F",
-                record.serverID,
-                "T" if record.enabledForCalendaring else "F",
-                "T" if record.enabledForAddressBooks else "F",
-                "T" if record.autoSchedule else "F",
-                record.autoScheduleMode if record.autoScheduleMode else "",
-                record.autoAcceptGroup,
-                "T" if record.enabledForLogin else "F",
-            )
-        )
-
-
-    def _modifyRecord(self, record):
-        return self._addRecord(record)
-
-
-
-class AugmentPostgreSQLDB(ADBAPIPostgreSQLMixin, AugmentADAPI):
-    """
-    PostgreSQL based augment database implementation.
-    """
-
-    def __init__(self, host, database, user=None, password=None):
-
-        ADBAPIPostgreSQLMixin.__init__(self)
-        AugmentADAPI.__init__(self, "Augments", "pgdb", (), host=host, database=database, user=user, password=password,)
-
-
-    @inlineCallbacks
-    def _addRecord(self, record):
-        yield self.execute(
-            """insert into AUGMENTS
-            (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED)
-            values (:1, :2, :3, :4, :5, :6, :7, :8, :9)""",
-            (
-                record.uid,
-                "T" if record.enabled else "F",
-                record.serverID,
-                "T" if record.enabledForCalendaring else "F",
-                "T" if record.enabledForAddressBooks else "F",
-                "T" if record.autoSchedule else "F",
-                record.autoScheduleMode if record.autoScheduleMode else "",
-                record.autoAcceptGroup,
-                "T" if record.enabledForLogin else "F",
-            )
-        )
-
-
-    @inlineCallbacks
-    def _modifyRecord(self, record):
-        yield self.execute(
-            """update AUGMENTS set
-            (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED) =
-            (:1, :2, :3, :4, :5, :6, :7, :8, :9) where UID = :10""",
-            (
-                record.uid,
-                "T" if record.enabled else "F",
-                record.serverID,
-                "T" if record.enabledForCalendaring else "F",
-                "T" if record.enabledForAddressBooks else "F",
-                "T" if record.autoSchedule else "F",
-                record.autoScheduleMode if record.autoScheduleMode else "",
-                record.autoAcceptGroup,
-                "T" if record.enabledForLogin else "F",
-                record.uid,
-            )
-        )

Modified: CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_augment.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_augment.py	2014-09-30 14:24:55 UTC (rev 14030)
+++ CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_augment.py	2014-09-30 16:22:02 UTC (rev 14031)
@@ -15,8 +15,7 @@
 ##
 
 from twistedcaldav.test.util import TestCase
-from twistedcaldav.directory.augment import AugmentXMLDB, AugmentSqliteDB, \
-    AugmentPostgreSQLDB, AugmentRecord
+from twistedcaldav.directory.augment import AugmentXMLDB, AugmentRecord
 from twisted.internet.defer import inlineCallbacks
 from twistedcaldav.directory.xmlaugmentsparser import XMLAugmentsParser
 import cStringIO
@@ -342,26 +341,3 @@
         uids = list(self.uidsFromFile(newxmlfile.path))
         self.assertEquals(uids, ['AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'])
 
-
-
-class AugmentSqliteTests(AugmentTests, AugmentTestsMixin):
-
-    def _db(self, dbpath=None):
-        return AugmentSqliteDB(dbpath if dbpath else os.path.abspath(self.mktemp()))
-
-
-
-class AugmentPostgreSQLTests(AugmentTests, AugmentTestsMixin):
-
-    def _db(self, dbpath=None):
-        return AugmentPostgreSQLDB("localhost", "augments")
-
-try:
-    import pgdb
-except ImportError:
-    AugmentPostgreSQLTests.skip = True
-else:
-    try:
-        db = pgdb.connect(host="localhost", database="augments")
-    except:
-        AugmentPostgreSQLTests.skip = True

Modified: CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_principal.py	2014-09-30 14:24:55 UTC (rev 14030)
+++ CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/directory/test/test_principal.py	2014-09-30 16:22:02 UTC (rev 14031)
@@ -429,9 +429,6 @@
                 yield hasProperty(
                     (calendarserver_namespace, "calendar-proxy-write-for")
                 )
-                # yield hasProperty(
-                #     (calendarserver_namespace, "auto-schedule")
-                # )
             else:
                 yield doesNotHaveProperty(
                     (caldav_namespace, "calendar-home-set")
@@ -454,9 +451,6 @@
                 yield doesNotHaveProperty(
                     (calendarserver_namespace, "calendar-proxy-write-for")
                 )
-                # yield doesNotHaveProperty(
-                #     (calendarserver_namespace, "auto-schedule")
-                # )
 
             if record.hasContacts:
                 yield hasProperty(carddavxml.AddressBookHomeSet.qname())

Modified: CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/stdconfig.py	2014-09-30 14:24:55 UTC (rev 14030)
+++ CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/stdconfig.py	2014-09-30 16:22:02 UTC (rev 14031)
@@ -101,15 +101,6 @@
         "xmlFiles": ["augments.xml", ],
         "statSeconds": 15,
     },
-    "twistedcaldav.directory.augment.AugmentSqliteDB": {
-        "dbpath": "augments.sqlite",
-    },
-    "twistedcaldav.directory.augment.AugmentPostgreSQLDB": {
-        "host": "localhost",
-        "database": "augments",
-        "user": "",
-        "password": "",
-    },
 }
 
 

Modified: CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/test/test_upgrade.py	2014-09-30 14:24:55 UTC (rev 14030)
+++ CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/test/test_upgrade.py	2014-09-30 16:22:02 UTC (rev 14031)
@@ -28,7 +28,7 @@
     xattrname, upgradeData, updateFreeBusySet,
     removeIllegalCharacters, normalizeCUAddrs,
     loadDelegatesFromXMLintoProxyDB, migrateDelegatesToStore,
-    upgradeResourcesXML
+    upgradeResourcesXML, upgradeAugmentsXML
 )
 from txdav.caldav.datastore.index_file import db_basename
 from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
@@ -1514,6 +1514,17 @@
         self.assertEquals(fp.getContent(), newResourcesFormat)
 
 
+    def test_augmentsXML(self):
+        """
+        Verify conversion of old augments.xml auto-schedule related elements to twext.who format
+        """
+        fileName = self.mktemp()
+        fp = FilePath(fileName)
+        fp.setContent(oldAugmentsFormat)
+        upgradeAugmentsXML(fp)
+        self.assertEquals(fp.getContent(), newAugmentsFormat)
+
+
 oldResourcesFormat = """<accounts realm="/Search">
   <location>
     <uid>location1</uid>
@@ -1536,6 +1547,58 @@
 newResourcesFormat = """<directory realm="/Search"><record type="location"><short-name>location1</short-name><guid>C4F46062-9094-4D34-8591-61A42D993FAA</guid><uid>C4F46062-9094-4D34-8591-61A42D993FAA</uid><full-name>location name</full-name></record><record type="location"><short-name>5456580A-08EE-4288-8A87-2B4204A62A12</short-name><guid>5456580A-08EE-4288-8A87-2B4204A62A12</guid><uid>5456580A-08EE-4288-8A87-2B4204A62A12</uid><full-name>Fake Room</full-name></record><record type="resource"><short-name>resource1</short-name><guid>60B771CC-D727-4453-ACE0-0FE13CD7445A</guid><uid>60B771CC-D727-4453-ACE0-0FE13CD7445A</uid><full-name>resource name</full-name></record></directory>"""
 
 
+
+
+oldAugmentsFormat = """<augments>
+  <record>
+    <uid>9F3603DD-65D0-480D-A1D1-5D33CAC41A13</uid>
+    <enable>true</enable>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule>false</auto-schedule>
+    <auto-schedule-mode>default</auto-schedule-mode>
+  </record>
+  <record>
+    <uid>6A49C436-4CDB-4184-AD87-6F945040E37A</uid>
+    <enable>true</enable>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule>true</auto-schedule>
+  </record>
+  <record>
+    <uid>60B771CC-D727-4453-ACE0-0FE13CD7445A</uid>
+    <enable>true</enable>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule-mode>none</auto-schedule-mode>
+  </record>
+  <record>
+    <uid>E173AADC-4642-43CB-9745-8CE436A6FE4A</uid>
+    <enable>false</enable>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule>false</auto-schedule>
+    <auto-schedule-mode>automatic</auto-schedule-mode>
+  </record>
+    <record>
+    <uid>FC9A7F56-CCCA-4401-9160-903902880A37</uid>
+    <enable>false</enable>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule>true</auto-schedule>
+    <auto-schedule-mode>accept-if-free</auto-schedule-mode>
+  </record>
+</augments>
+"""
+
+newAugmentsFormat = """<augments>\n  <record>\n    <uid>9F3603DD-65D0-480D-A1D1-5D33CAC41A13</uid>\n    <enable-calendar>true</enable-calendar>\n    <enable-addressbook>true</enable-addressbook>\n    <enable-login>true</enable-login>\n    <auto-schedule-mode>none</auto-schedule-mode>\n  </record>\n  <record>\n    <uid>6A49C436-4CDB-4184-AD87-6F945040E37A</uid>\n    <enable-calendar>true</enable-calendar>\n    <enable-addressbook>true</enable-addressbook>\n    <enable-login>true</enable-login>\n    </record>\n  <record>\n    <uid>60B771CC-D727-4453-ACE0-0FE13CD7445A</uid>\n    <enable-calendar>true</enable-calendar>\n    <enable-addressbook>true</enable-addressbook>\n    <enable-login>true</enable-login>\n    <auto-schedule-mode>none</auto-schedule-mode>\n  </record>\n  <record>\n    <uid>E173AADC-4642-43CB-9745-8CE436A6FE4A</uid>\n    <enable-calendar>true</enable-calendar>\n    <enable-addressbook>true</enable-addressbook>\n    <enable-login>true</enable-login>\n    <auto-schedule-mode>none</auto-schedule-mode>\n  </record>\n    <record>\n    <uid>FC9A7F56-CCCA-4401-9160-903902880A37</uid>\n    <enable-calendar>true</enable-calendar>\n    <enable-addressbook>true</enable-addressbook>\n    <enable-login>true</enable-login>\n    <auto-schedule-mode>accept-if-free</auto-schedule-mode>\n  </record>\n</augments>"""
+
+
 normalizeEvent = """BEGIN:VCALENDAR
 VERSION:2.0
 BEGIN:VEVENT

Modified: CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/upgrade.py	2014-09-30 14:24:55 UTC (rev 14030)
+++ CalendarServer/branches/release/CalendarServer-6.0-dev/twistedcaldav/upgrade.py	2014-09-30 16:22:02 UTC (rev 14031)
@@ -707,6 +707,47 @@
     resourcesFilePath.setContent(etreeToString(directoryNode, "utf-8"))
 
 
+def upgradeAugmentsXML(augmentsFilePath):
+    """
+    Convert the old augments XML auto-schedule related elements to the twext.who.xml format
+
+    @param augmentsFilePath: the file to convert
+    @type augmentsFilePath: L{FilePath}
+    """
+    try:
+        with augmentsFilePath.open() as fh:
+            try:
+                etree = parseXML(fh)
+            except XMLParseError:
+                log.error("Cannot parse {path}", path=augmentsFilePath.path)
+                return
+    except (OSError, IOError):
+        # Can't read the file
+        log.error("Cannot read {path}", path=augmentsFilePath.path)
+        return
+
+    augmentsNode = etree.getroot()
+    if augmentsNode.tag != "augments":
+        return
+
+    log.info("Converting augments.xml")
+    for recordNode in augmentsNode:
+
+        autoScheduleElement = recordNode.find("auto-schedule")
+        if autoScheduleElement is not None:
+            if autoScheduleElement.text == "false":
+                autoScheduleModeElement = recordNode.find("auto-schedule-mode")
+                if autoScheduleModeElement is not None:
+                    autoScheduleModeElement.text = "none"
+            recordNode.remove(autoScheduleElement)
+
+        enableElement = recordNode.find("enable")
+        if enableElement is not None:
+            recordNode.remove(enableElement)
+
+    augmentsFilePath.setContent(etreeToString(augmentsNode, "utf-8"))
+
+
 # The on-disk version number (which defaults to zero if .calendarserver_version
 # doesn't exist), is compared with each of the numbers in the upgradeMethods
 # array.  If it is less than the number, the associated method is called.
@@ -728,6 +769,14 @@
         if resourcesFilePath.exists():
             upgradeResourcesXML(resourcesFilePath)
 
+    if config.AugmentService.type == "twistedcaldav.directory.augment.AugmentXMLDB":
+        for fileName in config.AugmentService.params.xmlFiles:
+            if fileName[0] not in ("/", "."):
+                fileName = os.path.join(config.DataRoot, fileName)
+            filePath = FilePath(fileName)
+            if filePath.exists():
+                upgradeAugmentsXML(filePath)
+
     triggerPath = os.path.join(config.ServerRoot, TRIGGER_FILE)
     if os.path.exists(triggerPath):
         try:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140930/ca5b728f/attachment-0001.html>


More information about the calendarserver-changes mailing list