<!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>[12687] CalendarServer/trunk/txdav/who/groups.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/12687">12687</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-02-12 18:38:16 -0800 (Wed, 12 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Stop with the % formatting.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavwhogroupspy">CalendarServer/trunk/txdav/who/groups.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/groups.py (12686 => 12687)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/groups.py        2014-02-13 02:37:05 UTC (rev 12686)
+++ CalendarServer/trunk/txdav/who/groups.py        2014-02-13 02:38:16 UTC (rev 12687)
</span><span class="lines">@@ -58,7 +58,9 @@
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><span class="cx">                 datetime.timedelta(seconds=oldGroupCacher.updateSeconds)
</span><span class="cx">             )
</span><del>-            log.debug(&quot;Scheduling next group cacher update: %s&quot; % (notBefore,))
</del><ins>+            log.debug(
+                &quot;Scheduling next group cacher update: {when}&quot;, when=notBefore
+            )
</ins><span class="cx">             yield self.transaction.enqueue(
</span><span class="cx">                 GroupCacherPollingWork,
</span><span class="cx">                 notBefore=notBefore
</span><span class="lines">@@ -68,20 +70,28 @@
</span><span class="cx">             try:
</span><span class="cx">                 newGroupCacher.update(self.transaction)
</span><span class="cx">             except Exception, e:
</span><del>-                log.error(&quot;Failed to update new group membership cache (%s)&quot; % (e,))
</del><ins>+                log.error(
+                    &quot;Failed to update new group membership cache ({error})&quot;,
+                    error=e
+                )
</ins><span class="cx"> 
</span><span class="cx">             # Old implmementation
</span><span class="cx">             try:
</span><span class="cx">                 oldGroupCacher.updateCache()
</span><span class="cx">             except Exception, e:
</span><del>-                log.error(&quot;Failed to update old group membership cache (%s)&quot; % (e,))
</del><ins>+                log.error(
+                    &quot;Failed to update old group membership cache ({error})&quot;,
+                    error=e
+                )
</ins><span class="cx"> 
</span><span class="cx">         else:
</span><span class="cx">             notBefore = (
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><span class="cx">                 datetime.timedelta(seconds=10)
</span><span class="cx">             )
</span><del>-            log.debug(&quot;Rescheduling group cacher update: %s&quot; % (notBefore,))
</del><ins>+            log.debug(
+                &quot;Rescheduling group cacher update: {when}&quot;, when=notBefore
+            )
</ins><span class="cx">             yield self.transaction.enqueue(
</span><span class="cx">                 GroupCacherPollingWork,
</span><span class="cx">                 notBefore=notBefore
</span><span class="lines">@@ -92,8 +102,12 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def scheduleNextGroupCachingUpdate(store, seconds):
</span><span class="cx">     txn = store.newTransaction()
</span><del>-    notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds)
-    log.debug(&quot;Scheduling next group cacher update: %s&quot; % (notBefore,))
</del><ins>+    notBefore = (
+        datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds)
+    )
+    log.debug(
+        &quot;Scheduling next group cacher update: {when}&quot;, when=notBefore
+    )
</ins><span class="cx">     wp = (yield txn.enqueue(GroupCacherPollingWork, notBefore=notBefore))
</span><span class="cx">     yield txn.commit()
</span><span class="cx">     returnValue(wp)
</span><span class="lines">@@ -102,8 +116,8 @@
</span><span class="cx"> 
</span><span class="cx"> def schedulePolledGroupCachingUpdate(store):
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    Schedules a group caching update work item in &quot;the past&quot; so PeerConnectionPool's
-    overdue-item logic picks it up quickly.
</del><ins>+    Schedules a group caching update work item in &quot;the past&quot; so
+    PeerConnectionPool's overdue-item logic picks it up quickly.
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     seconds = -PeerConnectionPool.queueProcessTimeout
</span><span class="cx">     return scheduleNextGroupCachingUpdate(store, seconds)
</span><span class="lines">@@ -118,7 +132,9 @@
</span><span class="cx">     def doWork(self):
</span><span class="cx"> 
</span><span class="cx">         # Delete all other work items for this group
</span><del>-        yield Delete(From=self.table, Where=(self.table.GROUP_GUID == self.groupGUID)).on(self.transaction)
</del><ins>+        yield Delete(
+            From=self.table, Where=(self.table.GROUP_GUID == self.groupGUID)
+        ).on(self.transaction)
</ins><span class="cx"> 
</span><span class="cx">         groupCacher = getattr(self.transaction, &quot;_groupCacher&quot;, None)
</span><span class="cx">         if groupCacher is not None:
</span><span class="lines">@@ -147,9 +163,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class GroupAttendeeReconciliationWork(WorkItem, fromTable(schema.GROUP_ATTENDEE_RECONCILIATION_WORK)):
</del><ins>+class GroupAttendeeReconciliationWork(
+    WorkItem, fromTable(schema.GROUP_ATTENDEE_RECONCILIATION_WORK)
+):
</ins><span class="cx"> 
</span><del>-    group = property(lambda self: &quot;%s, %s&quot; % (self.groupID, self.eventID))
</del><ins>+    group = property(
+        lambda self: &quot;{0}, {1}&quot;.format(self.groupID, self.eventID)
+    )
</ins><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def doWork(self):
</span><span class="lines">@@ -168,8 +188,8 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def expandedMembers(record, members=None, records=None):
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    Return the expanded set of member records.  Intermediate groups are not returned
-    in the results, but their members are.
</del><ins>+    Return the expanded set of member records.  Intermediate groups are not
+    returned in the results, but their members are.
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     if members is None:
</span><span class="cx">         members = set()
</span><span class="lines">@@ -181,7 +201,10 @@
</span><span class="cx">         for member in (yield record.members()):
</span><span class="cx">             if member not in records:
</span><span class="cx">                 #TODO:  HACK for old-style XML. FIX
</span><del>-                if member.recordType != RecordType.group and str(member.recordType) != &quot;groups&quot;:
</del><ins>+                if (
+                    member.recordType != RecordType.group and
+                    str(member.recordType) != &quot;groups&quot;
+                ):
</ins><span class="cx">                     members.add(member)
</span><span class="cx">                 yield expandedMembers(member, members, records)
</span><span class="cx"> 
</span><span class="lines">@@ -190,12 +213,16 @@
</span><span class="cx"> 
</span><span class="cx"> def diffAssignments(old, new):
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    Compare two proxy assignment lists and return their differences in the form of
-    two lists -- one for added/updated assignments, and one for removed assignments.
</del><ins>+    Compare two proxy assignment lists and return their differences in the form
+    of two lists -- one for added/updated assignments, and one for removed
+    assignments.
+
</ins><span class="cx">     @param old: dictionary of delegator: (readGroupGUID, writeGroupGUID)
</span><span class="cx">     @type old: C{dict}
</span><ins>+
</ins><span class="cx">     @param new: dictionary of delegator: (readGroupGUID, writeGroupGUID)
</span><span class="cx">     @type new: C{dict}
</span><ins>+
</ins><span class="cx">     @return: Tuple of two lists; the first list contains tuples of (delegator,
</span><span class="cx">         (readGroupGUID, writeGroupGUID)), and represents all the new or updated
</span><span class="cx">         assignments.  The second list contains all the delegators which used to
</span><span class="lines">@@ -219,6 +246,7 @@
</span><span class="cx"> class GroupCacher(object):
</span><span class="cx">     log = Logger()
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def __init__(
</span><span class="cx">         self, directory,
</span><span class="cx">         useExternalProxies=False, externalProxiesSource=None
</span><span class="lines">@@ -242,7 +270,7 @@
</span><span class="cx">         # Figure out which groups matter
</span><span class="cx">         groupGUIDs = yield self.groupsToRefresh(txn)
</span><span class="cx">         self.log.debug(
</span><del>-            &quot;Number of groups to refresh: {num}&quot;.format(num=len(groupGUIDs))
</del><ins>+            &quot;Number of groups to refresh: {num}&quot;, num=len(groupGUIDs)
</ins><span class="cx">         )
</span><span class="cx">         # For each of those groups, create a per-group refresh work item
</span><span class="cx">         for groupGUID in groupGUIDs:
</span><span class="lines">@@ -260,15 +288,15 @@
</span><span class="cx"> 
</span><span class="cx">         oldAssignments = (yield txn.externalDelegates())
</span><span class="cx"> 
</span><del>-        &quot;&quot;&quot;
-        external assignments is of the form:
-        { delegatorGUID: (readDelegateGroupGUID, writeDelegateGroupGUID),
-        }
-        &quot;&quot;&quot;
</del><ins>+        # external assignments is of the form:
+        # { delegatorGUID: (readDelegateGroupGUID, writeDelegateGroupGUID),
+        # }
</ins><span class="cx"> 
</span><span class="cx">         changed, removed = diffAssignments(oldAssignments, newAssignments)
</span><span class="cx">         if changed:
</span><del>-            for delegatorGUID, (readDelegateGUID, writeDelegateGUID) in changed:
</del><ins>+            for (
+                delegatorGUID, (readDelegateGUID, writeDelegateGUID)
+            ) in changed:
</ins><span class="cx">                 readDelegateGroupID = writeDelegateGroupID  = None
</span><span class="cx">                 if readDelegateGUID:
</span><span class="cx">                     readDelegateGroupID, name, hash = (
</span><span class="lines">@@ -309,7 +337,9 @@
</span><span class="cx"> 
</span><span class="cx">         if cachedMembershipHash != membershipHash:
</span><span class="cx">             membershipChanged = True
</span><del>-            self.log.debug(&quot;Group '{group}' changed&quot;, group=record.fullNames[0])
</del><ins>+            self.log.debug(
+                &quot;Group '{group}' changed&quot;, group=record.fullNames[0]
+            )
</ins><span class="cx">         else:
</span><span class="cx">             membershipChanged = False
</span><span class="cx"> 
</span><span class="lines">@@ -384,7 +414,8 @@
</span><span class="cx">                 datetime.timedelta(seconds=10)
</span><span class="cx">             )
</span><span class="cx">             log.debug(
</span><del>-                &quot;scheduling group reconciliation for ({eventID}, {groupID}, {groupGUID}): {when}&quot;,
</del><ins>+                &quot;scheduling group reconciliation for &quot;
+                &quot;({eventID}, {groupID}, {groupGUID}): {when}&quot;,
</ins><span class="cx">                 eventID=eventID,
</span><span class="cx">                 groupID=groupID,
</span><span class="cx">                 groupGUID=groupGUID,
</span><span class="lines">@@ -402,7 +433,9 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def groupsToRefresh(self, txn):
</span><span class="cx">         delegatedGUIDs = set((yield allGroupDelegates(txn)))
</span><del>-        self.log.info(&quot;There are %d group delegates&quot; % (len(delegatedGUIDs),))
</del><ins>+        self.log.info(
+            &quot;There are {count} group delegates&quot;, count=len(delegatedGUIDs)
+        )
</ins><span class="cx"> 
</span><span class="cx">         attendeeGroupGUIDs = set()
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>