[CalendarServer-changes] [13524] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed May 21 12:57:49 PDT 2014
Revision: 13524
http://trac.calendarserver.org//changeset/13524
Author: sagen at apple.com
Date: 2014-05-21 12:57:49 -0700 (Wed, 21 May 2014)
Log Message:
-----------
Change the resource migration tool to use WorkerService
Modified Paths:
--------------
CalendarServer/trunk/bin/develop
CalendarServer/trunk/calendarserver/tools/resources.py
CalendarServer/trunk/requirements-stable.txt
CalendarServer/trunk/twistedcaldav/upgrade.py
Modified: CalendarServer/trunk/bin/develop
===================================================================
--- 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)
@@ -46,7 +46,7 @@
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}";
export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:-}";
-exec "\$(dirname \$0)/../${source}" "\$@";
+exec "\$(dirname \$0)/../${source}" --config "${wd}/conf/caldavd-dev.plist" "\$@";
__END__
chmod +x "${target}";
Modified: CalendarServer/trunk/calendarserver/tools/resources.py
===================================================================
--- 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)
@@ -23,32 +23,37 @@
]
from getopt import getopt, GetoptError
-from grp import getgrnam
import os
-from pwd import getpwnam
import sys
-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
+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
-try:
- from twext.who.opendirectory import (
- DirectoryService as OpenDirectoryService
- )
-except ImportError:
- pass
log = Logger()
+class ResourceMigrationService(WorkerService):
+ @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)
+
+
def usage():
name = os.path.basename(sys.argv[0])
@@ -66,23 +71,12 @@
-def abort(msg, status=1):
- sys.stdout.write("%s\n" % (msg,))
- try:
- reactor.stop()
- except RuntimeError:
- pass
- sys.exit(status)
-
-
-
def main():
try:
(optargs, _ignore_args) = getopt(
- sys.argv[1:], "hf:v", [
+ sys.argv[1:], "hf:", [
"help",
"config=",
- "verbose",
],
)
except GetoptError, e:
@@ -98,88 +92,26 @@
if opt in ("-h", "--help"):
usage()
- elif opt in ("-v", "--verbose"):
- verbose = True
-
elif opt in ("-f", "--config"):
configFileName = arg
else:
raise NotImplementedError(opt)
- #
- # Get configuration
- #
- try:
- loadConfig(configFileName)
+ utilityMain(configFileName, ResourceMigrationService, verbose=verbose)
- # Do this first, because modifying the config object will cause
- # some logging activity at whatever log level the plist says
- log.publisher.levels.clearLogLevels()
- config.DefaultLogLevel = "info" if verbose else "error"
+class DirectoryRecord(BaseDirectoryRecord, CalendarDirectoryRecordMixin):
+ pass
- #
- # Send logging output to stdout
- #
- observer = StandardIOObserver()
- observer.start()
- # 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()
-
-
-
@inlineCallbacks
-def migrate(sourceService, destService, verbose=False):
+def migrateResources(sourceService, destService, verbose=False):
"""
- Simply a wrapper around migrateResources in order to stop the reactor
+ Fetch all the locations and resources from sourceService that are not
+ already in destService and copy them into destService.
"""
- try:
- yield migrateResources(sourceService, destService, verbose=verbose)
- finally:
- reactor.stop()
-
-
-
- at inlineCallbacks
-def migrateResources(sourceService, destService, verbose=False):
-
destRecords = []
for recordType in (
@@ -192,13 +124,24 @@
if destRecord is None:
if verbose:
print(
- "Migrating {name} {recordType} {uid}".format(
- name=sourceRecord.displayName,
+ "Migrating {recordType} {uid}".format(
recordType=recordType.name,
uid=sourceRecord.uid
)
)
- destRecord = type(sourceRecord)(destService, sourceRecord.fields.copy())
+ 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)
destRecords.append(destRecord)
if destRecords:
Modified: CalendarServer/trunk/requirements-stable.txt
===================================================================
--- 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)
@@ -5,7 +5,7 @@
# For CalendarServer development, don't try to get these projects from PyPI; use svn.
-e .
--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13520#egg=twextpy
+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13523#egg=twextpy
-e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
-e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13420#egg=pycalendar
Modified: CalendarServer/trunk/twistedcaldav/upgrade.py
===================================================================
--- 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)
@@ -61,7 +61,6 @@
from txdav.who.idirectory import RecordType as CalRecordType
from txdav.who.delegates import addDelegate
from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
-from calendarserver.tools.resources import migrateResources
deadPropertyXattrPrefix = namedAny(
@@ -863,6 +862,7 @@
from twext.who.opendirectory import (
DirectoryService as OpenDirectoryService
)
+ from calendarserver.tools.resources import migrateResources
return migrateResources(OpenDirectoryService(), directory)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140521/355ba059/attachment.html>
More information about the calendarserver-changes
mailing list