<!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>[15396] twext/trunk/twext/enterprise/dal/model.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/15396">15396</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-12-15 09:14:26 -0800 (Tue, 15 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Tweak schema compare output to be a little clearer on the differences.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#twexttrunktwextenterprisedalmodelpy">twext/trunk/twext/enterprise/dal/model.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="twexttrunktwextenterprisedalmodelpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/enterprise/dal/model.py (15395 => 15396)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/enterprise/dal/model.py        2015-12-15 15:40:57 UTC (rev 15395)
+++ twext/trunk/twext/enterprise/dal/model.py        2015-12-15 17:14:26 UTC (rev 15396)
</span><span class="lines">@@ -81,11 +81,8 @@
</span><span class="cx">         A useful string representation which includes the name and length if
</span><span class="cx">         present.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        if self.length:
-            lendesc = &quot;(%s)&quot; % (self.length)
-        else:
-            lendesc = &quot;&quot;
-        return &quot;&lt;SQL Type: %r%s&gt;&quot; % (self.name, lendesc)
</del><ins>+        lendesc = &quot;({})&quot;.format(self.length) if self.length else &quot;&quot;
+        return &quot;&lt;SQL Type: {}{}&gt;&quot;.format(self.name, lendesc)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def normalizedName(self):
</span><span class="lines">@@ -193,7 +190,7 @@
</span><span class="cx">     prevent pollution with unicode values.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     if not isinstance(x, str):
</span><del>-        raise ValueError(&quot;%r is not a str.&quot; % (x,))
</del><ins>+        raise ValueError(&quot;{!r} is not a str.&quot;.format(x,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -251,7 +248,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><del>-        return &quot;&lt;Column (%s %r)&gt;&quot; % (self.name, self.type)
</del><ins>+        return &quot;&lt;Column ({} {!r})&gt;&quot;.format(self.name, self.type)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def compare(self, other):
</span><span class="lines">@@ -265,9 +262,9 @@
</span><span class="cx">         results = []
</span><span class="cx"> 
</span><span class="cx">         if self.name != other.name:
</span><del>-            results.append(&quot;Table: %s, column names %s and %s do not match&quot; % (self.table.name, self.name, other.name,))
</del><ins>+            results.append(&quot;Table: {}, column names {} and {} do not match&quot;.format(self.table.name, self.name, other.name,))
</ins><span class="cx">         if self.type != other.type:
</span><del>-            results.append(&quot;Table: %s, column name %s type mismatch&quot; % (self.table.name, self.name,))
</del><ins>+            results.append(&quot;Table: {}, column name {} type mismatch&quot;.format(self.table.name, self.name,))
</ins><span class="cx">         if self.default != other.default:
</span><span class="cx">             # Some DBs don't allow sequence as a default
</span><span class="cx">             if (
</span><span class="lines">@@ -278,11 +275,11 @@
</span><span class="cx">             ):
</span><span class="cx">                 pass
</span><span class="cx">             else:
</span><del>-                results.append(&quot;Table: %s, column name %s default mismatch&quot; % (self.table.name, self.name,))
</del><ins>+                results.append(&quot;Table: {}, column name {} default mismatch&quot;.format(self.table.name, self.name,))
</ins><span class="cx">         if stringIfNone(self.references, &quot;name&quot;) != stringIfNone(other.references, &quot;name&quot;):
</span><del>-            results.append(&quot;Table: %s, column name %s references mismatch&quot; % (self.table.name, self.name,))
</del><ins>+            results.append(&quot;Table: {}, column name {} references mismatch&quot;.format(self.table.name, self.name,))
</ins><span class="cx">         if stringIfNone(self.deleteAction, &quot;&quot;) != stringIfNone(other.deleteAction, &quot;&quot;):
</span><del>-            results.append(&quot;Table: %s, column name %s delete action mismatch&quot; % (self.table.name, self.name,))
</del><ins>+            results.append(&quot;Table: {}, column name {} delete action mismatch&quot;.format(self.table.name, self.name,))
</ins><span class="cx">         return results
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -364,7 +361,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><del>-        return &quot;&lt;Table %r:%r&gt;&quot; % (self.name, self.columns)
</del><ins>+        return &quot;&lt;Table {}:{!r}&gt;&quot;.format(self.name, self.columns)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def compare(self, other):
</span><span class="lines">@@ -383,11 +380,11 @@
</span><span class="cx">         ])
</span><span class="cx">         for item in set(myColumns.keys()) - set(otherColumns.keys()):
</span><span class="cx">             results.append(
</span><del>-                &quot;Table: %s, extra column: %s&quot; % (self.name, myColumns[item].name,)
</del><ins>+                &quot;Table: {}, extra column: {}&quot;.format(self.name, myColumns[item].name,)
</ins><span class="cx">             )
</span><span class="cx">         for item in set(otherColumns.keys()) - set(myColumns.keys()):
</span><span class="cx">             results.append(
</span><del>-                &quot;Table: %s, missing column: %s&quot; % (self.name, otherColumns[item].name,)
</del><ins>+                &quot;Table: {}, missing column: {}&quot;.format(self.name, otherColumns[item].name,)
</ins><span class="cx">             )
</span><span class="cx"> 
</span><span class="cx">         for name in set(myColumns.keys()) &amp; set(otherColumns.keys()):
</span><span class="lines">@@ -397,19 +394,19 @@
</span><span class="cx">             listIfNone(self.primaryKey),
</span><span class="cx">             listIfNone(other.primaryKey),
</span><span class="cx">         )]):
</span><del>-            results.append(&quot;Table: %s, mismatched primary key&quot; % (self.name,))
</del><ins>+            results.append(&quot;Table: {}, mismatched primary key&quot;.format(self.name,))
</ins><span class="cx"> 
</span><span class="cx">         for myRow, otherRow in zip(self.schemaRows, other.schemaRows):
</span><span class="cx">             myRows = dict([(column.name, value) for column, value in myRow.items()])
</span><span class="cx">             otherRows = dict([(column.name, value) for column, value in otherRow.items()])
</span><span class="cx">             if myRows != otherRows:
</span><del>-                results.append(&quot;Table: %s, mismatched schema rows: %s&quot; % (self.name, myRows))
</del><ins>+                results.append(&quot;Table: {}, mismatched schema rows: {}&quot;.format(self.name, myRows))
</ins><span class="cx"> 
</span><span class="cx">         # Compare psuedo-constraints - ones which include implicit primary key and unique
</span><span class="cx">         # index items.
</span><span class="cx">         diff_constraints = set(self.pseudoConstraints()) ^ set(other.pseudoConstraints())
</span><span class="cx">         if diff_constraints:
</span><del>-            results.append(&quot;Table: %s, mismatched constraints: %s&quot; % (self.name, diff_constraints))
</del><ins>+            results.append(&quot;Table: {}, mismatched constraints: {}&quot;.format(self.name, diff_constraints))
</ins><span class="cx"> 
</span><span class="cx">         return results
</span><span class="cx"> 
</span><span class="lines">@@ -427,7 +424,7 @@
</span><span class="cx">         for column in self.columns:
</span><span class="cx">             if column.name == name:
</span><span class="cx">                 return column
</span><del>-        raise KeyError(&quot;no such column: %r&quot; % (name,))
</del><ins>+        raise KeyError(&quot;no such column: {}&quot;.format(name,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def addColumn(self, name, type, default=NO_DEFAULT, notNull=False, primaryKey=False):
</span><span class="lines">@@ -572,8 +569,9 @@
</span><span class="cx">     def __init__(self, name, table, columns, index_type=&quot;&quot;):
</span><span class="cx"> 
</span><span class="cx">         self.name = (
</span><del>-            &quot;%s:%s:(%s)&quot;
-            % (table.name, index_type, &quot;,&quot;.join([col.name for col in columns]))
</del><ins>+            &quot;{}:{}:({})&quot;.format(
+                table.name, index_type, &quot;,&quot;.join([col.name for col in columns])
+            )
</ins><span class="cx">         )
</span><span class="cx">         self.original_name = name if name else self.name
</span><span class="cx">         self.table = table
</span><span class="lines">@@ -598,11 +596,11 @@
</span><span class="cx">         ])
</span><span class="cx">         for item in set(myColumns.keys()) - set(otherColumns.keys()):
</span><span class="cx">             results.append(
</span><del>-                &quot;Index: %s, extra column: %s&quot; % (self.original_name, myColumns[item].name,)
</del><ins>+                &quot;Index: {}, extra column: {}&quot;.format(self.original_name, myColumns[item].name,)
</ins><span class="cx">             )
</span><span class="cx">         for item in set(otherColumns.keys()) - set(myColumns.keys()):
</span><span class="cx">             results.append(
</span><del>-                &quot;Index: %s, missing column: %s&quot; % (self.original_name, otherColumns[item].name,)
</del><ins>+                &quot;Index: {}, missing column: {}&quot;.format(self.original_name, otherColumns[item].name,)
</ins><span class="cx">             )
</span><span class="cx"> 
</span><span class="cx">         return results
</span><span class="lines">@@ -624,7 +622,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><del>-        return &quot;&lt;Sequence %r&gt;&quot; % (self.name,)
</del><ins>+        return &quot;&lt;Sequence {}&gt;&quot;.format(self.name,)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def compare(self, other):
</span><span class="lines">@@ -654,7 +652,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><del>-        return &quot;&lt;Function %r&gt;&quot; % (self.name,)
</del><ins>+        return &quot;&lt;Function {}&gt;&quot;.format(self.name,)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def compare(self, other):
</span><span class="lines">@@ -696,7 +694,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><del>-        return &quot;&lt;Schema %r&gt;&quot; % (self.filename,)
</del><ins>+        return &quot;&lt;Schema {}&gt;&quot;.format(self.filename,)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def compare(self, other):
</span><span class="lines">@@ -721,13 +719,11 @@
</span><span class="cx">             ])
</span><span class="cx">             for item in set(myItems.keys()) - set(otherItems.keys()):
</span><span class="cx">                 results.append(
</span><del>-                    &quot;Schema: %s, extra %s: %s&quot;
-                    % (other.filename, descriptor, myItems[item].name)
</del><ins>+                    &quot;Schema: extra {}: {}&quot;.format(descriptor, myItems[item].name,)
</ins><span class="cx">                 )
</span><span class="cx">             for item in set(otherItems.keys()) - set(myItems.keys()):
</span><span class="cx">                 results.append(
</span><del>-                    &quot;Schema: %s, missing %s: %s&quot;
-                    % (self.filename, descriptor, otherItems[item].name)
</del><ins>+                    &quot;Schema: missing {}: {}&quot;.format(descriptor, otherItems[item].name,)
</ins><span class="cx">                 )
</span><span class="cx"> 
</span><span class="cx">             for name in set(myItems.keys()) &amp; set(otherItems.keys()):
</span><span class="lines">@@ -738,6 +734,8 @@
</span><span class="cx">         _compareLists(self.sequences, other.sequences, &quot;sequence&quot;, lowerTruncateName)
</span><span class="cx">         _compareLists(self.functions, other.functions, &quot;functions&quot;, lowerTruncateName)
</span><span class="cx"> 
</span><ins>+        if results:
+            results.insert(0, &quot;Comparing schema: {} to {}&quot;.format(self.filename, other.filename,))
</ins><span class="cx">         return results
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>