<!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>[12787] CalendarServer/trunk/calendarserver</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/12787">12787</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-03-03 15:47:56 -0800 (Mon, 03 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>lint
stop using % formatting</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertapcaldavpy">CalendarServer/trunk/calendarserver/tap/caldav.py</a></li>
<li><a href="#CalendarServertrunkcalendarserverwebadminworkpy">CalendarServer/trunk/calendarserver/webadmin/work.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertapcaldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/caldav.py (12786 => 12787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/caldav.py        2014-03-03 22:49:22 UTC (rev 12786)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py        2014-03-03 23:47:56 UTC (rev 12787)
</span><span class="lines">@@ -40,7 +40,9 @@
</span><span class="cx"> from twisted.application.internet import TCPServer, UNIXServer
</span><span class="cx"> from twisted.application.service import MultiService, IServiceMaker
</span><span class="cx"> from twisted.application.service import Service
</span><del>-from twisted.internet.defer import gatherResults, Deferred, inlineCallbacks, succeed
</del><ins>+from twisted.internet.defer import (
+ gatherResults, Deferred, inlineCallbacks, succeed
+)
</ins><span class="cx"> from twisted.internet.endpoints import UNIXClientEndpoint, TCP4ClientEndpoint
</span><span class="cx"> from twisted.internet.process import ProcessExitedAlready
</span><span class="cx"> from twisted.internet.protocol import ProcessProtocol
</span><span class="lines">@@ -58,13 +60,16 @@
</span><span class="cx"> from twext.enterprise.jobqueue import NonPerformingQueuer
</span><span class="cx"> from twext.enterprise.jobqueue import PeerConnectionPool
</span><span class="cx"> from twext.enterprise.jobqueue import WorkerFactory as QueueWorkerFactory
</span><del>-from twext.internet.fswatch import DirectoryChangeListener, IDirectoryChangeListenee
</del><ins>+from twext.internet.fswatch import (
+ DirectoryChangeListener, IDirectoryChangeListenee
+)
</ins><span class="cx"> from twext.internet.ssl import ChainingOpenSSLContextFactory
</span><span class="cx"> from twext.internet.tcp import MaxAcceptTCPServer, MaxAcceptSSLServer
</span><span class="cx"> from twext.python.filepath import CachingFilePath
</span><span class="cx"> from twext.python.log import Logger, LogLevel, replaceTwistedLoggers
</span><del>-from txweb2.channel.http import LimitingHTTPFactory, SSLRedirectRequest, \
- HTTPChannel
</del><ins>+from txweb2.channel.http import (
+ LimitingHTTPFactory, SSLRedirectRequest, HTTPChannel
+)
</ins><span class="cx"> from txweb2.metafd import ConnectionLimiter, ReportingHTTPService
</span><span class="cx"> from txweb2.server import Site
</span><span class="cx">
</span><span class="lines">@@ -74,9 +79,13 @@
</span><span class="cx"> from txdav.common.datastore.upgrade.sql.upgrade import (
</span><span class="cx"> UpgradeDatabaseCalendarDataStep, UpgradeDatabaseOtherStep,
</span><span class="cx"> UpgradeDatabaseSchemaStep, UpgradeDatabaseAddressBookDataStep,
</span><del>- UpgradeAcquireLockStep, UpgradeReleaseLockStep, UpgradeDatabaseNotificationDataStep)
</del><ins>+ UpgradeAcquireLockStep, UpgradeReleaseLockStep,
+ UpgradeDatabaseNotificationDataStep
+)
</ins><span class="cx"> from txdav.common.datastore.work.inbox_cleanup import scheduleFirstInboxCleanup
</span><del>-from txdav.common.datastore.work.revision_cleanup import scheduleFirstFindMinRevision
</del><ins>+from txdav.common.datastore.work.revision_cleanup import (
+ scheduleFirstFindMinRevision
+)
</ins><span class="cx"> from txdav.dps.server import DirectoryProxyServiceMaker
</span><span class="cx"> from txdav.dps.client import DirectoryService as DirectoryProxyClientService
</span><span class="cx"> from txdav.who.groups import GroupCacher as NewGroupCacher
</span><span class="lines">@@ -104,14 +113,13 @@
</span><span class="cx"> from calendarserver.push.amppush import AMPPushMaster, AMPPushForwarder
</span><span class="cx"> from calendarserver.push.applepush import ApplePushNotifierService
</span><span class="cx"> from calendarserver.push.notifier import PushDistributor
</span><del>-from calendarserver.tap.util import ConnectionDispenser
-from calendarserver.tap.util import Stepper
-from calendarserver.tap.util import checkDirectories
-from calendarserver.tap.util import getRootResource
-from calendarserver.tap.util import oracleConnectorFromConfig
-from calendarserver.tap.util import pgConnectorFromConfig
-from calendarserver.tap.util import pgServiceFromConfig, getDBPool, MemoryLimitService
-from calendarserver.tap.util import storeFromConfig
</del><ins>+from calendarserver.tap.util import (
+ ConnectionDispenser, Stepper,
+ checkDirectories, getRootResource,
+ oracleConnectorFromConfig, pgConnectorFromConfig,
+ pgServiceFromConfig, getDBPool, MemoryLimitService,
+ storeFromConfig
+)
</ins><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> from calendarserver.version import version
</span><span class="lines">@@ -121,10 +129,10 @@
</span><span class="cx"> sys.path.insert(
</span><span class="cx"> 0, getModule(__name__).pathEntry.filePath.child("support").path)
</span><span class="cx"> from version import version as getVersion
</span><del>- version = "%s (%s*)" % getVersion()
</del><ins>+ version = "{} ({}*)".format(getVersion())
</ins><span class="cx">
</span><span class="cx"> from txweb2.server import VERSION as TWISTED_VERSION
</span><del>-TWISTED_VERSION = "CalendarServer/%s %s" % (
</del><ins>+TWISTED_VERSION = "CalendarServer/{} {}".format(
</ins><span class="cx"> version.replace(" ", ""), TWISTED_VERSION,
</span><span class="cx"> )
</span><span class="cx">
</span><span class="lines">@@ -212,7 +220,7 @@
</span><span class="cx">
</span><span class="cx"> def connectionMade(self):
</span><span class="cx"> stats = self.factory.logger.observer.getStats()
</span><del>- self.transport.write("%s\r\n" % (stats,))
</del><ins>+ self.transport.write("{}\r\n".format(stats))
</ins><span class="cx"> self.transport.loseConnection()
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -234,10 +242,13 @@
</span><span class="cx"> """
</span><span class="cx"> @param logEnabled: Whether to write to a log file
</span><span class="cx"> @type logEnabled: C{boolean}
</span><ins>+
</ins><span class="cx"> @param logPath: the full path to the log file
</span><span class="cx"> @type logPath: C{str}
</span><ins>+
</ins><span class="cx"> @param logRotateLength: rotate when files exceed this many bytes
</span><span class="cx"> @type logRotateLength: C{int}
</span><ins>+
</ins><span class="cx"> @param logMaxFiles: keep at most this many files
</span><span class="cx"> @type logMaxFiles: C{int}
</span><span class="cx"> """
</span><span class="lines">@@ -273,10 +284,12 @@
</span><span class="cx"> connectionServiceName = "ConnectionService"
</span><span class="cx">
</span><span class="cx"> def __init__(self, logObserver):
</span><del>- self.logObserver = logObserver # accesslog observer
- ErrorLoggingMultiService.__init__(self, config.ErrorLogEnabled,
</del><ins>+ self.logObserver = logObserver # accesslog observer
+ ErrorLoggingMultiService.__init__(
+ self, config.ErrorLogEnabled,
</ins><span class="cx"> config.ErrorLogFile, config.ErrorLogRotateMB * 1024 * 1024,
</span><del>- config.ErrorLogMaxRotatedFiles)
</del><ins>+ config.ErrorLogMaxRotatedFiles
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def privilegedStartService(self):
</span><span class="lines">@@ -288,7 +301,9 @@
</span><span class="cx"> def stopService(self):
</span><span class="cx"> """
</span><span class="cx"> Wait for outstanding requests to finish
</span><del>- @return: a Deferred which fires when all outstanding requests are complete
</del><ins>+
+ @return: a Deferred which fires when all outstanding requests are
+ complete
</ins><span class="cx"> """
</span><span class="cx"> connectionService = self.getServiceNamed(self.connectionServiceName)
</span><span class="cx"> # Note: removeService() also calls stopService()
</span><span class="lines">@@ -306,7 +321,7 @@
</span><span class="cx"> "config", "f", DEFAULT_CONFIG_FILE, "Path to configuration file."
</span><span class="cx"> ]]
</span><span class="cx">
</span><del>- zsh_actions = {"config" : "_files -g '*.plist'"}
</del><ins>+ zsh_actions = {"config": "_files -g '*.plist'"}
</ins><span class="cx">
</span><span class="cx"> def __init__(self, *args, **kwargs):
</span><span class="cx"> super(CalDAVOptions, self).__init__(*args, **kwargs)
</span><span class="lines">@@ -382,7 +397,7 @@
</span><span class="cx"> self.overrides
</span><span class="cx"> )
</span><span class="cx"> else:
</span><del>- self.opt_option("%s=True" % (option,))
</del><ins>+ self.opt_option("{}=True".format(option))
</ins><span class="cx">
</span><span class="cx"> opt_o = opt_option
</span><span class="cx">
</span><span class="lines">@@ -392,25 +407,27 @@
</span><span class="cx"> self.loadConfiguration()
</span><span class="cx"> self.checkConfiguration()
</span><span class="cx"> except ConfigurationError, e:
</span><del>- print("Invalid configuration: %s" % (e,))
</del><ins>+ print("Invalid configuration:", e)
</ins><span class="cx"> sys.exit(1)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def loadConfiguration(self):
</span><span class="cx"> if not os.path.exists(self["config"]):
</span><del>- raise ConfigurationError("Config file %s not found. Exiting."
- % (self["config"],))
</del><ins>+ raise ConfigurationError(
+ "Config file {} not found. Exiting."
+ .format(self["config"])
+ )
</ins><span class="cx">
</span><del>- print("Reading configuration from file: %s" % (self["config"],))
</del><ins>+ print("Reading configuration from file:", self["config"])
</ins><span class="cx">
</span><span class="cx"> config.load(self["config"])
</span><span class="cx">
</span><span class="cx"> for path in config.getProvider().importedFiles:
</span><del>- print("Imported configuration from file: '%s'" % (path,))
</del><ins>+ print("Imported configuration from file:", path)
</ins><span class="cx"> for path in config.getProvider().includedFiles:
</span><del>- print("Adding configuration from file: '%s'" % (path,))
</del><ins>+ print("Adding configuration from file:", path)
</ins><span class="cx"> for path in config.getProvider().missingFiles:
</span><del>- print("Missing configuration file: '%s'" % (path,))
</del><ins>+ print("Missing configuration file:", path)
</ins><span class="cx">
</span><span class="cx"> config.updateDefaults(self.overrides)
</span><span class="cx">
</span><span class="lines">@@ -425,7 +442,9 @@
</span><span class="cx"> # for a running server (but is fine for command-line utilities)
</span><span class="cx"> if config.ProcessType not in ["Agent", "Utility"]:
</span><span class="cx"> if not config.EnableCalDAV and not config.EnableCardDAV:
</span><del>- print("Neither EnableCalDAV nor EnableCardDAV are set to True.")
</del><ins>+ print(
+ "Neither EnableCalDAV nor EnableCardDAV are set to True."
+ )
</ins><span class="cx"> sys.exit(1)
</span><span class="cx">
</span><span class="cx"> uid, gid = None, None
</span><span class="lines">@@ -436,8 +455,10 @@
</span><span class="cx"> def gottaBeRoot():
</span><span class="cx"> if os.getuid() != 0:
</span><span class="cx"> username = getpwuid(os.getuid()).pw_name
</span><del>- raise UsageError("Only root can drop privileges. You are: %r"
- % (username,))
</del><ins>+ raise UsageError(
+ "Only root can drop privileges. You are: {}"
+ .format(username)
+ )
</ins><span class="cx">
</span><span class="cx"> if uid and uid != os.getuid():
</span><span class="cx"> gottaBeRoot()
</span><span class="lines">@@ -459,9 +480,11 @@
</span><span class="cx"> # Check current umask and warn if changed
</span><span class="cx"> oldmask = os.umask(config.umask)
</span><span class="cx"> if oldmask != config.umask:
</span><del>- self.log.info("WARNING: changing umask from: 0%03o to 0%03o"
- % (oldmask, config.umask))
- self.parent['umask'] = config.umask
</del><ins>+ self.log.info(
+ "WARNING: changing umask from: 0{old!03o} to 0{new!03o}",
+ old=oldmask, new=config.umask
+ )
+ self.parent["umask"] = config.umask
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -497,8 +520,10 @@
</span><span class="cx"> - regular slave processes (CalDAV workers)
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def __init__(self, maker, monitor, dispenser, dispatcher, configPath,
- inheritFDs=None, inheritSSLFDs=None):
</del><ins>+ def __init__(
+ self, maker, monitor, dispenser, dispatcher, configPath,
+ inheritFDs=None, inheritSSLFDs=None
+ ):
</ins><span class="cx"> self.maker = maker
</span><span class="cx"> self.monitor = monitor
</span><span class="cx"> self.dispenser = dispenser
</span><span class="lines">@@ -524,8 +549,8 @@
</span><span class="cx"> self.monitor.addProcessObject(process, PARENT_ENVIRONMENT)
</span><span class="cx">
</span><span class="cx"> if (
</span><del>- config.DirectoryProxy.Enabled and
- config.DirectoryProxy.SocketPath != ""
</del><ins>+ config.DirectoryProxy.Enabled and
+ config.DirectoryProxy.SocketPath != ""
</ins><span class="cx"> ):
</span><span class="cx"> log.info("Adding directory proxy service")
</span><span class="cx">
</span><span class="lines">@@ -538,12 +563,13 @@
</span><span class="cx"> if config.GroupName:
</span><span class="cx"> dpsArgv.extend(("-g", config.GroupName))
</span><span class="cx"> dpsArgv.extend((
</span><del>- "--reactor=%s" % (config.Twisted.reactor,),
</del><ins>+ "--reactor={}".format(config.Twisted.reactor),
</ins><span class="cx"> "-n", "caldav_directoryproxy",
</span><span class="cx"> "-f", self.configPath,
</span><span class="cx"> ))
</span><del>- self.monitor.addProcess("directoryproxy", dpsArgv,
- env=PARENT_ENVIRONMENT)
</del><ins>+ self.monitor.addProcess(
+ "directoryproxy", dpsArgv, env=PARENT_ENVIRONMENT
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -573,11 +599,23 @@
</span><span class="cx"> # ultimatelyPerform( ) handles groups correctly. Once that is fixed
</span><span class="cx"> # these can be set to zero seconds in the future.
</span><span class="cx"> if self.doImip:
</span><del>- yield scheduleNextMailPoll(self.store, int(config.LogID) if config.LogID else 5)
</del><ins>+ yield scheduleNextMailPoll(
+ self.store,
+ int(config.LogID) if config.LogID else 5
+ )
</ins><span class="cx"> if self.doGroupCaching:
</span><del>- yield scheduleNextGroupCachingUpdate(self.store, int(config.LogID) if config.LogID else 5)
- yield scheduleFirstFindMinRevision(self.store, int(config.LogID) if config.LogID else 5)
- yield scheduleFirstInboxCleanup(self.store, int(config.LogID) if config.LogID else 5)
</del><ins>+ yield scheduleNextGroupCachingUpdate(
+ self.store,
+ int(config.LogID) if config.LogID else 5
+ )
+ yield scheduleFirstFindMinRevision(
+ self.store,
+ int(config.LogID) if config.LogID else 5
+ )
+ yield scheduleFirstInboxCleanup(
+ self.store,
+ int(config.LogID) if config.LogID else 5
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -607,12 +645,14 @@
</span><span class="cx"> """
</span><span class="cx"> self.log.warn("SIGHUP received - restarting")
</span><span class="cx"> try:
</span><del>- self.log.info("Removing pidfile: %s" % (self.pidfilePath,))
</del><ins>+ self.log.info("Removing pidfile: {log_source.pidfilePath}")
</ins><span class="cx"> os.remove(self.pidfilePath)
</span><span class="cx"> except OSError:
</span><span class="cx"> pass
</span><del>- self.reactor.addSystemEventTrigger("after", "shutdown", os.execv,
- sys.executable, [sys.executable] + sys.argv)
</del><ins>+ self.reactor.addSystemEventTrigger(
+ "after", "shutdown", os.execv,
+ sys.executable, [sys.executable] + sys.argv
+ )
</ins><span class="cx"> self.reactor.stop()
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -644,8 +684,10 @@
</span><span class="cx"> aren't allowed to upgrade the database).
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def __init__(self, serviceCreator, connectionPool, store, logObserver,
- storageService, reactor=None):
</del><ins>+ def __init__(
+ self, serviceCreator, connectionPool, store, logObserver,
+ storageService, reactor=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> @param serviceCreator: callable which will be passed the connection
</span><span class="cx"> pool, store, and log observer, and should return a Service
</span><span class="lines">@@ -672,8 +714,10 @@
</span><span class="cx"> The final "step"; if we get here we know our store is ready, so
</span><span class="cx"> we create the main service and pass in the store.
</span><span class="cx"> """
</span><del>- service = self.serviceCreator(self.connectionPool, self.store,
- self.logObserver, self.storageService)
</del><ins>+ service = self.serviceCreator(
+ self.connectionPool, self.store,
+ self.logObserver, self.storageService
+ )
</ins><span class="cx"> if self.parent is not None:
</span><span class="cx"> self.reactor.callLater(0, service.setServiceParent, self.parent)
</span><span class="cx"> return succeed(None)
</span><span class="lines">@@ -685,10 +729,14 @@
</span><span class="cx"> so we create the main service and pass in a None for the store.
</span><span class="cx"> """
</span><span class="cx"> try:
</span><del>- service = self.serviceCreator(self.connectionPool, None,
- self.logObserver, self.storageService)
</del><ins>+ service = self.serviceCreator(
+ self.connectionPool, None,
+ self.logObserver, self.storageService
+ )
</ins><span class="cx"> if self.parent is not None:
</span><del>- self.reactor.callLater(0, service.setServiceParent, self.parent)
</del><ins>+ self.reactor.callLater(
+ 0, service.setServiceParent, self.parent
+ )
</ins><span class="cx"> except StoreNotAvailable:
</span><span class="cx"> self.reactor.stop()
</span><span class="cx">
</span><span class="lines">@@ -780,29 +828,43 @@
</span><span class="cx"> """
</span><span class="cx"> replaceTwistedLoggers()
</span><span class="cx">
</span><del>- self.log.info("%s %s starting %s process..." % (self.description, version, config.ProcessType))
</del><ins>+ self.log.info(
+ "{log_source.description} {version} starting "
+ "{config.ProcessType} process...",
+ version=version, config=config
+ )
</ins><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> from setproctitle import setproctitle
</span><ins>+
</ins><span class="cx"> except ImportError:
</span><span class="cx"> pass
</span><ins>+
</ins><span class="cx"> else:
</span><span class="cx"> execName = os.path.basename(sys.argv[0])
</span><ins>+
</ins><span class="cx"> if config.LogID:
</span><del>- logID = " #%s" % (config.LogID,)
</del><ins>+ logID = " #{}".format(config.LogID)
</ins><span class="cx"> else:
</span><span class="cx"> logID = ""
</span><ins>+
</ins><span class="cx"> if config.ProcessType is not "Utility":
</span><span class="cx"> execName = ""
</span><del>- setproctitle("CalendarServer %s [%s%s] %s" % (version, config.ProcessType, logID, execName))
</del><span class="cx">
</span><del>- serviceMethod = getattr(self, "makeService_%s" % (config.ProcessType,), None)
</del><ins>+ setproctitle(
+ "CalendarServer {} [{}{}] {}"
+ .format(version, config.ProcessType, logID, execName)
+ )
</ins><span class="cx">
</span><ins>+ serviceMethod = getattr(
+ self, "makeService_{}".format(config.ProcessType), None
+ )
+
</ins><span class="cx"> if not serviceMethod:
</span><span class="cx"> raise UsageError(
</span><del>- "Unknown server type %s. "
</del><ins>+ "Unknown server type {}. "
</ins><span class="cx"> "Please choose: Slave, Single or Combined"
</span><del>- % (config.ProcessType,)
</del><ins>+ .format(config.ProcessType)
</ins><span class="cx"> )
</span><span class="cx"> else:
</span><span class="cx"> #
</span><span class="lines">@@ -820,7 +882,7 @@
</span><span class="cx"> try:
</span><span class="cx"> service = serviceMethod(options)
</span><span class="cx"> except ConfigurationError, e:
</span><del>- sys.stderr.write("Configuration error: %s\n" % (e,))
</del><ins>+ sys.stderr.write("Configuration error: {}\n".format(e))
</ins><span class="cx"> sys.exit(1)
</span><span class="cx">
</span><span class="cx"> #
</span><span class="lines">@@ -836,7 +898,9 @@
</span><span class="cx"> if frame is None:
</span><span class="cx"> return "Unknown"
</span><span class="cx"> else:
</span><del>- return "%s: %s" % (frame.f_code.co_name, frame.f_lineno)
</del><ins>+ return "{frame.f_code.co_name}: {frame.f_lineno}".format(
+ frame=frame
+ )
</ins><span class="cx">
</span><span class="cx"> return service
</span><span class="cx">
</span><span class="lines">@@ -867,34 +931,46 @@
</span><span class="cx"> logObserver = AMPCommonAccessLoggingObserver()
</span><span class="cx"> result = self.requestProcessingService(options, store, logObserver)
</span><span class="cx"> directory = store.directoryService()
</span><ins>+
</ins><span class="cx"> if pool is not None:
</span><span class="cx"> pool.setServiceParent(result)
</span><span class="cx">
</span><span class="cx"> if config.ControlSocket:
</span><span class="cx"> id = config.ControlSocket
</span><del>- self.log.info("Control via AF_UNIX: %s" % (id,))
</del><ins>+ self.log.info("Control via AF_UNIX: {id}", id=id)
</ins><span class="cx"> endpointFactory = lambda reactor: UNIXClientEndpoint(
</span><del>- reactor, id)
</del><ins>+ reactor, id
+ )
</ins><span class="cx"> else:
</span><span class="cx"> id = int(config.ControlPort)
</span><del>- self.log.info("Control via AF_INET: %d" % (id,))
</del><ins>+ self.log.info("Control via AF_INET: {id}", id=id)
</ins><span class="cx"> endpointFactory = lambda reactor: TCP4ClientEndpoint(
</span><del>- reactor, "127.0.0.1", id)
</del><ins>+ reactor, "127.0.0.1", id
+ )
</ins><span class="cx"> controlSocketClient = ControlSocket()
</span><ins>+
</ins><span class="cx"> class LogClient(AMP):
</span><span class="cx"> def startReceivingBoxes(self, sender):
</span><span class="cx"> super(LogClient, self).startReceivingBoxes(sender)
</span><span class="cx"> logObserver.addClient(self)
</span><ins>+
</ins><span class="cx"> f = Factory()
</span><span class="cx"> f.protocol = LogClient
</span><ins>+
</ins><span class="cx"> controlSocketClient.addFactory(_LOG_ROUTE, f)
</span><ins>+
</ins><span class="cx"> from txdav.common.datastore.sql import CommonDataStore as SQLStore
</span><ins>+
</ins><span class="cx"> if isinstance(store, SQLStore):
</span><span class="cx"> def queueMasterAvailable(connectionFromMaster):
</span><del>- store.queuer = store.queuer.transferProposalCallbacks(connectionFromMaster)
- queueFactory = QueueWorkerFactory(store.newTransaction,
- queueMasterAvailable)
</del><ins>+ store.queuer = store.queuer.transferProposalCallbacks(
+ connectionFromMaster
+ )
+ queueFactory = QueueWorkerFactory(
+ store.newTransaction, queueMasterAvailable
+ )
</ins><span class="cx"> controlSocketClient.addFactory(_QUEUE_ROUTE, queueFactory)
</span><ins>+
</ins><span class="cx"> controlClient = ControlSocketConnectingService(
</span><span class="cx"> endpointFactory, controlSocketClient
</span><span class="cx"> )
</span><span class="lines">@@ -917,8 +993,9 @@
</span><span class="cx">
</span><span class="cx"> # Optionally set up mail retrieval
</span><span class="cx"> if config.Scheduling.iMIP.Enabled:
</span><del>- mailRetriever = MailRetriever(store, directory,
- config.Scheduling.iMIP.Receiving)
</del><ins>+ mailRetriever = MailRetriever(
+ store, directory, config.Scheduling.iMIP.Receiving
+ )
</ins><span class="cx"> mailRetriever.setServiceParent(result)
</span><span class="cx"> else:
</span><span class="cx"> mailRetriever = None
</span><span class="lines">@@ -932,8 +1009,8 @@
</span><span class="cx"> config.GroupCaching.ExpireSeconds,
</span><span class="cx"> config.GroupCaching.LockSeconds,
</span><span class="cx"> namespace=config.GroupCaching.MemcachedPool,
</span><del>- useExternalProxies=config.GroupCaching.UseExternalProxies
- )
</del><ins>+ useExternalProxies=config.GroupCaching.UseExternalProxies,
+ )
</ins><span class="cx"> else:
</span><span class="cx"> groupCacher = None
</span><span class="cx">
</span><span class="lines">@@ -948,24 +1025,32 @@
</span><span class="cx"> # Optionally enable Manhole access
</span><span class="cx"> if config.Manhole.Enabled:
</span><span class="cx"> try:
</span><del>- from twisted.conch.manhole_tap import makeService as manholeMakeService
- portString = "tcp:%d:interface=127.0.0.1" % (config.Manhole.StartingPortNumber + int(config.LogID) + 1,)
</del><ins>+ from twisted.conch.manhole_tap import (
+ makeService as manholeMakeService
+ )
+ portString = "tcp:{:d}:interface=127.0.0.1".format(
+ config.Manhole.StartingPortNumber + int(config.LogID) + 1
+ )
</ins><span class="cx"> manholeService = manholeMakeService({
</span><del>- "sshPort" : None,
- "telnetPort" : portString,
- "namespace" : {
- "config" : config,
- "service" : result,
- "store" : store,
- "directory" : directory,
- },
- "passwd" : config.Manhole.PasswordFilePath,
</del><ins>+ "sshPort": None,
+ "telnetPort": portString,
+ "namespace": {
+ "config": config,
+ "service": result,
+ "store": store,
+ "directory": directory,
+ },
+ "passwd": config.Manhole.PasswordFilePath,
</ins><span class="cx"> })
</span><span class="cx"> manholeService.setServiceParent(result)
</span><span class="cx"> # Using print(because logging isn't ready at this point)
</span><del>- print("Manhole access enabled: %s" % (portString,))
</del><ins>+ print("Manhole access enabled:", portString)
+
</ins><span class="cx"> except ImportError:
</span><del>- print("Manhole access could not enabled because manhole_tap could not be imported")
</del><ins>+ print(
+ "Manhole access could not enabled because "
+ "manhole_tap could not be imported"
+ )
</ins><span class="cx">
</span><span class="cx"> return result
</span><span class="cx">
</span><span class="lines">@@ -994,7 +1079,9 @@
</span><span class="cx"> #
</span><span class="cx"> self.log.info("Setting up service")
</span><span class="cx">
</span><del>- self.log.info("Configuring access log observer: %s" % (logObserver,))
</del><ins>+ self.log.info(
+ "Configuring access log observer: {observer}", observer=logObserver
+ )
</ins><span class="cx"> service = CalDAVService(logObserver)
</span><span class="cx">
</span><span class="cx"> rootResource = getRootResource(config, store, additional)
</span><span class="lines">@@ -1011,7 +1098,10 @@
</span><span class="cx"> requestFactory = underlyingSite
</span><span class="cx">
</span><span class="cx"> if config.EnableSSL and config.RedirectHTTPToHTTPS:
</span><del>- self.log.info("Redirecting to HTTPS port %s" % (config.SSLPort,))
</del><ins>+ self.log.info(
+ "Redirecting to HTTPS port {port}", port=config.SSLPort
+ )
+
</ins><span class="cx"> def requestFactory(*args, **kw):
</span><span class="cx"> return SSLRedirectRequest(site=underlyingSite, *args, **kw)
</span><span class="cx">
</span><span class="lines">@@ -1026,15 +1116,21 @@
</span><span class="cx"> # if enabled.
</span><span class="cx"> if config.StrictTransportSecuritySeconds:
</span><span class="cx"> previousRequestFactory = requestFactory
</span><ins>+
</ins><span class="cx"> def requestFactory(*args, **kw):
</span><span class="cx"> request = previousRequestFactory(*args, **kw)
</span><ins>+
</ins><span class="cx"> def responseFilter(ignored, response):
</span><span class="cx"> ignored, secure = request.chanRequest.getHostInfo()
</span><span class="cx"> if secure:
</span><del>- response.headers.addRawHeader("Strict-Transport-Security",
- "max-age={max_age:d}"
- .format(max_age=config.StrictTransportSecuritySeconds))
</del><ins>+ response.headers.addRawHeader(
+ "Strict-Transport-Security",
+ "max-age={max_age:d}".format(
+ max_age=config.StrictTransportSecuritySeconds
+ )
+ )
</ins><span class="cx"> return response
</span><ins>+
</ins><span class="cx"> responseFilter.handleErrors = True
</span><span class="cx"> request.addResponseFilter(responseFilter)
</span><span class="cx"> return request
</span><span class="lines">@@ -1066,7 +1162,8 @@
</span><span class="cx"> (config.GroupCaching.Enabled and config.GroupCaching.EnableUpdater)
</span><span class="cx"> ).setServiceParent(service)
</span><span class="cx">
</span><del>- # For calendarserver.tap.test.test_caldav.BaseServiceMakerTests.getSite():
</del><ins>+ # For calendarserver.tap.test
+ # .test_caldav.BaseServiceMakerTests.getSite():
</ins><span class="cx"> connectionService.underlyingSite = underlyingSite
</span><span class="cx">
</span><span class="cx"> if config.InheritFDs or config.InheritSSLFDs:
</span><span class="lines">@@ -1077,7 +1174,10 @@
</span><span class="cx"> try:
</span><span class="cx"> contextFactory = self.createContextFactory()
</span><span class="cx"> except SSLError, e:
</span><del>- log.error("Unable to set up SSL context factory: %s" % (e,))
</del><ins>+ log.error(
+ "Unable to set up SSL context factory: {error}",
+ error=e
+ )
</ins><span class="cx"> else:
</span><span class="cx"> MaxAcceptSSLServer(
</span><span class="cx"> int(fdAsStr), httpFactory,
</span><span class="lines">@@ -1099,7 +1199,10 @@
</span><span class="cx"> try:
</span><span class="cx"> contextFactory = self.createContextFactory()
</span><span class="cx"> except SSLError, e:
</span><del>- self.log.error("Unable to set up SSL context factory: %s" % (e,))
</del><ins>+ self.log.error(
+ "Unable to set up SSL context factory: {error}",
+ error=e
+ )
</ins><span class="cx"> # None is okay as a context factory for ReportingHTTPService as
</span><span class="cx"> # long as we will never receive a file descriptor with the
</span><span class="cx"> # 'SSL' tag on it, since that's the only time it's used.
</span><span class="lines">@@ -1109,20 +1212,24 @@
</span><span class="cx"> requestFactory, int(config.MetaFD), contextFactory
</span><span class="cx"> ).setServiceParent(connectionService)
</span><span class="cx">
</span><del>- else: # Not inheriting, therefore we open our own:
</del><ins>+ else: # Not inheriting, therefore we open our own:
</ins><span class="cx"> for bindAddress in self._allBindAddresses():
</span><span class="cx"> self._validatePortConfig()
</span><span class="cx"> if config.EnableSSL:
</span><span class="cx"> for port in config.BindSSLPorts:
</span><del>- self.log.info("Adding SSL server at %s:%s"
- % (bindAddress, port))
</del><ins>+ self.log.info(
+ "Adding SSL server at {address}:{port}",
+ address=bindAddress, port=port
+ )
</ins><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> contextFactory = self.createContextFactory()
</span><span class="cx"> except SSLError, e:
</span><del>- self.log.error("Unable to set up SSL context factory: %s"
- % (e,))
- self.log.error("Disabling SSL port: %s" % (port,))
</del><ins>+ self.log.error(
+ "Unable to set up SSL context factory: {error}"
+ "Disabling SSL port: {port}",
+ error=e, port=port
+ )
</ins><span class="cx"> else:
</span><span class="cx"> httpsService = MaxAcceptSSLServer(
</span><span class="cx"> int(port), httpFactory,
</span><span class="lines">@@ -1210,15 +1317,17 @@
</span><span class="cx"> observers = []
</span><span class="cx"> if config.Notifications.Services.APNS.Enabled:
</span><span class="cx"> pushSubService = ApplePushNotifierService.makeService(
</span><del>- config.Notifications.Services.APNS, store)
</del><ins>+ config.Notifications.Services.APNS, store
+ )
</ins><span class="cx"> observers.append(pushSubService)
</span><span class="cx"> pushSubService.setServiceParent(result)
</span><span class="cx"> if config.Notifications.Services.AMP.Enabled:
</span><del>- pushSubService = AMPPushMaster(None, result,
</del><ins>+ pushSubService = AMPPushMaster(
+ None, result,
</ins><span class="cx"> config.Notifications.Services.AMP.Port,
</span><span class="cx"> config.Notifications.Services.AMP.EnableStaggering,
</span><del>- config.Notifications.Services.AMP.StaggerSeconds
- )
</del><ins>+ config.Notifications.Services.AMP.StaggerSeconds,
+ )
</ins><span class="cx"> observers.append(pushSubService)
</span><span class="cx"> if observers:
</span><span class="cx"> pushDistributor = PushDistributor(observers)
</span><span class="lines">@@ -1227,8 +1336,9 @@
</span><span class="cx">
</span><span class="cx"> # Optionally set up mail retrieval
</span><span class="cx"> if config.Scheduling.iMIP.Enabled:
</span><del>- mailRetriever = MailRetriever(store, directory,
- config.Scheduling.iMIP.Receiving)
</del><ins>+ mailRetriever = MailRetriever(
+ store, directory, config.Scheduling.iMIP.Receiving
+ )
</ins><span class="cx"> mailRetriever.setServiceParent(result)
</span><span class="cx"> else:
</span><span class="cx"> mailRetriever = None
</span><span class="lines">@@ -1244,7 +1354,9 @@
</span><span class="cx"> namespace=config.GroupCaching.MemcachedPool,
</span><span class="cx"> useExternalProxies=config.GroupCaching.UseExternalProxies
</span><span class="cx"> )
</span><del>- newGroupCacher = NewGroupCacher(DirectoryProxyClientService(None))
</del><ins>+ newGroupCacher = NewGroupCacher(
+ DirectoryProxyClientService(None)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> groupCacher = None
</span><span class="cx"> newGroupCacher = None
</span><span class="lines">@@ -1252,24 +1364,31 @@
</span><span class="cx"> # Optionally enable Manhole access
</span><span class="cx"> if config.Manhole.Enabled:
</span><span class="cx"> try:
</span><del>- from twisted.conch.manhole_tap import makeService as manholeMakeService
- portString = "tcp:%d:interface=127.0.0.1" % (config.Manhole.StartingPortNumber,)
</del><ins>+ from twisted.conch.manhole_tap import (
+ makeService as manholeMakeService
+ )
+ portString = "tcp:{:d}:interface=127.0.0.1".format(
+ config.Manhole.StartingPortNumber
+ )
</ins><span class="cx"> manholeService = manholeMakeService({
</span><del>- "sshPort" : None,
- "telnetPort" : portString,
- "namespace" : {
- "config" : config,
- "service" : result,
- "store" : store,
- "directory" : directory,
- },
- "passwd" : config.Manhole.PasswordFilePath,
</del><ins>+ "sshPort": None,
+ "telnetPort": portString,
+ "namespace": {
+ "config": config,
+ "service": result,
+ "store": store,
+ "directory": directory,
+ },
+ "passwd": config.Manhole.PasswordFilePath,
</ins><span class="cx"> })
</span><span class="cx"> manholeService.setServiceParent(result)
</span><span class="cx"> # Using print(because logging isn't ready at this point)
</span><del>- print("Manhole access enabled: %s" % (portString,))
</del><ins>+ print("Manhole access enabled:", portString)
</ins><span class="cx"> except ImportError:
</span><del>- print("Manhole access could not enabled because manhole_tap could not be imported")
</del><ins>+ print(
+ "Manhole access could not enabled because "
+ "manhole_tap could not be imported"
+ )
</ins><span class="cx">
</span><span class="cx"> # Optionally enable Directory Proxy
</span><span class="cx"> if config.DirectoryProxy.Enabled:
</span><span class="lines">@@ -1302,7 +1421,8 @@
</span><span class="cx"> for name, pool in config.Memcached.Pools.items():
</span><span class="cx"> if pool.ServerEnabled:
</span><span class="cx"> self.log.info(
</span><del>- "Adding memcached service for pool: %s" % (name,)
</del><ins>+ "Adding memcached service for pool: {name}",
+ name=name, pool=pool
</ins><span class="cx"> )
</span><span class="cx"> memcachedArgv = [
</span><span class="cx"> config.Memcached.memcached,
</span><span class="lines">@@ -1319,7 +1439,9 @@
</span><span class="cx"> memcachedArgv.extend(config.Memcached.Options)
</span><span class="cx"> Popen(memcachedArgv)
</span><span class="cx">
</span><del>- return self.storageService(slaveSvcCreator, logObserver, uid=uid, gid=gid)
</del><ins>+ return self.storageService(
+ slaveSvcCreator, logObserver, uid=uid, gid=gid
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def makeService_Utility(self, options):
</span><span class="lines">@@ -1342,9 +1464,9 @@
</span><span class="cx"> Create an agent service which listens for configuration requests
</span><span class="cx"> """
</span><span class="cx">
</span><del>- # Don't use memcached initially -- calendar server might take it away at
- # any moment. However, when we run a command through the gateway, it
- # will conditionally set ClientEnabled at that time.
</del><ins>+ # Don't use memcached initially -- calendar server might take it away
+ # at any moment. However, when we run a command through the gateway,
+ # it will conditionally set ClientEnabled at that time.
</ins><span class="cx"> def agentPostUpdateHook(configDict, reloading=False):
</span><span class="cx"> configDict.Memcached.Pools.Default.ClientEnabled = False
</span><span class="cx">
</span><span class="lines">@@ -1359,8 +1481,11 @@
</span><span class="cx"> if storageService is not None:
</span><span class="cx"> # Shut down if DataRoot becomes unavailable
</span><span class="cx"> from twisted.internet import reactor
</span><del>- dataStoreWatcher = DirectoryChangeListener(reactor,
- config.DataRoot, DataStoreMonitor(reactor, storageService))
</del><ins>+ dataStoreWatcher = DirectoryChangeListener(
+ reactor,
+ config.DataRoot,
+ DataStoreMonitor(reactor, storageService)
+ )
</ins><span class="cx"> dataStoreWatcher.startListening()
</span><span class="cx"> if store is not None:
</span><span class="cx"> store.queuer = NonPerformingQueuer()
</span><span class="lines">@@ -1373,12 +1498,14 @@
</span><span class="cx"> config.AgentLogFile,
</span><span class="cx"> config.ErrorLogRotateMB * 1024 * 1024,
</span><span class="cx"> config.ErrorLogMaxRotatedFiles
</span><del>- )
</del><ins>+ )
</ins><span class="cx"> svc.setServiceParent(agentLoggingService)
</span><span class="cx"> return agentLoggingService
</span><span class="cx">
</span><span class="cx">
</span><del>- def storageService(self, createMainService, logObserver, uid=None, gid=None):
</del><ins>+ def storageService(
+ self, createMainService, logObserver, uid=None, gid=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> If necessary, create a service to be started used for storage; for
</span><span class="cx"> example, starting a database backend. This service will then start the
</span><span class="lines">@@ -1388,14 +1515,13 @@
</span><span class="cx"> stand alone port-binding until the backing for the selected data store
</span><span class="cx"> implementation is ready to process requests.
</span><span class="cx">
</span><del>- @param createMainService: This is the service that will be doing the main
- work of the current process. If the configured storage mode does
- not require any particular setup, then this may return the
</del><ins>+ @param createMainService: This is the service that will be doing the
+ main work of the current process. If the configured storage mode
+ does not require any particular setup, then this may return the
</ins><span class="cx"> C{mainService} argument.
</span><ins>+ @type createMainService: C{callable} that takes C{(connectionPool,
+ store)} and returns L{IService}
</ins><span class="cx">
</span><del>- @type createMainService: C{callable} that takes C{(connectionPool, store)}
- and returns L{IService}
-
</del><span class="cx"> @param uid: the user ID to run the backend as, if this process is
</span><span class="cx"> running as root (also the uid to chown Attachments to).
</span><span class="cx"> @type uid: C{int}
</span><span class="lines">@@ -1405,21 +1531,24 @@
</span><span class="cx"> @type gid: C{int}
</span><span class="cx">
</span><span class="cx"> @return: the appropriate a service to start.
</span><del>-
</del><span class="cx"> @rtype: L{IService}
</span><span class="cx"> """
</span><del>- def createSubServiceFactory(dialect=POSTGRES_DIALECT,
- paramstyle='pyformat'):
</del><ins>+ def createSubServiceFactory(
+ dialect=POSTGRES_DIALECT, paramstyle='pyformat'
+ ):
</ins><span class="cx"> def subServiceFactory(connectionFactory, storageService):
</span><span class="cx"> ms = MultiService()
</span><del>- cp = ConnectionPool(connectionFactory, dialect=dialect,
- paramstyle=paramstyle,
- maxConnections=config.MaxDBConnectionsPerPool)
</del><ins>+ cp = ConnectionPool(
+ connectionFactory, dialect=dialect,
+ paramstyle=paramstyle,
+ maxConnections=config.MaxDBConnectionsPerPool
+ )
</ins><span class="cx"> cp.setServiceParent(ms)
</span><span class="cx"> store = storeFromConfig(config, cp.connection)
</span><span class="cx">
</span><del>- pps = PreProcessingService(createMainService, cp, store,
- logObserver, storageService)
</del><ins>+ pps = PreProcessingService(
+ createMainService, cp, store, logObserver, storageService
+ )
</ins><span class="cx">
</span><span class="cx"> # The following "steps" will run sequentially when the service
</span><span class="cx"> # hierarchy is started. If any of the steps raise an exception
</span><span class="lines">@@ -1479,13 +1608,14 @@
</span><span class="cx"> # Conditionally stop after upgrade at this point
</span><span class="cx"> pps.addStep(
</span><span class="cx"> QuitAfterUpgradeStep(
</span><del>- config.StopAfterUpgradeTriggerFile or config.UpgradeHomePrefix
</del><ins>+ config.StopAfterUpgradeTriggerFile or
+ config.UpgradeHomePrefix
</ins><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> pps.addStep(
</span><del>- PostDBImportStep(store, config,
- getattr(self, "doPostImport", True)
</del><ins>+ PostDBImportStep(
+ store, config, getattr(self, "doPostImport", True)
</ins><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx">
</span><span class="lines">@@ -1505,7 +1635,7 @@
</span><span class="cx">
</span><span class="cx"> if config.UseDatabase:
</span><span class="cx">
</span><del>- if os.getuid() == 0: # Only override if root
</del><ins>+ if os.getuid() == 0: # Only override if root
</ins><span class="cx"> overrideUID = uid
</span><span class="cx"> overrideGID = gid
</span><span class="cx"> else:
</span><span class="lines">@@ -1521,17 +1651,23 @@
</span><span class="cx"> uid=overrideUID, gid=overrideGID
</span><span class="cx"> )
</span><span class="cx"> return pgserv
</span><del>- elif config.DBType == 'postgres':
</del><ins>+ elif config.DBType == "postgres":
</ins><span class="cx"> # Connect to a postgres database that is already running.
</span><del>- return createSubServiceFactory()(pgConnectorFromConfig(config), None)
- elif config.DBType == 'oracle':
</del><ins>+ return createSubServiceFactory()(
+ pgConnectorFromConfig(config), None
+ )
+ elif config.DBType == "oracle":
</ins><span class="cx"> # Connect to an Oracle database that is already running.
</span><del>- return createSubServiceFactory(dialect=ORACLE_DIALECT,
- paramstyle='numeric')(
</del><ins>+ return createSubServiceFactory(
+ dialect=ORACLE_DIALECT,
+ paramstyle="numeric"
+ )(
</ins><span class="cx"> oracleConnectorFromConfig(config), None
</span><span class="cx"> )
</span><span class="cx"> else:
</span><del>- raise UsageError("Unknown database type %r" (config.DBType,))
</del><ins>+ raise UsageError(
+ "Unknown database type {}".format(config.DBType)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> store = storeFromConfig(config, None)
</span><span class="cx"> return createMainService(None, store, logObserver, None)
</span><span class="lines">@@ -1566,8 +1702,9 @@
</span><span class="cx"> try:
</span><span class="cx"> gid = getgrnam(config.GroupName).gr_gid
</span><span class="cx"> except KeyError:
</span><del>- raise ConfigurationError("Invalid group name: %s" %
- (config.GroupName,))
</del><ins>+ raise ConfigurationError(
+ "Invalid group name: {}".format(config.GroupName)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> gid = os.getgid()
</span><span class="cx">
</span><span class="lines">@@ -1575,8 +1712,9 @@
</span><span class="cx"> try:
</span><span class="cx"> uid = getpwnam(config.UserName).pw_uid
</span><span class="cx"> except KeyError:
</span><del>- raise ConfigurationError("Invalid user name: %s" %
- (config.UserName,))
</del><ins>+ raise ConfigurationError(
+ "Invalid user name: {}".format(config.UserName)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> uid = os.getuid()
</span><span class="cx">
</span><span class="lines">@@ -1584,7 +1722,10 @@
</span><span class="cx"> controlSocket.addFactory(_LOG_ROUTE, logger)
</span><span class="cx">
</span><span class="cx"> # Optionally set up AMPPushMaster
</span><del>- if config.Notifications.Enabled and config.Notifications.Services.AMP.Enabled:
</del><ins>+ if (
+ config.Notifications.Enabled and
+ config.Notifications.Services.AMP.Enabled
+ ):
</ins><span class="cx"> ampSettings = config.Notifications.Services.AMP
</span><span class="cx"> AMPPushMaster(
</span><span class="cx"> controlSocket,
</span><span class="lines">@@ -1609,14 +1750,17 @@
</span><span class="cx"> monitor.setServiceParent(s)
</span><span class="cx">
</span><span class="cx"> if config.MemoryLimiter.Enabled:
</span><del>- memoryLimiter = MemoryLimitService(monitor, config.MemoryLimiter.Seconds,
- config.MemoryLimiter.Bytes, config.MemoryLimiter.ResidentOnly)
</del><ins>+ memoryLimiter = MemoryLimitService(
+ monitor, config.MemoryLimiter.Seconds,
+ config.MemoryLimiter.Bytes, config.MemoryLimiter.ResidentOnly
+ )
</ins><span class="cx"> memoryLimiter.setServiceParent(s)
</span><span class="cx">
</span><span class="cx"> for name, pool in config.Memcached.Pools.items():
</span><span class="cx"> if pool.ServerEnabled:
</span><span class="cx"> self.log.info(
</span><del>- "Adding memcached service for pool: %s" % (name,)
</del><ins>+ "Adding memcached service for pool: {name}",
+ name=name, pool=pool
</ins><span class="cx"> )
</span><span class="cx"> memcachedArgv = [
</span><span class="cx"> config.Memcached.memcached,
</span><span class="lines">@@ -1631,8 +1775,10 @@
</span><span class="cx"> if config.UserName:
</span><span class="cx"> memcachedArgv.extend(["-u", config.UserName])
</span><span class="cx"> memcachedArgv.extend(config.Memcached.Options)
</span><del>- monitor.addProcess('memcached-%s' % (name,), memcachedArgv,
- env=PARENT_ENVIRONMENT)
</del><ins>+ monitor.addProcess(
+ "memcached-{}".format(name), memcachedArgv,
+ env=PARENT_ENVIRONMENT
+ )
</ins><span class="cx">
</span><span class="cx"> # Open the socket(s) to be inherited by the slaves
</span><span class="cx"> inheritFDs = []
</span><span class="lines">@@ -1644,7 +1790,8 @@
</span><span class="cx"> config.MultiProcess.ProcessCount))
</span><span class="cx"> dispatcher = cl.dispatcher
</span><span class="cx"> else:
</span><del>- s._inheritedSockets = [] # keep a reference to these so they don't close
</del><ins>+ # keep a reference to these so they don't close
+ s._inheritedSockets = []
</ins><span class="cx"> dispatcher = None
</span><span class="cx">
</span><span class="cx"> for bindAddress in self._allBindAddresses():
</span><span class="lines">@@ -1655,10 +1802,16 @@
</span><span class="cx"> portsList.append((config.BindSSLPorts, "SSL"))
</span><span class="cx"> for ports, description in portsList:
</span><span class="cx"> for port in ports:
</span><del>- cl.addPortService(description, port, bindAddress, config.ListenBacklog)
</del><ins>+ cl.addPortService(
+ description, port, bindAddress,
+ config.ListenBacklog
+ )
</ins><span class="cx"> else:
</span><span class="cx"> def _openSocket(addr, port):
</span><del>- log.info("Opening socket for inheritance at %s:%d" % (addr, port))
</del><ins>+ log.info(
+ "Opening socket for inheritance at {address}:{port}",
+ address=addr, port=port
+ )
</ins><span class="cx"> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
</span><span class="cx"> sock.setblocking(0)
</span><span class="cx"> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
</span><span class="lines">@@ -1696,22 +1849,29 @@
</span><span class="cx"> # Optionally enable Manhole access
</span><span class="cx"> if config.Manhole.Enabled:
</span><span class="cx"> try:
</span><del>- from twisted.conch.manhole_tap import makeService as manholeMakeService
- portString = "tcp:%d:interface=127.0.0.1" % (config.Manhole.StartingPortNumber,)
</del><ins>+ from twisted.conch.manhole_tap import (
+ makeService as manholeMakeService
+ )
+ portString = "tcp:{:d}:interface=127.0.0.1".format(
+ config.Manhole.StartingPortNumber
+ )
</ins><span class="cx"> manholeService = manholeMakeService({
</span><del>- "sshPort" : None,
- "telnetPort" : portString,
- "namespace" : {
- "config" : config,
- "service" : s,
- },
- "passwd" : config.Manhole.PasswordFilePath,
</del><ins>+ "sshPort": None,
+ "telnetPort": portString,
+ "namespace": {
+ "config": config,
+ "service": s,
+ },
+ "passwd": config.Manhole.PasswordFilePath,
</ins><span class="cx"> })
</span><span class="cx"> manholeService.setServiceParent(s)
</span><span class="cx"> # Using print(because logging isn't ready at this point)
</span><del>- print("Manhole access enabled: %s" % (portString,))
</del><ins>+ print("Manhole access enabled:", portString)
</ins><span class="cx"> except ImportError:
</span><del>- print("Manhole access could not enabled because manhole_tap could not be imported")
</del><ins>+ print(
+ "Manhole access could not enabled because "
+ "manhole_tap could not be imported"
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> # Finally, let's get the real show on the road. Create a service that
</span><span class="lines">@@ -1727,9 +1887,13 @@
</span><span class="cx"> raise StoreNotAvailable()
</span><span class="cx">
</span><span class="cx"> from twisted.internet import reactor
</span><del>- pool = PeerConnectionPool(reactor, store.newTransaction, config.WorkQueue.ampPort)
</del><ins>+ pool = PeerConnectionPool(
+ reactor, store.newTransaction, config.WorkQueue.ampPort
+ )
</ins><span class="cx"> store.queuer = store.queuer.transferProposalCallbacks(pool)
</span><del>- controlSocket.addFactory(_QUEUE_ROUTE, pool.workerListenerFactory())
</del><ins>+ controlSocket.addFactory(
+ _QUEUE_ROUTE, pool.workerListenerFactory()
+ )
</ins><span class="cx"> # TODO: now that we have the shared control socket, we should get
</span><span class="cx"> # rid of the connection dispenser and make a shared / async
</span><span class="cx"> # connection pool implementation that can dispense transactions
</span><span class="lines">@@ -1754,8 +1918,9 @@
</span><span class="cx">
</span><span class="cx"> # Optionally set up mail retrieval
</span><span class="cx"> if config.Scheduling.iMIP.Enabled:
</span><del>- mailRetriever = MailRetriever(store, directory,
- config.Scheduling.iMIP.Receiving)
</del><ins>+ mailRetriever = MailRetriever(
+ store, directory, config.Scheduling.iMIP.Receiving
+ )
</ins><span class="cx"> mailRetriever.setServiceParent(multi)
</span><span class="cx"> else:
</span><span class="cx"> mailRetriever = None
</span><span class="lines">@@ -1770,7 +1935,7 @@
</span><span class="cx"> config.GroupCaching.LockSeconds,
</span><span class="cx"> namespace=config.GroupCaching.MemcachedPool,
</span><span class="cx"> useExternalProxies=config.GroupCaching.UseExternalProxies
</span><del>- )
</del><ins>+ )
</ins><span class="cx"> else:
</span><span class="cx"> groupCacher = None
</span><span class="cx">
</span><span class="lines">@@ -1792,20 +1957,27 @@
</span><span class="cx"> def deleteStaleSocketFiles(self):
</span><span class="cx">
</span><span class="cx"> # Check all socket files we use.
</span><del>- for checkSocket in [config.ControlSocket, config.Stats.UnixStatsSocket] :
-
</del><ins>+ for checkSocket in [
+ config.ControlSocket, config.Stats.UnixStatsSocket
+ ]:
</ins><span class="cx"> # See if the file exists.
</span><span class="cx"> if (os.path.exists(checkSocket)):
</span><span class="cx"> # See if the file represents a socket. If not, delete it.
</span><span class="cx"> if (not stat.S_ISSOCK(os.stat(checkSocket).st_mode)):
</span><del>- self.log.warn("Deleting stale socket file (not a socket): %s" % checkSocket)
</del><ins>+ self.log.warn(
+ "Deleting stale socket file (not a socket): {socket}",
+ socket=checkSocket
+ )
</ins><span class="cx"> os.remove(checkSocket)
</span><span class="cx"> else:
</span><del>- # It looks like a socket. See if it's accepting connections.
- tmpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
</del><ins>+ # It looks like a socket.
+ # See if it's accepting connections.
+ tmpSocket = socket.socket(
+ socket.AF_INET, socket.SOCK_STREAM
+ )
</ins><span class="cx"> numConnectFailures = 0
</span><span class="cx"> testPorts = [config.HTTPPort, config.SSLPort]
</span><del>- for testPort in testPorts :
</del><ins>+ for testPort in testPorts:
</ins><span class="cx"> try:
</span><span class="cx"> tmpSocket.connect(("127.0.0.1", testPort))
</span><span class="cx"> tmpSocket.shutdown(2)
</span><span class="lines">@@ -1814,7 +1986,11 @@
</span><span class="cx"> # If the file didn't connect on any expected ports,
</span><span class="cx"> # consider it stale and remove it.
</span><span class="cx"> if numConnectFailures == len(testPorts):
</span><del>- self.log.warn("Deleting stale socket file (not accepting connections): %s" % checkSocket)
</del><ins>+ self.log.warn(
+ "Deleting stale socket file "
+ "(not accepting connections): {socket}",
+ socket=checkSocket
+ )
</ins><span class="cx"> os.remove(checkSocket)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -1869,11 +2045,13 @@
</span><span class="cx"> self.configFile = configFile
</span><span class="cx">
</span><span class="cx"> self.id = id
</span><ins>+
</ins><span class="cx"> def emptyIfNone(x):
</span><span class="cx"> if x is None:
</span><span class="cx"> return []
</span><span class="cx"> else:
</span><span class="cx"> return x
</span><ins>+
</ins><span class="cx"> self.inheritFDs = emptyIfNone(inheritFDs)
</span><span class="cx"> self.inheritSSLFDs = emptyIfNone(inheritSSLFDs)
</span><span class="cx"> self.metaSocket = metaSocket
</span><span class="lines">@@ -1883,7 +2061,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def getName(self):
</span><del>- return '%s-%s' % (self.prefix, self.id)
</del><ins>+ return "{}-{}".format(self.prefix, self.id)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def getFileDescriptors(self):
</span><span class="lines">@@ -1935,46 +2113,49 @@
</span><span class="cx"> args.extend(("-g", config.GroupName))
</span><span class="cx">
</span><span class="cx"> if config.Profiling.Enabled:
</span><del>- args.append(
- "--profile=%s/%s.pstats"
- % (config.Profiling.BaseDirectory, self.getName())
- )
</del><ins>+ args.append("--profile={}/{}.pstats".format(
+ config.Profiling.BaseDirectory, self.getName()
+ ))
</ins><span class="cx"> args.extend(("--savestats", "--profiler", "cprofile-cpu"))
</span><span class="cx">
</span><span class="cx"> args.extend([
</span><del>- "--reactor=%s" % (config.Twisted.reactor,),
</del><ins>+ "--reactor={}".format(config.Twisted.reactor),
</ins><span class="cx"> "-n", self.tapname,
</span><span class="cx"> "-f", self.configFile,
</span><span class="cx"> "-o", "ProcessType=Slave",
</span><del>- "-o", "BindAddresses=%s" % (",".join(self.interfaces),),
- "-o", "PIDFile=%s-instance-%s.pid" % (self.tapname, self.id,),
</del><ins>+ "-o", "BindAddresses={}".format(",".join(self.interfaces)),
+ "-o", "PIDFile={}-instance-{}.pid".format(self.tapname, self.id),
</ins><span class="cx"> "-o", "ErrorLogFile=None",
</span><span class="cx"> "-o", "ErrorLogEnabled=False",
</span><del>- "-o", "LogID=%s" % (self.id,),
- "-o", "MultiProcess/ProcessCount=%d"
- % (config.MultiProcess.ProcessCount,),
- "-o", "ControlPort=%d"
- % (config.ControlPort,),
</del><ins>+ "-o", "LogID={}".format(self.id),
+ "-o", "MultiProcess/ProcessCount={:d}".format(
+ config.MultiProcess.ProcessCount
+ ),
+ "-o", "ControlPort={:d}".format(config.ControlPort),
</ins><span class="cx"> ])
</span><span class="cx">
</span><span class="cx"> if self.inheritFDs:
</span><span class="cx"> args.extend([
</span><del>- "-o", "InheritFDs=%s" % (",".join(map(str, self.inheritFDs)),)
</del><ins>+ "-o", "InheritFDs={}".format(
+ ",".join(map(str, self.inheritFDs))
+ )
</ins><span class="cx"> ])
</span><span class="cx">
</span><span class="cx"> if self.inheritSSLFDs:
</span><span class="cx"> args.extend([
</span><del>- "-o", "InheritSSLFDs=%s" % (",".join(map(str, self.inheritSSLFDs)),)
</del><ins>+ "-o", "InheritSSLFDs={}".format(
+ ",".join(map(str, self.inheritSSLFDs))
+ )
</ins><span class="cx"> ])
</span><span class="cx">
</span><span class="cx"> if self.metaSocket is not None:
</span><span class="cx"> args.extend([
</span><del>- "-o", "MetaFD=%s" % (self.metaSocket.fileno(),)
- ])
</del><ins>+ "-o", "MetaFD={}".format(self.metaSocket.fileno())
+ ])
</ins><span class="cx"> if self.ampDBSocket is not None:
</span><span class="cx"> args.extend([
</span><del>- "-o", "DBAMPFD=%s" % (self.ampDBSocket.fileno(),)
- ])
</del><ins>+ "-o", "DBAMPFD={}".format(self.ampDBSocket.fileno())
+ ])
</ins><span class="cx"> return args
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -2064,10 +2245,13 @@
</span><span class="cx"> class SimpleProcessObject(object):
</span><span class="cx"> def getName(self):
</span><span class="cx"> return name
</span><ins>+
</ins><span class="cx"> def getCommandLine(self):
</span><span class="cx"> return args
</span><ins>+
</ins><span class="cx"> def getFileDescriptors(self):
</span><span class="cx"> return []
</span><ins>+
</ins><span class="cx"> self.addProcessObject(SimpleProcessObject(), env, uid, gid)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -2132,7 +2316,7 @@
</span><span class="cx"> @param name: The name of the process to be stopped
</span><span class="cx"> """
</span><span class="cx"> if name not in self.processes:
</span><del>- raise KeyError('Unrecognized process name: %s' % (name,))
</del><ins>+ raise KeyError("Unrecognized process name: {}".format(name))
</ins><span class="cx">
</span><span class="cx"> proto = self.protocols.get(name, None)
</span><span class="cx"> if proto is not None:
</span><span class="lines">@@ -2143,8 +2327,8 @@
</span><span class="cx"> pass
</span><span class="cx"> else:
</span><span class="cx"> self.murder[name] = self._reactor.callLater(
</span><del>- self.killTime,
- self._forceStopProcess, proc)
</del><ins>+ self.killTime, self._forceStopProcess, proc
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def processEnded(self, name):
</span><span class="lines">@@ -2241,7 +2425,7 @@
</span><span class="cx"> procObj, env, uid, gid = self.processes[name]
</span><span class="cx"> self.timeStarted[name] = time()
</span><span class="cx">
</span><del>- childFDs = {0 : "w", 1 : "r", 2 : "r"}
</del><ins>+ childFDs = {0: "w", 1: "r", 2: "r"}
</ins><span class="cx">
</span><span class="cx"> childFDs.update(procObj.getFileDescriptors())
</span><span class="cx">
</span><span class="lines">@@ -2263,17 +2447,19 @@
</span><span class="cx"> """
</span><span class="cx"> interval = (self.delayInterval * self._pendingStarts)
</span><span class="cx"> self._pendingStarts += 1
</span><ins>+
</ins><span class="cx"> def delayedStart():
</span><span class="cx"> self._pendingStarts -= 1
</span><span class="cx"> self.reallyStartProcess(name)
</span><ins>+
</ins><span class="cx"> self._reactor.callLater(interval, delayedStart)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def restartAll(self):
</span><span class="cx"> """
</span><span class="cx"> Restart all processes. This is useful for third party management
</span><del>- services to allow a user to restart servers because of an outside change
- in circumstances -- for example, a new version of a library is
</del><ins>+ services to allow a user to restart servers because of an outside
+ change in circumstances -- for example, a new version of a library is
</ins><span class="cx"> installed.
</span><span class="cx"> """
</span><span class="cx"> for name in self.processes:
</span><span class="lines">@@ -2282,6 +2468,7 @@
</span><span class="cx">
</span><span class="cx"> def __repr__(self):
</span><span class="cx"> l = []
</span><ins>+
</ins><span class="cx"> for name, (procObj, uid, gid, _ignore_env) in self.processes.items():
</span><span class="cx"> uidgid = ''
</span><span class="cx"> if uid is not None:
</span><span class="lines">@@ -2291,13 +2478,15 @@
</span><span class="cx">
</span><span class="cx"> if uidgid:
</span><span class="cx"> uidgid = '(' + uidgid + ')'
</span><del>- l.append('%r%s: %r' % (name, uidgid, procObj))
- return ('<' + self.__class__.__name__ + ' '
- + ' '.join(l)
- + '>')
</del><ins>+ l.append("{:r}{}: {:r}".format(name, uidgid, procObj))
</ins><span class="cx">
</span><ins>+ return (
+ "<{self.__class__.__name__} {l}>"
+ .format(self=self, l=" ".join(l))
+ )
</ins><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> class DelayedStartupLineLogger(object):
</span><span class="cx"> """
</span><span class="cx"> A line logger that can handle very long lines.
</span><span class="lines">@@ -2306,7 +2495,7 @@
</span><span class="cx"> MAX_LENGTH = 1024
</span><span class="cx"> CONTINUED_TEXT = " (truncated, continued)"
</span><span class="cx"> tag = None
</span><del>- exceeded = False # Am I in the middle of parsing a long line?
</del><ins>+ exceeded = False # Am I in the middle of parsing a long line?
</ins><span class="cx"> _buffer = ''
</span><span class="cx">
</span><span class="cx"> def makeConnection(self, transport):
</span><span class="lines">@@ -2338,7 +2527,7 @@
</span><span class="cx">
</span><span class="cx"> def lineReceived(self, line):
</span><span class="cx"> from twisted.python.log import msg
</span><del>- msg('[%s] %s' % (self.tag, line))
</del><ins>+ msg("[{}] {}".format(self.tag, line))
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def lineLengthExceeded(self, line):
</span><span class="lines">@@ -2361,13 +2550,22 @@
</span><span class="cx"> @return: array of C{str}
</span><span class="cx"> """
</span><span class="cx"> length = len(line)
</span><del>- numSegments = length / self.MAX_LENGTH + (1 if length % self.MAX_LENGTH else 0)
</del><ins>+
+ numSegments = (
+ length / self.MAX_LENGTH +
+ (1 if length % self.MAX_LENGTH else 0)
+ )
+
</ins><span class="cx"> segments = []
</span><ins>+
</ins><span class="cx"> for i in range(numSegments):
</span><span class="cx"> msg = line[i * self.MAX_LENGTH:(i + 1) * self.MAX_LENGTH]
</span><del>- if i < numSegments - 1: # not the last segment
</del><ins>+
+ if i < numSegments - 1: # not the last segment
</ins><span class="cx"> msg += self.CONTINUED_TEXT
</span><ins>+
</ins><span class="cx"> segments.append(msg)
</span><ins>+
</ins><span class="cx"> return segments
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -2424,10 +2622,14 @@
</span><span class="cx"> output, error = child.communicate()
</span><span class="cx">
</span><span class="cx"> if child.returncode:
</span><del>- log.error("Could not get passphrase for %s: %s"
- % (config.SSLPrivateKey, error))
</del><ins>+ log.error(
+ "Could not get passphrase for {key}: {error}",
+ key=config.SSLPrivateKey, error=error
+ )
</ins><span class="cx"> else:
</span><del>- log.info("Obtained passphrase for %s" % (config.SSLPrivateKey))
</del><ins>+ log.info(
+ "Obtained passphrase for {key}", key=config.SSLPrivateKey
+ )
</ins><span class="cx"> return output.strip()
</span><span class="cx">
</span><span class="cx"> if (
</span><span class="lines">@@ -2448,13 +2650,15 @@
</span><span class="cx"> sslPrivKey.close()
</span><span class="cx">
</span><span class="cx"> if keyType is None:
</span><del>- log.error("Could not get private key type for %s"
- % (config.SSLPrivateKey,))
</del><ins>+ log.error(
+ "Could not get private key type for {key}",
+ key=config.SSLPrivateKey
+ )
</ins><span class="cx"> else:
</span><span class="cx"> child = Popen(
</span><span class="cx"> args=[
</span><span class="cx"> config.SSLPassPhraseDialog,
</span><del>- "%s:%s" % (config.ServerHostName, config.SSLPort),
</del><ins>+ "{}:{}".format(config.ServerHostName, config.SSLPort),
</ins><span class="cx"> keyType,
</span><span class="cx"> ],
</span><span class="cx"> stdout=PIPE, stderr=PIPE,
</span><span class="lines">@@ -2462,8 +2666,10 @@
</span><span class="cx"> output, error = child.communicate()
</span><span class="cx">
</span><span class="cx"> if child.returncode:
</span><del>- log.error("Could not get passphrase for %s: %s"
- % (config.SSLPrivateKey, error))
</del><ins>+ log.error(
+ "Could not get passphrase for {key}: {error}",
+ key=config.SSLPrivateKey, error=error
+ )
</ins><span class="cx"> else:
</span><span class="cx"> return output.strip()
</span><span class="cx">
</span><span class="lines">@@ -2489,7 +2695,9 @@
</span><span class="cx"> try:
</span><span class="cx"> uid = getpwnam(userName).pw_uid
</span><span class="cx"> except KeyError:
</span><del>- raise ConfigurationError("Invalid user name: %s" % (userName,))
</del><ins>+ raise ConfigurationError(
+ "Invalid user name: {}".format(userName)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> uid = getuid()
</span><span class="cx">
</span><span class="lines">@@ -2497,7 +2705,9 @@
</span><span class="cx"> try:
</span><span class="cx"> gid = getgrnam(groupName).gr_gid
</span><span class="cx"> except KeyError:
</span><del>- raise ConfigurationError("Invalid group name: %s" % (groupName,))
</del><ins>+ raise ConfigurationError(
+ "Invalid group name: {}".format(groupName)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> gid = getgid()
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunkcalendarserverwebadminworkpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/webadmin/work.py (12786 => 12787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/webadmin/work.py        2014-03-03 22:49:22 UTC (rev 12786)
+++ CalendarServer/trunk/calendarserver/webadmin/work.py        2014-03-03 23:47:56 UTC (rev 12787)
</span><span class="lines">@@ -39,10 +39,11 @@
</span><span class="cx"> # from twistedcaldav.directory.directory import GroupCacherPollingWork
</span><span class="cx"> # from calendarserver.push.notifier import PushNotificationWork
</span><span class="cx">
</span><del>-from txdav.caldav.datastore.scheduling.work import (
- ScheduleOrganizerWork, ScheduleReplyWork, ScheduleRefreshWork
-)
</del><ins>+# from txdav.caldav.datastore.scheduling.work import (
+# ScheduleOrganizerWork, ScheduleReplyWork, ScheduleRefreshWork
+# )
</ins><span class="cx">
</span><ins>+from twext.enterprise.jobqueue import JobItem
</ins><span class="cx">
</span><span class="cx"> from .eventsource import EventSourceResource, IEventDecoder
</span><span class="cx"> from .resource import PageElement, TemplateResource
</span><span class="lines">@@ -105,62 +106,66 @@
</span><span class="cx">
</span><span class="cx"> payload = {}
</span><span class="cx">
</span><del>- for workDescription, workItemClass, itemAttributes in (
- (
- u"Organizer Request",
- ScheduleOrganizerWork,
- (
- ("icalendarUid", "iCalendar UID"),
- ("attendeeCount", "Attendee Count"),
- ),
- ),
- (
- u"Attendee Reply",
- ScheduleReplyWork,
- (
- ("icalendarUid", "iCalendar UID"),
- ),
- ),
- (
- u"Attendee Refresh",
- ScheduleRefreshWork,
- (
- ("icalendarUid", "iCalendar UID"),
- ("attendeeCount", "Attendee Count"),
- ),
- ),
- ):
- workItems = yield workItemClass.all(txn)
</del><ins>+ records = yield JobItem.histogram(txn)
</ins><span class="cx">
</span><del>- categoryData = []
</del><span class="cx">
</span><del>- for workItem in workItems:
- itemData = {}
</del><span class="cx">
</span><del>- for itemAttribute, itemDescription in itemAttributes:
- itemData[itemDescription] = getattr(
- workItem, itemAttribute
- )
</del><ins>+ # for workDescription, workItemClass, itemAttributes in (
+ # (
+ # u"Organizer Request",
+ # ScheduleOrganizerWork,
+ # (
+ # ("icalendarUid", "iCalendar UID"),
+ # ("attendeeCount", "Attendee Count"),
+ # ),
+ # ),
+ # (
+ # u"Attendee Reply",
+ # ScheduleReplyWork,
+ # (
+ # ("icalendarUid", "iCalendar UID"),
+ # ),
+ # ),
+ # (
+ # u"Attendee Refresh",
+ # ScheduleRefreshWork,
+ # (
+ # ("icalendarUid", "iCalendar UID"),
+ # ("attendeeCount", "Attendee Count"),
+ # ),
+ # ),
+ # ):
+ # workItems = yield workItemClass.all(txn)
</ins><span class="cx">
</span><del>- categoryData.append(itemData)
</del><ins>+ # categoryData = []
</ins><span class="cx">
</span><del>- payload[workDescription] = categoryData
</del><ins>+ # for workItem in workItems:
+ # itemData = {}
</ins><span class="cx">
</span><del>- self.addEvents((
- dict(
- eventClass=u"work",
- eventText=asJSON(payload),
- ),
- ))
</del><ins>+ # for itemAttribute, itemDescription in itemAttributes:
+ # itemData[itemDescription] = getattr(
+ # workItem, itemAttribute
+ # )
</ins><span class="cx">
</span><del>- if not hasattr(self, "_clock"):
- from twisted.internet import reactor
- self._clock = reactor
</del><ins>+ # categoryData.append(itemData)
</ins><span class="cx">
</span><del>- # self._clock.callLater(5, self.poll)
</del><ins>+ # payload[workDescription] = categoryData
</ins><span class="cx">
</span><ins>+ # self.addEvents((
+ # dict(
+ # eventClass=u"work",
+ # eventText=asJSON(payload),
+ # ),
+ # ))
</ins><span class="cx">
</span><ins>+ # if not hasattr(self, "_clock"):
+ # from twisted.internet import reactor
+ # self._clock = reactor
</ins><span class="cx">
</span><ins>+ # # self._clock.callLater(5, self.poll)
+
+
+
</ins><span class="cx"> @implementer(IEventDecoder)
</span><span class="cx"> class EventDecoder(object):
</span><span class="cx"> @staticmethod
</span></span></pre>
</div>
</div>
</body>
</html>