<!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>[12903] CalendarServer/trunk/calendarserver/tap/caldav.py</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/12903">12903</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-03-13 20:47:35 -0700 (Thu, 13 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Clean up imports</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertapcaldavpy">CalendarServer/trunk/calendarserver/tap/caldav.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 (12902 => 12903)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/caldav.py        2014-03-13 23:04:22 UTC (rev 12902)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py        2014-03-14 03:47:35 UTC (rev 12903)
</span><span class="lines">@@ -22,23 +22,27 @@
</span><span class="cx">     &quot;CalDAVServiceMaker&quot;,
</span><span class="cx"> ]
</span><span class="cx"> 
</span><del>-import os
</del><ins>+import sys
+# import os
+from os import getuid, getgid, umask, remove, environ, stat, chown
+from os.path import exists, basename, isfile
</ins><span class="cx"> import socket
</span><del>-import stat
-import sys
</del><ins>+from stat import S_ISSOCK
</ins><span class="cx"> from time import time
</span><span class="cx"> from subprocess import Popen, PIPE
</span><span class="cx"> from pwd import getpwuid, getpwnam
</span><span class="cx"> from grp import getgrnam
</span><ins>+
</ins><span class="cx"> import OpenSSL
</span><span class="cx"> from OpenSSL.SSL import Error as SSLError
</span><del>-from os import getuid, getgid
</del><span class="cx"> 
</span><span class="cx"> from zope.interface import implements
</span><span class="cx"> 
</span><del>-from twisted.application.internet import TCPServer, UNIXServer
-from twisted.application.service import MultiService, IServiceMaker
-from twisted.application.service import Service
</del><ins>+from twisted.python.log import FileLogObserver, ILogObserver
+from twisted.python.logfile import LogFile
+from twisted.python.usage import Options, UsageError
+from twisted.python.util import uidFromString, gidFromString
+from twisted.plugin import IPlugin
</ins><span class="cx"> from twisted.internet.defer import (
</span><span class="cx">     gatherResults, Deferred, inlineCallbacks, succeed
</span><span class="cx"> )
</span><span class="lines">@@ -46,27 +50,26 @@
</span><span class="cx"> from twisted.internet.process import ProcessExitedAlready
</span><span class="cx"> from twisted.internet.protocol import ProcessProtocol
</span><span class="cx"> from twisted.internet.protocol import Factory
</span><del>-from twisted.plugin import IPlugin
</del><ins>+from twisted.application.internet import TCPServer, UNIXServer
+from twisted.application.service import MultiService, IServiceMaker
+from twisted.application.service import Service
</ins><span class="cx"> from twisted.protocols.amp import AMP
</span><del>-from twisted.python.log import FileLogObserver, ILogObserver
-from twisted.python.logfile import LogFile
-from twisted.python.usage import Options, UsageError
-from twisted.python.util import uidFromString, gidFromString
</del><span class="cx"> 
</span><ins>+from twext.python.filepath import CachingFilePath
+from twext.python.log import Logger, LogLevel, replaceTwistedLoggers
+from twext.internet.fswatch import (
+    DirectoryChangeListener, IDirectoryChangeListenee
+)
+from twext.internet.ssl import ChainingOpenSSLContextFactory
+from twext.internet.tcp import MaxAcceptTCPServer, MaxAcceptSSLServer
</ins><span class="cx"> from twext.enterprise.adbapi2 import ConnectionPool
</span><span class="cx"> from twext.enterprise.ienterprise import ORACLE_DIALECT
</span><span class="cx"> from twext.enterprise.ienterprise import POSTGRES_DIALECT
</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
-)
-from twext.internet.ssl import ChainingOpenSSLContextFactory
-from twext.internet.tcp import MaxAcceptTCPServer, MaxAcceptSSLServer
-from twext.python.filepath import CachingFilePath
-from twext.python.log import Logger, LogLevel, replaceTwistedLoggers
</del><span class="cx"> from twext.application.service import ReExecService
</span><ins>+from txdav.who.groups import scheduleNextGroupCachingUpdate
</ins><span class="cx"> 
</span><span class="cx"> from txweb2.channel.http import (
</span><span class="cx">     LimitingHTTPFactory, SSLRedirectRequest, HTTPChannel
</span><span class="lines">@@ -95,7 +98,6 @@
</span><span class="cx"> from twistedcaldav.config import config, ConfigurationError
</span><span class="cx"> from twistedcaldav.directory import calendaruserproxy
</span><span class="cx"> from twistedcaldav.directory.directory import GroupMembershipCacheUpdater
</span><del>-from txdav.who.groups import scheduleNextGroupCachingUpdate
</del><span class="cx"> from twistedcaldav.localization import processLocalizationFiles
</span><span class="cx"> from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
</span><span class="cx"> from twistedcaldav.upgrade import UpgradeFileSystemFormatStep, PostDBImportStep
</span><span class="lines">@@ -125,11 +127,11 @@
</span><span class="cx"> 
</span><span class="cx"> try:
</span><span class="cx">     from calendarserver.version import version
</span><del>-    version
</del><span class="cx"> except ImportError:
</span><span class="cx">     from twisted.python.modules import getModule
</span><span class="cx">     sys.path.insert(
</span><del>-        0, getModule(__name__).pathEntry.filePath.child(&quot;support&quot;).path)
</del><ins>+        0, getModule(__name__).pathEntry.filePath.child(&quot;support&quot;).path
+    )
</ins><span class="cx">     from version import version as getVersion
</span><span class="cx">     version = &quot;{} ({}*)&quot;.format(getVersion())
</span><span class="cx"> 
</span><span class="lines">@@ -214,7 +216,7 @@
</span><span class="cx">             result[varname] = parent[varname]
</span><span class="cx">     return result
</span><span class="cx"> 
</span><del>-PARENT_ENVIRONMENT = _computeEnvVars(os.environ)
</del><ins>+PARENT_ENVIRONMENT = _computeEnvVars(environ)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -396,7 +398,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def loadConfiguration(self):
</span><del>-        if not os.path.exists(self[&quot;config&quot;]):
</del><ins>+        if not exists(self[&quot;config&quot;]):
</ins><span class="cx">             raise ConfigurationError(
</span><span class="cx">                 &quot;Config file {} not found. Exiting.&quot;
</span><span class="cx">                 .format(self[&quot;config&quot;])
</span><span class="lines">@@ -437,17 +439,17 @@
</span><span class="cx">             uid, gid = getid(self.parent[&quot;uid&quot;], self.parent[&quot;gid&quot;])
</span><span class="cx"> 
</span><span class="cx">         def gottaBeRoot():
</span><del>-            if os.getuid() != 0:
-                username = getpwuid(os.getuid()).pw_name
</del><ins>+            if getuid() != 0:
+                username = getpwuid(getuid()).pw_name
</ins><span class="cx">                 raise UsageError(
</span><span class="cx">                     &quot;Only root can drop privileges.  You are: {}&quot;
</span><span class="cx">                     .format(username)
</span><span class="cx">                 )
</span><span class="cx"> 
</span><del>-        if uid and uid != os.getuid():
</del><ins>+        if uid and uid != getuid():
</ins><span class="cx">             gottaBeRoot()
</span><span class="cx"> 
</span><del>-        if gid and gid != os.getgid():
</del><ins>+        if gid and gid != getgid():
</ins><span class="cx">             gottaBeRoot()
</span><span class="cx"> 
</span><span class="cx">         self.parent[&quot;pidfile&quot;] = config.PIDFile
</span><span class="lines">@@ -462,7 +464,7 @@
</span><span class="cx">             FileLogObserver.timeFormat = &quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Check current umask and warn if changed
</span><del>-        oldmask = os.umask(config.umask)
</del><ins>+        oldmask = umask(config.umask)
</ins><span class="cx">         if oldmask != config.umask:
</span><span class="cx">             self.log.info(
</span><span class="cx">                 &quot;WARNING: changing umask from: 0{old!03o} to 0{new!03o}&quot;,
</span><span class="lines">@@ -492,7 +494,7 @@
</span><span class="cx"> 
</span><span class="cx">         # Unfortunately, there's no public way to access this. -glyph
</span><span class="cx">         fileName = self._port.port
</span><del>-        os.chown(fileName, os.getuid(), self.gid)
</del><ins>+        chown(fileName, getuid(), self.gid)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -722,13 +724,13 @@
</span><span class="cx"> 
</span><span class="cx">     def removeTriggerFile(self):
</span><span class="cx">         try:
</span><del>-            os.remove(self.triggerFile)
</del><ins>+            remove(self.triggerFile)
</ins><span class="cx">         except OSError:
</span><span class="cx">             pass
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def stepWithResult(self, result):
</span><del>-        if os.path.exists(self.triggerFile):
</del><ins>+        if exists(self.triggerFile):
</ins><span class="cx">             self.removeTriggerFile()
</span><span class="cx">             self.reactor.stop()
</span><span class="cx">             raise PostUpgradeStopRequested()
</span><span class="lines">@@ -737,7 +739,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def stepWithFailure(self, failure):
</span><del>-        if os.path.exists(self.triggerFile):
</del><ins>+        if exists(self.triggerFile):
</ins><span class="cx">             self.removeTriggerFile()
</span><span class="cx">             self.reactor.stop()
</span><span class="cx">             raise PostUpgradeStopRequested()
</span><span class="lines">@@ -775,7 +777,7 @@
</span><span class="cx">             pass
</span><span class="cx"> 
</span><span class="cx">         else:
</span><del>-            execName = os.path.basename(sys.argv[0])
</del><ins>+            execName = basename(sys.argv[0])
</ins><span class="cx"> 
</span><span class="cx">             if config.LogID:
</span><span class="cx">                 logID = &quot; #{}&quot;.format(config.LogID)
</span><span class="lines">@@ -1569,7 +1571,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 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">@@ -1640,7 +1642,7 @@
</span><span class="cx">                     &quot;Invalid group name: {}&quot;.format(config.GroupName)
</span><span class="cx">                 )
</span><span class="cx">         else:
</span><del>-            gid = os.getgid()
</del><ins>+            gid = getgid()
</ins><span class="cx"> 
</span><span class="cx">         if config.UserName:
</span><span class="cx">             try:
</span><span class="lines">@@ -1650,7 +1652,7 @@
</span><span class="cx">                     &quot;Invalid user name: {}&quot;.format(config.UserName)
</span><span class="cx">                 )
</span><span class="cx">         else:
</span><del>-            uid = os.getuid()
</del><ins>+            uid = getuid()
</ins><span class="cx"> 
</span><span class="cx">         controlSocket = ControlSocket()
</span><span class="cx">         controlSocket.addFactory(_LOG_ROUTE, logger)
</span><span class="lines">@@ -1897,14 +1899,14 @@
</span><span class="cx">             config.ControlSocket, config.Stats.UnixStatsSocket
</span><span class="cx">         ]:
</span><span class="cx">             # See if the file exists.
</span><del>-            if (os.path.exists(checkSocket)):
</del><ins>+            if (exists(checkSocket)):
</ins><span class="cx">                 # See if the file represents a socket.  If not, delete it.
</span><del>-                if (not stat.S_ISSOCK(os.stat(checkSocket).st_mode)):
</del><ins>+                if (not S_ISSOCK(stat(checkSocket).st_mode)):
</ins><span class="cx">                     self.log.warn(
</span><span class="cx">                         &quot;Deleting stale socket file (not a socket): {socket}&quot;,
</span><span class="cx">                         socket=checkSocket
</span><span class="cx">                     )
</span><del>-                    os.remove(checkSocket)
</del><ins>+                    remove(checkSocket)
</ins><span class="cx">                 else:
</span><span class="cx">                     # It looks like a socket.
</span><span class="cx">                     # See if it's accepting connections.
</span><span class="lines">@@ -1927,7 +1929,7 @@
</span><span class="cx">                             &quot;(not accepting connections): {socket}&quot;,
</span><span class="cx">                             socket=checkSocket
</span><span class="cx">                         )
</span><del>-                        os.remove(checkSocket)
</del><ins>+                        remove(checkSocket)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1997,24 +1999,27 @@
</span><span class="cx"> 
</span><span class="cx">     def starting(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Called when the process is being started (or restarted). Allows for various initialization
-        operations to be done. The child process will itself signal back to the master when it is ready
-        to accept sockets - until then the master socket is marked as &quot;starting&quot; which means it is not
-        active and won't be dispatched to.
</del><ins>+        Called when the process is being started (or restarted). Allows for
+        various initialization operations to be done. The child process will
+        itself signal back to the master when it is ready to accept sockets -
+        until then the master socket is marked as &quot;starting&quot; which means it is
+        not active and won't be dispatched to.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        # Always tell any metafd socket that we have started, so it can re-initialize state.
</del><ins>+        # Always tell any metafd socket that we have started, so it can
+        # re-initialize state.
</ins><span class="cx">         if self.metaSocket is not None:
</span><span class="cx">             self.metaSocket.start()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def stopped(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Called when the process has stopped (died). The socket is marked as &quot;stopped&quot; which means it is
-        not active and won't be dispatched to.
</del><ins>+        Called when the process has stopped (died). The socket is marked as
+        &quot;stopped&quot; which means it is not active and won't be dispatched to.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        # Always tell any metafd socket that we have started, so it can re-initialize state.
</del><ins>+        # Always tell any metafd socket that we have started, so it can
+        # re-initialize state.
</ins><span class="cx">         if self.metaSocket is not None:
</span><span class="cx">             self.metaSocket.stop()
</span><span class="cx"> 
</span><span class="lines">@@ -2109,7 +2114,9 @@
</span><span class="cx"> 
</span><span class="cx">         if self.metaSocket is not None:
</span><span class="cx">             args.extend([
</span><del>-                &quot;-o&quot;, &quot;MetaFD={}&quot;.format(self.metaSocket.childSocket().fileno())
</del><ins>+                &quot;-o&quot;, &quot;MetaFD={}&quot;.format(
+                    self.metaSocket.childSocket().fileno()
+                )
</ins><span class="cx">             ])
</span><span class="cx">         if self.ampDBSocket is not None:
</span><span class="cx">             args.extend([
</span><span class="lines">@@ -2584,7 +2591,7 @@
</span><span class="cx">     if not config.SSLPrivateKey:
</span><span class="cx">         return None
</span><span class="cx"> 
</span><del>-    if config.SSLCertAdmin and os.path.isfile(config.SSLCertAdmin):
</del><ins>+    if config.SSLCertAdmin and isfile(config.SSLCertAdmin):
</ins><span class="cx">         child = Popen(
</span><span class="cx">             args=[
</span><span class="cx">                 &quot;sudo&quot;, config.SSLCertAdmin,
</span><span class="lines">@@ -2607,7 +2614,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (
</span><span class="cx">         config.SSLPassPhraseDialog and
</span><del>-        os.path.isfile(config.SSLPassPhraseDialog)
</del><ins>+        isfile(config.SSLPassPhraseDialog)
</ins><span class="cx">     ):
</span><span class="cx">         sslPrivKey = open(config.SSLPrivateKey)
</span><span class="cx">         try:
</span></span></pre>
</div>
</div>

</body>
</html>