<!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>[13677] CalendarServer/trunk</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/13677">13677</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-06-23 22:18:48 -0700 (Mon, 23 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Convert resources.xml to new format</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkrequirementsstabletxt">CalendarServer/trunk/requirements-stable.txt</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>
<li><a href="#CalendarServertrunktxdavwhowikipy">CalendarServer/trunk/txdav/who/wiki.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-stable.txt (13676 => 13677)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/requirements-stable.txt        2014-06-24 05:07:09 UTC (rev 13676)
+++ CalendarServer/trunk/requirements-stable.txt        2014-06-24 05:18:48 UTC (rev 13677)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx"> # For CalendarServer development, don't try to get these projects from PyPI; use svn.
</span><span class="cx"> 
</span><span class="cx"> -e .
</span><del>--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13660#egg=twextpy
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13676#egg=twextpy
</ins><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
</span><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13621#egg=pycalendar
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavtesttest_upgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/test/test_upgrade.py (13676 => 13677)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/test/test_upgrade.py        2014-06-24 05:07:09 UTC (rev 13676)
+++ CalendarServer/trunk/twistedcaldav/test/test_upgrade.py        2014-06-24 05:18:48 UTC (rev 13677)
</span><span class="lines">@@ -14,26 +14,26 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><ins>+import cPickle
</ins><span class="cx"> import hashlib
</span><span class="cx"> import os
</span><span class="cx"> import zlib
</span><del>-import cPickle
</del><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, succeed
</span><del>-
-from txdav.xml.parser import WebDAVDocument
-from txdav.caldav.datastore.index_file import db_basename
-
</del><ins>+from twisted.python.filepath import FilePath
</ins><span class="cx"> from twistedcaldav.config import config
</span><del>-from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
</del><ins>+from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
+from twistedcaldav.test.util import StoreTestCase
</ins><span class="cx"> from twistedcaldav.upgrade import (
</span><span class="cx">     xattrname, upgradeData, updateFreeBusySet,
</span><span class="cx">     removeIllegalCharacters, normalizeCUAddrs,
</span><del>-    loadDelegatesFromXML, migrateDelegatesToStore
</del><ins>+    loadDelegatesFromXML, migrateDelegatesToStore,
+    upgradeResourcesXML
</ins><span class="cx"> )
</span><del>-from twistedcaldav.test.util import StoreTestCase
</del><ins>+from txdav.caldav.datastore.index_file import db_basename
+from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
</ins><span class="cx"> from txdav.who.delegates import delegatesOf
</span><del>-from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
</del><ins>+from txdav.xml.parser import WebDAVDocument
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1503,7 +1503,34 @@
</span><span class="cx">         yield txn.commit()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def test_resourcesXML(self):
+        &quot;&quot;&quot;
+        Verify conversion of old resources.xml format to twext.who.xml format
+        &quot;&quot;&quot;
+        fileName = self.mktemp()
+        fp = FilePath(fileName)
+        fp.setContent(oldResourcesFormat)
+        upgradeResourcesXML(fp)
+        self.assertEquals(fp.getContent(), newResourcesFormat)
</ins><span class="cx"> 
</span><ins>+
+oldResourcesFormat = &quot;&quot;&quot;&lt;accounts realm=&quot;/Search&quot;&gt;
+  &lt;location&gt;
+    &lt;uid&gt;location1&lt;/uid&gt;
+    &lt;guid&gt;C4F46062-9094-4D34-8591-61A42D993FAA&lt;/guid&gt;
+    &lt;name&gt;location name&lt;/name&gt;
+  &lt;/location&gt;
+  &lt;resource&gt;
+    &lt;uid&gt;resource1&lt;/uid&gt;
+    &lt;guid&gt;60B771CC-D727-4453-ACE0-0FE13CD7445A&lt;/guid&gt;
+    &lt;name&gt;resource name&lt;/name&gt;
+  &lt;/resource&gt;
+&lt;/accounts&gt;
+&quot;&quot;&quot;
+
+newResourcesFormat = &quot;&quot;&quot;&lt;directory realm=&quot;/Search&quot;&gt;&lt;record type=&quot;location&quot;&gt;&lt;short-name&gt;location1&lt;/short-name&gt;&lt;uid&gt;C4F46062-9094-4D34-8591-61A42D993FAA&lt;/uid&gt;&lt;full-name&gt;location name&lt;/full-name&gt;&lt;/record&gt;&lt;record type=&quot;resource&quot;&gt;&lt;short-name&gt;resource1&lt;/short-name&gt;&lt;uid&gt;60B771CC-D727-4453-ACE0-0FE13CD7445A&lt;/uid&gt;&lt;full-name&gt;resource name&lt;/full-name&gt;&lt;/record&gt;&lt;/directory&gt;&quot;&quot;&quot;
+
+
</ins><span class="cx"> normalizeEvent = &quot;&quot;&quot;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 (13676 => 13677)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/upgrade.py        2014-06-24 05:07:09 UTC (rev 13676)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py        2014-06-24 05:18:48 UTC (rev 13677)
</span><span class="lines">@@ -30,6 +30,10 @@
</span><span class="cx"> from zlib import compress
</span><span class="cx"> from cPickle import loads as unpickle, UnpicklingError
</span><span class="cx"> 
</span><ins>+from xml.etree.ElementTree import (
+    parse as parseXML, ParseError as XMLParseError,
+    tostring as etreeToString, Element as XMLElement
+)
</ins><span class="cx"> 
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from txdav.xml import element
</span><span class="lines">@@ -48,6 +52,7 @@
</span><span class="cx"> from twisted.internet.defer import (
</span><span class="cx">     inlineCallbacks, succeed, returnValue
</span><span class="cx"> )
</span><ins>+from twisted.python.filepath import FilePath
</ins><span class="cx"> from twisted.python.reflect import namedAny
</span><span class="cx"> from twisted.python.reflect import namedClass
</span><span class="cx"> 
</span><span class="lines">@@ -646,7 +651,53 @@
</span><span class="cx">         raise UpgradeError(&quot;Data upgrade failed, see error.log for details&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+def upgradeResourcesXML(resourcesFilePath):
+    &quot;&quot;&quot;
+    Convert the old XML format to the twext.who.xml format
</ins><span class="cx"> 
</span><ins>+    @param resourcesFilePath: the file to convert
+    @type resourcesFilePath: L{FilePath}
+    &quot;&quot;&quot;
+    try:
+        with resourcesFilePath.open() as fh:
+            try:
+                etree = parseXML(fh)
+            except XMLParseError:
+                log.error(&quot;Cannot parse {path}&quot;, path=resourcesFilePath.path)
+                return
+    except (OSError, IOError):
+        # Can't read the file
+        log.error(&quot;Cannot read {path}&quot;, path=resourcesFilePath.path)
+        return
+
+    accountsNode = etree.getroot()
+    if accountsNode.tag != &quot;accounts&quot;:
+        return
+
+    tagMap = {
+        &quot;uid&quot;: &quot;short-name&quot;,
+        &quot;guid&quot;: &quot;uid&quot;,
+        &quot;name&quot;: &quot;full-name&quot;,
+    }
+    log.info(&quot;Converting resources.xml&quot;)
+    directoryNode = XMLElement(&quot;directory&quot;)
+    directoryNode.set(&quot;realm&quot;, accountsNode.get(&quot;realm&quot;))
+    for sourceNode in accountsNode:
+        recordType = sourceNode.tag
+        destNode = XMLElement(&quot;record&quot;)
+        destNode.set(&quot;type&quot;, recordType)
+        for sourceFieldNode in sourceNode:
+            tag = tagMap.get(sourceFieldNode.tag, None)
+            if tag:
+                destFieldNode = XMLElement(tag)
+                destFieldNode.text = sourceFieldNode.text
+                destNode.append(destFieldNode)
+
+        directoryNode.append(destNode)
+
+    resourcesFilePath.setContent(etreeToString(directoryNode, &quot;utf-8&quot;))
+
+
</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">@@ -660,6 +711,14 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def upgradeData(config, directory):
</span><span class="cx"> 
</span><ins>+    if config.ResourceService.Enabled:
+        resourcesFileName = config.ResourceService.params.xmlFile
+        if resourcesFileName[0] not in (&quot;/&quot;, &quot;.&quot;):
+            resourcesFileName = os.path.join(config.DataRoot, resourcesFileName)
+        resourcesFilePath = FilePath(resourcesFileName)
+        if resourcesFilePath.exists():
+            upgradeResourcesXML(resourcesFilePath)
+
</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>
<a id="CalendarServertrunktxdavwhowikipy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/wiki.py (13676 => 13677)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/wiki.py        2014-06-24 05:07:09 UTC (rev 13676)
+++ CalendarServer/trunk/txdav/who/wiki.py        2014-06-24 05:18:48 UTC (rev 13677)
</span><span class="lines">@@ -194,6 +194,7 @@
</span><span class="cx">                 &quot;in wiki {log_source}: {error}&quot;,
</span><span class="cx">                 record=record, error=e
</span><span class="cx">             )
</span><ins>+            returnValue(WikiAccessLevel.none)
</ins><span class="cx"> 
</span><span class="cx">         except WebError as e:
</span><span class="cx">             status = int(e.status)
</span><span class="lines">@@ -216,6 +217,7 @@
</span><span class="cx">                 &quot;Unable to look up wiki access: {error}&quot;,
</span><span class="cx">                 record=record, error=e
</span><span class="cx">             )
</span><ins>+            returnValue(WikiAccessLevel.none)
</ins><span class="cx"> 
</span><span class="cx">         try:
</span><span class="cx">             returnValue({
</span></span></pre>
</div>
</div>

</body>
</html>