<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14019] CalendarServer/trunk/twistedcaldav</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14019">14019</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-09-29 16:31:24 -0700 (Mon, 29 Sep 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Convert old auto-schedule augments XML elements to new format</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavdirectoryaugmentpy">CalendarServer/trunk/twistedcaldav/directory/augment.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavdirectorytesttest_principalpy">CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavtesttest_upgradepy">CalendarServer/trunk/twistedcaldav/test/test_upgrade.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavupgradepy">CalendarServer/trunk/twistedcaldav/upgrade.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavdirectoryaugmentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/directory/augment.py (14018 => 14019)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/directory/augment.py        2014-09-29 15:51:07 UTC (rev 14018)
+++ CalendarServer/trunk/twistedcaldav/directory/augment.py        2014-09-29 23:31:24 UTC (rev 14019)
</span><span class="lines">@@ -596,11 +596,11 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> # Query for the record information
</span><del>- results = (yield self.query("select UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED from AUGMENTS where UID = :1", (uid,)))
</del><ins>+ results = (yield self.query("select UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED from AUGMENTS where UID = :1", (uid,)))
</ins><span class="cx"> if not results:
</span><span class="cx"> returnValue(None)
</span><span class="cx"> else:
</span><del>- uid, enabled, serverid, enabledForCalendaring, enabledForAddressBooks, autoSchedule, autoScheduleMode, autoAcceptGroup, enabledForLogin = results[0]
</del><ins>+ uid, enabled, serverid, enabledForCalendaring, enabledForAddressBooks, autoScheduleMode, autoAcceptGroup, enabledForLogin = results[0]
</ins><span class="cx">
</span><span class="cx"> record = AugmentRecord(
</span><span class="cx"> uid=uid,
</span><span class="lines">@@ -609,7 +609,6 @@
</span><span class="cx"> enabledForCalendaring=enabledForCalendaring == "T",
</span><span class="cx"> enabledForAddressBooks=enabledForAddressBooks == "T",
</span><span class="cx"> enabledForLogin=enabledForLogin == "T",
</span><del>- autoSchedule=autoSchedule == "T",
</del><span class="cx"> autoScheduleMode=autoScheduleMode,
</span><span class="cx"> autoAcceptGroup=autoAcceptGroup,
</span><span class="cx"> )
</span><span class="lines">@@ -685,7 +684,6 @@
</span><span class="cx"> ("SERVERID", "text"),
</span><span class="cx"> ("CALENDARING", "text(1)"),
</span><span class="cx"> ("ADDRESSBOOKS", "text(1)"),
</span><del>- ("AUTOSCHEDULE", "text(1)"),
</del><span class="cx"> ("AUTOSCHEDULEMODE", "text"),
</span><span class="cx"> ("AUTOACCEPTGROUP", "text"),
</span><span class="cx"> ("LOGINENABLED", "text(1)"),
</span><span class="lines">@@ -715,15 +713,14 @@
</span><span class="cx"> def _addRecord(self, record):
</span><span class="cx"> yield self.execute(
</span><span class="cx"> """insert or replace into AUGMENTS
</span><del>- (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED)
- values (:1, :2, :3, :4, :5, :6, :7, :8, :9)""",
</del><ins>+ (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED)
+ values (:1, :2, :3, :4, :5, :6, :7, :8)""",
</ins><span class="cx"> (
</span><span class="cx"> record.uid,
</span><span class="cx"> "T" if record.enabled else "F",
</span><span class="cx"> record.serverID,
</span><span class="cx"> "T" if record.enabledForCalendaring else "F",
</span><span class="cx"> "T" if record.enabledForAddressBooks else "F",
</span><del>- "T" if record.autoSchedule else "F",
</del><span class="cx"> record.autoScheduleMode if record.autoScheduleMode else "",
</span><span class="cx"> record.autoAcceptGroup,
</span><span class="cx"> "T" if record.enabledForLogin else "F",
</span><span class="lines">@@ -751,15 +748,14 @@
</span><span class="cx"> def _addRecord(self, record):
</span><span class="cx"> yield self.execute(
</span><span class="cx"> """insert into AUGMENTS
</span><del>- (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED)
- values (:1, :2, :3, :4, :5, :6, :7, :8, :9)""",
</del><ins>+ (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED)
+ values (:1, :2, :3, :4, :5, :6, :7, :8)""",
</ins><span class="cx"> (
</span><span class="cx"> record.uid,
</span><span class="cx"> "T" if record.enabled else "F",
</span><span class="cx"> record.serverID,
</span><span class="cx"> "T" if record.enabledForCalendaring else "F",
</span><span class="cx"> "T" if record.enabledForAddressBooks else "F",
</span><del>- "T" if record.autoSchedule else "F",
</del><span class="cx"> record.autoScheduleMode if record.autoScheduleMode else "",
</span><span class="cx"> record.autoAcceptGroup,
</span><span class="cx"> "T" if record.enabledForLogin else "F",
</span><span class="lines">@@ -771,15 +767,14 @@
</span><span class="cx"> def _modifyRecord(self, record):
</span><span class="cx"> yield self.execute(
</span><span class="cx"> """update AUGMENTS set
</span><del>- (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED) =
- (:1, :2, :3, :4, :5, :6, :7, :8, :9) where UID = :10""",
</del><ins>+ (UID, ENABLED, SERVERID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULEMODE, AUTOACCEPTGROUP, LOGINENABLED) =
+ (:1, :2, :3, :4, :5, :6, :7, :8) where UID = :9""",
</ins><span class="cx"> (
</span><span class="cx"> record.uid,
</span><span class="cx"> "T" if record.enabled else "F",
</span><span class="cx"> record.serverID,
</span><span class="cx"> "T" if record.enabledForCalendaring else "F",
</span><span class="cx"> "T" if record.enabledForAddressBooks else "F",
</span><del>- "T" if record.autoSchedule else "F",
</del><span class="cx"> record.autoScheduleMode if record.autoScheduleMode else "",
</span><span class="cx"> record.autoAcceptGroup,
</span><span class="cx"> "T" if record.enabledForLogin else "F",
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavdirectorytesttest_principalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py (14018 => 14019)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py        2014-09-29 15:51:07 UTC (rev 14018)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py        2014-09-29 23:31:24 UTC (rev 14019)
</span><span class="lines">@@ -429,9 +429,6 @@
</span><span class="cx"> yield hasProperty(
</span><span class="cx"> (calendarserver_namespace, "calendar-proxy-write-for")
</span><span class="cx"> )
</span><del>- # yield hasProperty(
- # (calendarserver_namespace, "auto-schedule")
- # )
</del><span class="cx"> else:
</span><span class="cx"> yield doesNotHaveProperty(
</span><span class="cx"> (caldav_namespace, "calendar-home-set")
</span><span class="lines">@@ -454,9 +451,6 @@
</span><span class="cx"> yield doesNotHaveProperty(
</span><span class="cx"> (calendarserver_namespace, "calendar-proxy-write-for")
</span><span class="cx"> )
</span><del>- # yield doesNotHaveProperty(
- # (calendarserver_namespace, "auto-schedule")
- # )
</del><span class="cx">
</span><span class="cx"> if record.hasContacts:
</span><span class="cx"> yield hasProperty(carddavxml.AddressBookHomeSet.qname())
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavtesttest_upgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/test/test_upgrade.py (14018 => 14019)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/test/test_upgrade.py        2014-09-29 15:51:07 UTC (rev 14018)
+++ CalendarServer/trunk/twistedcaldav/test/test_upgrade.py        2014-09-29 23:31:24 UTC (rev 14019)
</span><span class="lines">@@ -28,7 +28,7 @@
</span><span class="cx"> xattrname, upgradeData, updateFreeBusySet,
</span><span class="cx"> removeIllegalCharacters, normalizeCUAddrs,
</span><span class="cx"> loadDelegatesFromXMLintoProxyDB, migrateDelegatesToStore,
</span><del>- upgradeResourcesXML
</del><ins>+ upgradeResourcesXML, upgradeAugmentsXML
</ins><span class="cx"> )
</span><span class="cx"> from txdav.caldav.datastore.index_file import db_basename
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
</span><span class="lines">@@ -1514,6 +1514,17 @@
</span><span class="cx"> self.assertEquals(fp.getContent(), newResourcesFormat)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ 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)
+
+
</ins><span class="cx"> oldResourcesFormat = """<accounts realm="/Search">
</span><span class="cx"> <location>
</span><span class="cx"> <uid>location1</uid>
</span><span class="lines">@@ -1536,6 +1547,58 @@
</span><span class="cx"> 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>"""
</span><span class="cx">
</span><span class="cx">
</span><ins>+
+
+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>true</enable>\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>true</enable>\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>true</enable>\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>false</enable>\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>false</enable>\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>"""
+
+
</ins><span class="cx"> normalizeEvent = """BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="cx"> BEGIN:VEVENT
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavupgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/upgrade.py (14018 => 14019)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/upgrade.py        2014-09-29 15:51:07 UTC (rev 14018)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py        2014-09-29 23:31:24 UTC (rev 14019)
</span><span class="lines">@@ -707,6 +707,42 @@
</span><span class="cx"> resourcesFilePath.setContent(etreeToString(directoryNode, "utf-8"))
</span><span class="cx">
</span><span class="cx">
</span><ins>+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)
+
+ augmentsFilePath.setContent(etreeToString(augmentsNode, "utf-8"))
+
+
</ins><span class="cx"> # The on-disk version number (which defaults to zero if .calendarserver_version
</span><span class="cx"> # doesn't exist), is compared with each of the numbers in the upgradeMethods
</span><span class="cx"> # array. If it is less than the number, the associated method is called.
</span><span class="lines">@@ -728,6 +764,14 @@
</span><span class="cx"> if resourcesFilePath.exists():
</span><span class="cx"> upgradeResourcesXML(resourcesFilePath)
</span><span class="cx">
</span><ins>+ 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)
+
</ins><span class="cx"> triggerPath = os.path.join(config.ServerRoot, TRIGGER_FILE)
</span><span class="cx"> if os.path.exists(triggerPath):
</span><span class="cx"> try:
</span></span></pre>
</div>
</div>
</body>
</html>