[CalendarServer-changes] [14076] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 13 10:11:18 PDT 2014


Revision: 14076
          http://trac.calendarserver.org//changeset/14076
Author:   cdaboo at apple.com
Date:     2014-10-13 10:11:18 -0700 (Mon, 13 Oct 2014)
Log Message:
-----------
Change augments conversion to only write out new file if there were changes. Also use the xmlutil apis so that proper XML file header is used.

Modified Paths:
--------------
    CalendarServer/trunk/conf/auth/augments-default.xml
    CalendarServer/trunk/conf/auth/augments-test.xml
    CalendarServer/trunk/twistedcaldav/test/test_upgrade.py
    CalendarServer/trunk/twistedcaldav/upgrade.py

Modified: CalendarServer/trunk/conf/auth/augments-default.xml
===================================================================
--- CalendarServer/trunk/conf/auth/augments-default.xml	2014-10-13 14:57:29 UTC (rev 14075)
+++ CalendarServer/trunk/conf/auth/augments-default.xml	2014-10-13 17:11:18 UTC (rev 14076)
@@ -1,5 +1,23 @@
 <?xml version="1.0" encoding="utf-8"?>
+
+<!--
+Copyright (c) 2006-2014 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.
+ -->
+
 <!DOCTYPE augments SYSTEM "augments.dtd">
+
 <augments>
   <record>
     <uid>Default</uid>

Modified: CalendarServer/trunk/conf/auth/augments-test.xml
===================================================================
--- CalendarServer/trunk/conf/auth/augments-test.xml	2014-10-13 14:57:29 UTC (rev 14075)
+++ CalendarServer/trunk/conf/auth/augments-test.xml	2014-10-13 17:11:18 UTC (rev 14076)
@@ -1,3 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+Copyright (c) 2006-2014 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.
+ -->
+
+<!DOCTYPE augments SYSTEM "augments.dtd">
+
 <augments>
 <record>
     <uid>Default</uid>
@@ -59,4 +79,4 @@
     <auto-schedule-mode>decline-always</auto-schedule-mode>
     <auto-accept-group>20000000-0000-0000-0000-000000000001</auto-accept-group>
 </record>
-</augments>
\ No newline at end of file
+</augments>

Modified: CalendarServer/trunk/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_upgrade.py	2014-10-13 14:57:29 UTC (rev 14075)
+++ CalendarServer/trunk/twistedcaldav/test/test_upgrade.py	2014-10-13 17:11:18 UTC (rev 14076)
@@ -1548,7 +1548,9 @@
 
 
 
-oldAugmentsFormat = """<augments>
+oldAugmentsFormat = """<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE augments SYSTEM "augments.dtd">
+<augments>
   <record>
     <uid>9F3603DD-65D0-480D-A1D1-5D33CAC41A13</uid>
     <enable>true</enable>
@@ -1583,7 +1585,7 @@
     <auto-schedule>false</auto-schedule>
     <auto-schedule-mode>automatic</auto-schedule-mode>
   </record>
-    <record>
+  <record>
     <uid>FC9A7F56-CCCA-4401-9160-903902880A37</uid>
     <enable>false</enable>
     <enable-calendar>true</enable-calendar>
@@ -1595,9 +1597,48 @@
 </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-s
 chedule-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>"""
+newAugmentsFormat = """<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE augments SYSTEM "augments.dtd">
 
+<augments>
+  <record>
+    <uid>9F3603DD-65D0-480D-A1D1-5D33CAC41A13</uid>
+    <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>6A49C436-4CDB-4184-AD87-6F945040E37A</uid>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+  </record>
+  <record>
+    <uid>60B771CC-D727-4453-ACE0-0FE13CD7445A</uid>
+    <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-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule-mode>none</auto-schedule-mode>
+  </record>
+  <record>
+    <uid>FC9A7F56-CCCA-4401-9160-903902880A37</uid>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+    <enable-login>true</enable-login>
+    <auto-schedule-mode>accept-if-free</auto-schedule-mode>
+  </record>
+</augments>
+"""
 
+
 normalizeEvent = """BEGIN:VCALENDAR
 VERSION:2.0
 BEGIN:VEVENT

Modified: CalendarServer/trunk/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/upgrade.py	2014-10-13 14:57:29 UTC (rev 14075)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py	2014-10-13 17:11:18 UTC (rev 14076)
@@ -36,19 +36,26 @@
     tostring as etreeToString, Element as XMLElement
 )
 
-from twext.python.log import Logger
-from txdav.xml import element
 from txweb2.dav.fileop import rmdir
 
 from twistedcaldav import caldavxml
+from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
 from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
 from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
 from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
+from twistedcaldav.directory.xmlaugmentsparser import ELEMENT_AUGMENTS
 from twistedcaldav.ical import Component
+from twistedcaldav.xmlutil import readXML, writeXML
+
+from txdav.caldav.datastore.index_file import db_basename
 from txdav.caldav.datastore.scheduling.cuaddress import LocalCalendarUser
 from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
+from txdav.caldav.datastore.scheduling.imip.mailgateway import migrateTokensToStore
 from txdav.caldav.datastore.scheduling.scheduler import DirectScheduler
 from txdav.caldav.datastore.util import normalizationLookup
+from txdav.who.delegates import addDelegate
+from txdav.who.idirectory import RecordType as CalRecordType
+from txdav.xml import element
 
 from twisted.internet.defer import (
     inlineCallbacks, succeed, returnValue
@@ -57,16 +64,10 @@
 from twisted.python.reflect import namedAny
 from twisted.python.reflect import namedClass
 
-from txdav.caldav.datastore.index_file import db_basename
-
 from calendarserver.tap.util import getRootResource, FakeRequest
 
-from txdav.caldav.datastore.scheduling.imip.mailgateway import migrateTokensToStore
-
+from twext.python.log import Logger
 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(
@@ -715,24 +716,16 @@
     @param augmentsFilePath: the file to convert
     @type augmentsFilePath: L{FilePath}
     """
+    # Read in XML
     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)
+        _ignore_tree, augments_node = readXML(augmentsFilePath.path, ELEMENT_AUGMENTS)
+    except ValueError:
+        log.error("Cannot parse {path}", path=augmentsFilePath.path)
         return
 
-    augmentsNode = etree.getroot()
-    if augmentsNode.tag != "augments":
-        return
-
     log.info("Converting augments.xml")
-    for recordNode in augmentsNode:
+    changed = False
+    for recordNode in augments_node:
 
         autoScheduleElement = recordNode.find("auto-schedule")
         if autoScheduleElement is not None:
@@ -741,12 +734,15 @@
                 if autoScheduleModeElement is not None:
                     autoScheduleModeElement.text = "none"
             recordNode.remove(autoScheduleElement)
+            changed = True
 
         enableElement = recordNode.find("enable")
         if enableElement is not None:
             recordNode.remove(enableElement)
+            changed = True
 
-    augmentsFilePath.setContent(etreeToString(augmentsNode, "utf-8"))
+    if changed:
+        writeXML(augmentsFilePath.path, augments_node)
 
 
 # The on-disk version number (which defaults to zero if .calendarserver_version
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141013/a400b309/attachment-0001.html>


More information about the calendarserver-changes mailing list