<!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>[117046] trunk/base/src</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="https://trac.macports.org/changeset/117046">117046</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2014-02-13 14:14:24 -0800 (Thu, 13 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>rev-upgrade: use new fancy progress bars</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbasesrcmacports10macportstcl">trunk/base/src/macports1.0/macports.tcl</a></li>
<li><a href="#trunkbasesrcportporttcl">trunk/base/src/port/port.tcl</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbasesrcmacports10macportstcl"></a>
<div class="modfile"><h4>Modified: trunk/base/src/macports1.0/macports.tcl (117045 => 117046)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/macports1.0/macports.tcl        2014-02-13 21:47:32 UTC (rev 117045)
+++ trunk/base/src/macports1.0/macports.tcl        2014-02-13 22:14:24 UTC (rev 117046)
</span><span class="lines">@@ -4351,17 +4351,22 @@
</span><span class="cx"> 
</span><span class="cx">     set files [registry::file search active 1 binary -null]
</span><span class="cx">     set files_count [llength $files]
</span><del>-    set fancy_output [expr {![macports::ui_isset ports_debug] &amp;&amp; [isatty stdout]}]
</del><ins>+    set fancy_output [expr {![macports::ui_isset ports_debug] &amp;&amp; [info exists macports::ui_options(progress_generic)]}]
+    if {$fancy_output} {
+        set revupgrade_progress $macports::ui_options(progress_generic)
+    }
</ins><span class="cx">     if {$files_count &gt; 0} {
</span><span class="cx">         registry::write {
</span><span class="cx">             try {
</span><del>-                ui_msg -nonewline &quot;$macports::ui_prefix Updating database of binaries&quot;
</del><ins>+                ui_msg &quot;$macports::ui_prefix Updating database of binaries&quot;
</ins><span class="cx">                 set i 1
</span><ins>+                if {$fancy_output} {
+                    $revupgrade_progress start
+                }
</ins><span class="cx">                 foreach f $files {
</span><span class="cx">                     if {$fancy_output} {
</span><del>-                        if {$files_count &lt; 10000 || $i % 10 == 1 || $i == $files_count} {
-                            ui_msg -nonewline &quot;\r$macports::ui_prefix Updating database of binaries: [expr {($i * 1000 / $files_count) / 10.0}]%&quot;
-                            flush stdout
</del><ins>+                        if {$files_count &lt; 10000 || $i % 10 == 1} {
+                            $revupgrade_progress update $i $files_count
</ins><span class="cx">                         }
</span><span class="cx">                     }
</span><span class="cx">                     set fpath [$f actual_path]
</span><span class="lines">@@ -4371,7 +4376,7 @@
</span><span class="cx">                     if {0 != [catch {$f binary [fileIsBinary $fpath]} fileIsBinaryError]} {
</span><span class="cx">                         # handle errors (e.g. file not found, permission denied) gracefully
</span><span class="cx">                         if {$fancy_output} {
</span><del>-                            ui_msg {}
</del><ins>+                            $revupgrade_progress intermission
</ins><span class="cx">                         }
</span><span class="cx">                         ui_warn &quot;Error determining file type of `$fpath': $fileIsBinaryError&quot;
</span><span class="cx">                         ui_warn &quot;A file belonging to the `[[registry::entry owner $fpath] name]' port is missing or unreadable. Consider reinstalling it.&quot;
</span><span class="lines">@@ -4382,14 +4387,16 @@
</span><span class="cx">                 throw
</span><span class="cx">             }
</span><span class="cx">         }
</span><del>-        ui_msg {}
</del><ins>+        if {$fancy_output} {
+            $revupgrade_progress finish
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     set broken_files {};
</span><span class="cx">     set binaries [registry::file search active 1 binary 1]
</span><span class="cx">     set binary_count [llength $binaries]
</span><span class="cx">     if {$binary_count &gt; 0} {
</span><del>-        ui_msg -nonewline &quot;$macports::ui_prefix Scanning binaries for linking errors&quot;
</del><ins>+        ui_msg &quot;$macports::ui_prefix Scanning binaries for linking errors&quot;
</ins><span class="cx">         set handle [machista::create_handle]
</span><span class="cx">         if {$handle eq {NULL}} {
</span><span class="cx">             error &quot;Error creating libmachista handle&quot;
</span><span class="lines">@@ -4397,12 +4404,15 @@
</span><span class="cx">         array unset files_warned_about
</span><span class="cx">         array set files_warned_about [list]
</span><span class="cx"> 
</span><ins>+        if {$fancy_output} {
+            $revupgrade_progress start
+        }
+
</ins><span class="cx">         set i 1
</span><span class="cx">         foreach b $binaries {
</span><span class="cx">             if {$fancy_output} {
</span><del>-                if {$binary_count &lt; 10000 || $i % 10 == 1 || $i == $binary_count} {
-                    ui_msg -nonewline &quot;\r$macports::ui_prefix Scanning binaries for linking errors: [expr {($i * 1000 / $binary_count) / 10.0}]%&quot;
-                    flush stdout
</del><ins>+                if {$binary_count &lt; 10000 || $i % 10 == 1} {
+                    $revupgrade_progress update $i $binary_count
</ins><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">             set bpath [$b actual_path]
</span><span class="lines">@@ -4420,7 +4430,7 @@
</span><span class="cx">                     #ui_debug &quot;Error parsing file ${bpath}: [machista::strerror $returncode]&quot;
</span><span class="cx">                 } else {
</span><span class="cx">                     if {$fancy_output} {
</span><del>-                        ui_msg {}
</del><ins>+                        $revupgrade_progress intermission
</ins><span class="cx">                     }
</span><span class="cx">                     ui_warn &quot;Error parsing file ${bpath}: [machista::strerror $returncode]&quot;
</span><span class="cx">                 }
</span><span class="lines">@@ -4442,7 +4452,7 @@
</span><span class="cx">                                     set portname &lt;unknown-port&gt;
</span><span class="cx">                                 }
</span><span class="cx">                                 if {$fancy_output} {
</span><del>-                                    ui_msg {}
</del><ins>+                                    $revupgrade_progress intermission
</ins><span class="cx">                                 }
</span><span class="cx">                                 ui_warn &quot;ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path&quot;
</span><span class="cx">                             } elseif {![file exists $idloadcmdpath]} {
</span><span class="lines">@@ -4453,7 +4463,7 @@
</span><span class="cx">                                     set portname &lt;unknown-port&gt;
</span><span class="cx">                                 }
</span><span class="cx">                                 if {$fancy_output} {
</span><del>-                                    ui_msg {}
</del><ins>+                                    $revupgrade_progress intermission
</ins><span class="cx">                                 }
</span><span class="cx">                                 ui_warn &quot;ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath&quot;
</span><span class="cx">                                 ui_warn &quot;This is probably a bug in the $portname port and might cause problems in libraries linking against this file&quot;
</span><span class="lines">@@ -4470,7 +4480,7 @@
</span><span class="cx">                                         set portname &lt;unknown-port&gt;
</span><span class="cx">                                     }
</span><span class="cx">                                     if {$fancy_output} {
</span><del>-                                        ui_msg {}
</del><ins>+                                        $revupgrade_progress intermission
</ins><span class="cx">                                     }
</span><span class="cx">                                     ui_warn &quot;ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file ${idloadcmdpath}, which is a different file&quot;
</span><span class="cx">                                     ui_warn &quot;This is probably a bug in the $portname port and might cause problems in libraries linking against this file&quot;
</span><span class="lines">@@ -4499,7 +4509,7 @@
</span><span class="cx">                         (${filepath} == &quot;/usr/lib/libc++.1.dylib&quot; &amp;&amp; ${macports::cxx_stdlib} == &quot;libstdc++&quot;)} {
</span><span class="cx"> 
</span><span class="cx">                         if {$fancy_output} {
</span><del>-                            ui_msg {}
</del><ins>+                            $revupgrade_progress intermission
</ins><span class="cx">                         }
</span><span class="cx">                         ui_warn &quot;${bpath} uses ${filepath} as C++ standard library although macports::cxx_stdlib is set to ${macports::cxx_stdlib}.&quot;
</span><span class="cx">                     }
</span><span class="lines">@@ -4510,8 +4520,8 @@
</span><span class="cx"> 
</span><span class="cx">                     if {$libreturncode != $machista::SUCCESS} {
</span><span class="cx">                         if {![info exists files_warned_about($filepath)]} {
</span><del>-                            if {[macports::ui_isset ports_verbose]} {
-                                ui_msg {}
</del><ins>+                            if {$fancy_output} {
+                                $revupgrade_progress intermission
</ins><span class="cx">                             }
</span><span class="cx">                             ui_info &quot;Could not open ${filepath}: [machista::strerror $libreturncode] (referenced from $bpath)&quot;
</span><span class="cx">                             set files_warned_about($filepath) yes
</span><span class="lines">@@ -4533,8 +4543,8 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         if {[$loadcommand cget -mlt_version] ne [$libarchitecture cget -mat_version] &amp;&amp; [$loadcommand cget -mlt_comp_version] &gt; [$libarchitecture cget -mat_comp_version]} {
</span><del>-                            if {[macports::ui_isset ports_verbose]} {
-                                ui_msg {}
</del><ins>+                            if {$fancy_output} {
+                                $revupgrade_progress intermission
</ins><span class="cx">                             }
</span><span class="cx">                             ui_info &quot;Incompatible library version: $bpath requires version [machista::format_dylib_version [$loadcommand cget -mlt_comp_version]] or later, but $filepath provides version [machista::format_dylib_version [$libarchitecture cget -mat_comp_version]]&quot;
</span><span class="cx">                             ui_debug &quot;Marking $bpath as broken&quot;
</span><span class="lines">@@ -4561,7 +4571,9 @@
</span><span class="cx">                 set architecture [$architecture cget -next]
</span><span class="cx">             }
</span><span class="cx">         }
</span><del>-        ui_msg {}
</del><ins>+        if {$fancy_output} {
+            $revupgrade_progress finish
+        }
</ins><span class="cx"> 
</span><span class="cx">         machista::destroy_handle $handle
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbasesrcportporttcl"></a>
<div class="modfile"><h4>Modified: trunk/base/src/port/port.tcl (117045 => 117046)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/port/port.tcl        2014-02-13 21:47:32 UTC (rev 117045)
+++ trunk/base/src/port/port.tcl        2014-02-13 22:14:24 UTC (rev 117046)
</span><span class="lines">@@ -4790,13 +4790,72 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ##
</span><ins>+# Progress callback for generic operations executed by macports 1.0.
+#
+# @param action
+#        One of &quot;start&quot;, &quot;update&quot;, &quot;intermission&quot; or &quot;finish&quot;, where start will
+#        be called before any number of update calls, interrupted by any number
+#        of intermission calls (called because other output is being produced),
+#        followed by one call to finish.
+# @param args
+#        A list of variadic args that differ for each action.
+#        For &quot;start&quot;: empty.
+#        For &quot;update&quot;: contains the arguments $cur and $total where $cur is the
+#        current number of units processed and $total is the total number of
+#        units to be processed.
+#        For &quot;intermission&quot;: empty.
+#        For &quot;finish&quot;: empty.
+proc port_progress_generic {action args} {
+    global _port_progress_starttime _port_progress_display_bar
+    switch -nocase -- $action {
+        start {
+            set _port_progress_starttime [clock milliseconds]
+            set _port_progress_display_bar no
+        }
+        update {
+            # the for loop is a simple hack because Tcl 8.4 doesn't have
+            # lassign
+            foreach {now total} $args {
+                if {${_port_progress_display_bar} ne yes} {
+                    # check whether we should show a progress bar for this transfer
+                    if {[expr {[clock milliseconds] - ${_port_progress_starttime}}] &gt; 500 &amp;&amp; ($total == 0 || [expr {$now / $total}] &lt; 0.5)} {
+                        # wait 500ms, then, if we don't know the total or we're
+                        # not past 50% yet, display a progress bar.
+                        set _port_progress_display_bar yes
+                    }
+                }
+                if {${_port_progress_display_bar} eq yes} {
+                    set barprefix &quot;      &quot;
+                    if {$total != 0} {
+                        progress_bar $now $total 20 $barprefix
+                    } else {
+                        unprogress_bar $now 20 $barprefix
+                    }
+                }
+            }
+        }
+        intermission -
+        finish {
+            # erase to start of line
+            ::term::ansi::send::esol
+            # return cursor to start of line
+            puts -nonewline &quot;\r&quot;
+            flush stdout
+        }
+    }
+
+    return 0
+}
+
+
+##
</ins><span class="cx"> # Progress callback for downloads executed by macports 1.0.
</span><span class="cx"> #
</span><span class="cx"> # This is essentially a cURL progress callback.
</span><span class="cx"> #
</span><span class="cx"> # @param action
</span><span class="cx"> #        One of &quot;start&quot;, &quot;update&quot; or &quot;finish&quot;, where start will be called
</span><del>-#        before any number of change calls, followed by one call to finish.
</del><ins>+#        before any number of update calls, followed by one call to finish.
</ins><span class="cx"> # @param args
</span><span class="cx"> #        A list of variadic args that differ for each action.
</span><span class="cx"> #        For &quot;start&quot;: contains a single argument &quot;ul&quot; or &quot;dl&quot; indicating
</span><span class="lines">@@ -4826,7 +4885,7 @@
</span><span class="cx">                     }
</span><span class="cx">                 }
</span><span class="cx">                 if {${_port_progress_display_bar} eq yes} {
</span><del>-                    set barprefix &quot;     &quot;
</del><ins>+                    set barprefix &quot;      &quot;
</ins><span class="cx">                     if {$total != 0} {
</span><span class="cx">                         set barsuffix [format &quot;        speed: %-13s&quot; &quot;[bytesize $speed {} &quot;%.1f&quot;]/s&quot;]
</span><span class="cx">                         progress_bar $now $total 20 $barprefix $barsuffix
</span><span class="lines">@@ -4865,7 +4924,7 @@
</span><span class="cx"> proc progress_bar {current total halfwidth {prefix &quot;&quot;} {suffix &quot;&quot;}} {
</span><span class="cx">     # we use 8 different states per character, so let's multiply the width by
</span><span class="cx">     # 8 and map the percentage to this range
</span><del>-    set percent [expr {($current * 100 / $total)}]
</del><ins>+    set percent [expr {(double($current) * 100 / double($total))}]
</ins><span class="cx">     set progress [expr {int(round(($current * $halfwidth * 8) / $total))}]
</span><span class="cx">     set fullfields [expr {int($progress / 8)}]
</span><span class="cx">     set remainder [expr {$progress % 8}]
</span><span class="lines">@@ -5002,6 +5061,7 @@
</span><span class="cx"> 
</span><span class="cx"> if {[isatty stdout] &amp;&amp; (![info exists ui_options(ports_quiet)] || $ui_options(ports_quiet) ne &quot;yes&quot;)} {
</span><span class="cx">     set ui_options(progress_download) port_progress_download
</span><ins>+    set ui_options(progress_generic)  port_progress_generic
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # Get arguments remaining after option processing
</span></span></pre>
</div>
</div>

</body>
</html>