<!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>[13524] 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/13524">13524</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-05-21 12:57:49 -0700 (Wed, 21 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Change the resource migration tool to use WorkerService</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkbindevelop">CalendarServer/trunk/bin/develop</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolsresourcespy">CalendarServer/trunk/calendarserver/tools/resources.py</a></li>
<li><a href="#CalendarServertrunkrequirementsstabletxt">CalendarServer/trunk/requirements-stable.txt</a></li>
<li><a href="#CalendarServertrunktwistedcaldavupgradepy">CalendarServer/trunk/twistedcaldav/upgrade.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkbindevelop"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/bin/develop (13523 => 13524)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/bin/develop        2014-05-21 19:56:54 UTC (rev 13523)
+++ CalendarServer/trunk/bin/develop        2014-05-21 19:57:49 UTC (rev 13524)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx"> export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}";
</span><span class="cx"> export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:-}";
</span><span class="cx">
</span><del>-exec "\$(dirname \$0)/../${source}" "\$@";
</del><ins>+exec "\$(dirname \$0)/../${source}" --config "${wd}/conf/caldavd-dev.plist" "\$@";
</ins><span class="cx"> __END__
</span><span class="cx"> chmod +x "${target}";
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolsresourcespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/resources.py (13523 => 13524)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/resources.py        2014-05-21 19:56:54 UTC (rev 13523)
+++ CalendarServer/trunk/calendarserver/tools/resources.py        2014-05-21 19:57:49 UTC (rev 13524)
</span><span class="lines">@@ -23,32 +23,37 @@
</span><span class="cx"> ]
</span><span class="cx">
</span><span class="cx"> from getopt import getopt, GetoptError
</span><del>-from grp import getgrnam
</del><span class="cx"> import os
</span><del>-from pwd import getpwnam
</del><span class="cx"> import sys
</span><span class="cx">
</span><del>-from calendarserver.tools.util import (
- loadConfig, setupMemcached, checkDirectory
-)
-from twext.python.log import Logger, StandardIOObserver
-from twisted.internet import reactor
-from twisted.internet.defer import inlineCallbacks
-from twisted.python.util import switchUID
-from twistedcaldav.config import config, ConfigurationError
-from txdav.who.util import directoryFromConfig
</del><ins>+from calendarserver.tools.cmdline import utilityMain, WorkerService
+from twext.python.log import Logger
+from twisted.internet.defer import inlineCallbacks, returnValue
+from txdav.who.directory import CalendarDirectoryRecordMixin
+from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
+from twext.who.opendirectory import RecordType
</ins><span class="cx">
</span><del>-try:
- from twext.who.opendirectory import (
- DirectoryService as OpenDirectoryService
- )
-except ImportError:
- pass
</del><span class="cx">
</span><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="cx">
</span><ins>+class ResourceMigrationService(WorkerService):
</ins><span class="cx">
</span><ins>+ @inlineCallbacks
+ def doWork(self):
+ try:
+ from twext.who.opendirectory import (
+ DirectoryService as OpenDirectoryService
+ )
+ except ImportError:
+ returnValue(None)
+ sourceService = OpenDirectoryService()
+ sourceService.recordType = RecordType
+
+ destService = self.store.directoryService()
+ yield migrateResources(sourceService, destService)
+
+
</ins><span class="cx"> def usage():
</span><span class="cx">
</span><span class="cx"> name = os.path.basename(sys.argv[0])
</span><span class="lines">@@ -66,23 +71,12 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-def abort(msg, status=1):
- sys.stdout.write("%s\n" % (msg,))
- try:
- reactor.stop()
- except RuntimeError:
- pass
- sys.exit(status)
-
-
-
</del><span class="cx"> def main():
</span><span class="cx"> try:
</span><span class="cx"> (optargs, _ignore_args) = getopt(
</span><del>- sys.argv[1:], "hf:v", [
</del><ins>+ sys.argv[1:], "hf:", [
</ins><span class="cx"> "help",
</span><span class="cx"> "config=",
</span><del>- "verbose",
</del><span class="cx"> ],
</span><span class="cx"> )
</span><span class="cx"> except GetoptError, e:
</span><span class="lines">@@ -98,88 +92,26 @@
</span><span class="cx"> if opt in ("-h", "--help"):
</span><span class="cx"> usage()
</span><span class="cx">
</span><del>- elif opt in ("-v", "--verbose"):
- verbose = True
-
</del><span class="cx"> elif opt in ("-f", "--config"):
</span><span class="cx"> configFileName = arg
</span><span class="cx">
</span><span class="cx"> else:
</span><span class="cx"> raise NotImplementedError(opt)
</span><span class="cx">
</span><del>- #
- # Get configuration
- #
- try:
- loadConfig(configFileName)
</del><ins>+ utilityMain(configFileName, ResourceMigrationService, verbose=verbose)
</ins><span class="cx">
</span><del>- # Do this first, because modifying the config object will cause
- # some logging activity at whatever log level the plist says
- log.publisher.levels.clearLogLevels()
</del><span class="cx">
</span><del>- config.DefaultLogLevel = "info" if verbose else "error"
</del><ins>+class DirectoryRecord(BaseDirectoryRecord, CalendarDirectoryRecordMixin):
+ pass
</ins><span class="cx">
</span><del>- #
- # Send logging output to stdout
- #
- observer = StandardIOObserver()
- observer.start()
</del><span class="cx">
</span><del>- # Create the DataRoot directory before shedding privileges
- if config.DataRoot.startswith(config.ServerRoot + os.sep):
- checkDirectory(
- config.DataRoot,
- "Data root",
- access=os.W_OK,
- create=(0750, config.UserName, config.GroupName),
- )
-
- # Shed privileges
- if config.UserName and config.GroupName and os.getuid() == 0:
- uid = getpwnam(config.UserName).pw_uid
- gid = getgrnam(config.GroupName).gr_gid
- switchUID(uid, uid, gid)
-
- os.umask(config.umask)
-
- # Configure memcached client settings prior to setting up resource
- # hierarchy
- setupMemcached(config)
-
- config.directory = directoryFromConfig(config)
-
- except ConfigurationError, e:
- abort(e)
-
- sourceService = OpenDirectoryService()
- destService = config.directory
-
- #
- # Start the reactor
- #
- reactor.callLater(
- 0, migrate, sourceService, destService, verbose=verbose
- )
- reactor.run()
-
-
-
</del><span class="cx"> @inlineCallbacks
</span><del>-def migrate(sourceService, destService, verbose=False):
</del><ins>+def migrateResources(sourceService, destService, verbose=False):
</ins><span class="cx"> """
</span><del>- Simply a wrapper around migrateResources in order to stop the reactor
</del><ins>+ Fetch all the locations and resources from sourceService that are not
+ already in destService and copy them into destService.
</ins><span class="cx"> """
</span><span class="cx">
</span><del>- try:
- yield migrateResources(sourceService, destService, verbose=verbose)
- finally:
- reactor.stop()
-
-
-
-@inlineCallbacks
-def migrateResources(sourceService, destService, verbose=False):
-
</del><span class="cx"> destRecords = []
</span><span class="cx">
</span><span class="cx"> for recordType in (
</span><span class="lines">@@ -192,13 +124,24 @@
</span><span class="cx"> if destRecord is None:
</span><span class="cx"> if verbose:
</span><span class="cx"> print(
</span><del>- "Migrating {name} {recordType} {uid}".format(
- name=sourceRecord.displayName,
</del><ins>+ "Migrating {recordType} {uid}".format(
</ins><span class="cx"> recordType=recordType.name,
</span><span class="cx"> uid=sourceRecord.uid
</span><span class="cx"> )
</span><span class="cx"> )
</span><del>- destRecord = type(sourceRecord)(destService, sourceRecord.fields.copy())
</del><ins>+ fields = sourceRecord.fields.copy()
+ fields[destService.fieldName.recordType] = destService.recordType.lookupByName(recordType.name)
+
+ # Only interested in these fields:
+ fn = destService.fieldName
+ interestingFields = [
+ fn.recordType, fn.shortNames, fn.uid, fn.fullNames, fn.guid
+ ]
+ for key in fields.keys():
+ if key not in interestingFields:
+ del fields[key]
+
+ destRecord = DirectoryRecord(destService, fields)
</ins><span class="cx"> destRecords.append(destRecord)
</span><span class="cx">
</span><span class="cx"> if destRecords:
</span></span></pre></div>
<a id="CalendarServertrunkrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-stable.txt (13523 => 13524)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/requirements-stable.txt        2014-05-21 19:56:54 UTC (rev 13523)
+++ CalendarServer/trunk/requirements-stable.txt        2014-05-21 19:57:49 UTC (rev 13524)
</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@13520#egg=twextpy
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13523#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@13420#egg=pycalendar
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavupgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/upgrade.py (13523 => 13524)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/upgrade.py        2014-05-21 19:56:54 UTC (rev 13523)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py        2014-05-21 19:57:49 UTC (rev 13524)
</span><span class="lines">@@ -61,7 +61,6 @@
</span><span class="cx"> from txdav.who.idirectory import RecordType as CalRecordType
</span><span class="cx"> from txdav.who.delegates import addDelegate
</span><span class="cx"> from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
</span><del>-from calendarserver.tools.resources import migrateResources
</del><span class="cx">
</span><span class="cx">
</span><span class="cx"> deadPropertyXattrPrefix = namedAny(
</span><span class="lines">@@ -863,6 +862,7 @@
</span><span class="cx"> from twext.who.opendirectory import (
</span><span class="cx"> DirectoryService as OpenDirectoryService
</span><span class="cx"> )
</span><ins>+ from calendarserver.tools.resources import migrateResources
</ins><span class="cx"> return migrateResources(OpenDirectoryService(), directory)
</span><span class="cx">
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>