[117046] trunk/base/src

cal at macports.org cal at macports.org
Thu Feb 13 14:14:24 PST 2014


Revision: 117046
          https://trac.macports.org/changeset/117046
Author:   cal at macports.org
Date:     2014-02-13 14:14:24 -0800 (Thu, 13 Feb 2014)
Log Message:
-----------
rev-upgrade: use new fancy progress bars

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/port/port.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- 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)
@@ -4351,17 +4351,22 @@
 
     set files [registry::file search active 1 binary -null]
     set files_count [llength $files]
-    set fancy_output [expr {![macports::ui_isset ports_debug] && [isatty stdout]}]
+    set fancy_output [expr {![macports::ui_isset ports_debug] && [info exists macports::ui_options(progress_generic)]}]
+    if {$fancy_output} {
+        set revupgrade_progress $macports::ui_options(progress_generic)
+    }
     if {$files_count > 0} {
         registry::write {
             try {
-                ui_msg -nonewline "$macports::ui_prefix Updating database of binaries"
+                ui_msg "$macports::ui_prefix Updating database of binaries"
                 set i 1
+                if {$fancy_output} {
+                    $revupgrade_progress start
+                }
                 foreach f $files {
                     if {$fancy_output} {
-                        if {$files_count < 10000 || $i % 10 == 1 || $i == $files_count} {
-                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr {($i * 1000 / $files_count) / 10.0}]%"
-                            flush stdout
+                        if {$files_count < 10000 || $i % 10 == 1} {
+                            $revupgrade_progress update $i $files_count
                         }
                     }
                     set fpath [$f actual_path]
@@ -4371,7 +4376,7 @@
                     if {0 != [catch {$f binary [fileIsBinary $fpath]} fileIsBinaryError]} {
                         # handle errors (e.g. file not found, permission denied) gracefully
                         if {$fancy_output} {
-                            ui_msg {}
+                            $revupgrade_progress intermission
                         }
                         ui_warn "Error determining file type of `$fpath': $fileIsBinaryError"
                         ui_warn "A file belonging to the `[[registry::entry owner $fpath] name]' port is missing or unreadable. Consider reinstalling it."
@@ -4382,14 +4387,16 @@
                 throw
             }
         }
-        ui_msg {}
+        if {$fancy_output} {
+            $revupgrade_progress finish
+        }
     }
 
     set broken_files {};
     set binaries [registry::file search active 1 binary 1]
     set binary_count [llength $binaries]
     if {$binary_count > 0} {
-        ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
+        ui_msg "$macports::ui_prefix Scanning binaries for linking errors"
         set handle [machista::create_handle]
         if {$handle eq {NULL}} {
             error "Error creating libmachista handle"
@@ -4397,12 +4404,15 @@
         array unset files_warned_about
         array set files_warned_about [list]
 
+        if {$fancy_output} {
+            $revupgrade_progress start
+        }
+
         set i 1
         foreach b $binaries {
             if {$fancy_output} {
-                if {$binary_count < 10000 || $i % 10 == 1 || $i == $binary_count} {
-                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr {($i * 1000 / $binary_count) / 10.0}]%"
-                    flush stdout
+                if {$binary_count < 10000 || $i % 10 == 1} {
+                    $revupgrade_progress update $i $binary_count
                 }
             }
             set bpath [$b actual_path]
@@ -4420,7 +4430,7 @@
                     #ui_debug "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 } else {
                     if {$fancy_output} {
-                        ui_msg {}
+                        $revupgrade_progress intermission
                     }
                     ui_warn "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 }
@@ -4442,7 +4452,7 @@
                                     set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg {}
+                                    $revupgrade_progress intermission
                                 }
                                 ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
                             } elseif {![file exists $idloadcmdpath]} {
@@ -4453,7 +4463,7 @@
                                     set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg {}
+                                    $revupgrade_progress intermission
                                 }
                                 ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
                                 ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
@@ -4470,7 +4480,7 @@
                                         set portname <unknown-port>
                                     }
                                     if {$fancy_output} {
-                                        ui_msg {}
+                                        $revupgrade_progress intermission
                                     }
                                     ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file ${idloadcmdpath}, which is a different file"
                                     ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
@@ -4499,7 +4509,7 @@
                         (${filepath} == "/usr/lib/libc++.1.dylib" && ${macports::cxx_stdlib} == "libstdc++")} {
 
                         if {$fancy_output} {
-                            ui_msg {}
+                            $revupgrade_progress intermission
                         }
                         ui_warn "${bpath} uses ${filepath} as C++ standard library although macports::cxx_stdlib is set to ${macports::cxx_stdlib}."
                     }
@@ -4510,8 +4520,8 @@
 
                     if {$libreturncode != $machista::SUCCESS} {
                         if {![info exists files_warned_about($filepath)]} {
-                            if {[macports::ui_isset ports_verbose]} {
-                                ui_msg {}
+                            if {$fancy_output} {
+                                $revupgrade_progress intermission
                             }
                             ui_info "Could not open ${filepath}: [machista::strerror $libreturncode] (referenced from $bpath)"
                             set files_warned_about($filepath) yes
@@ -4533,8 +4543,8 @@
                         }
 
                         if {[$loadcommand cget -mlt_version] ne [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
-                            if {[macports::ui_isset ports_verbose]} {
-                                ui_msg {}
+                            if {$fancy_output} {
+                                $revupgrade_progress intermission
                             }
                             ui_info "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]]"
                             ui_debug "Marking $bpath as broken"
@@ -4561,7 +4571,9 @@
                 set architecture [$architecture cget -next]
             }
         }
-        ui_msg {}
+        if {$fancy_output} {
+            $revupgrade_progress finish
+        }
 
         machista::destroy_handle $handle
 

Modified: trunk/base/src/port/port.tcl
===================================================================
--- 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)
@@ -4790,13 +4790,72 @@
 }
 
 ##
+# Progress callback for generic operations executed by macports 1.0.
+#
+# @param action
+#        One of "start", "update", "intermission" or "finish", 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 "start": empty.
+#        For "update": 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 "intermission": empty.
+#        For "finish": 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}}] > 500 && ($total == 0 || [expr {$now / $total}] < 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 "      "
+                    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 "\r"
+            flush stdout
+        }
+    }
+
+    return 0
+}
+
+
+##
 # Progress callback for downloads executed by macports 1.0.
 #
 # This is essentially a cURL progress callback.
 #
 # @param action
 #        One of "start", "update" or "finish", where start will be called
-#        before any number of change calls, followed by one call to finish.
+#        before any number of update calls, followed by one call to finish.
 # @param args
 #        A list of variadic args that differ for each action.
 #        For "start": contains a single argument "ul" or "dl" indicating
@@ -4826,7 +4885,7 @@
                     }
                 }
                 if {${_port_progress_display_bar} eq yes} {
-                    set barprefix "     "
+                    set barprefix "      "
                     if {$total != 0} {
                         set barsuffix [format "        speed: %-13s" "[bytesize $speed {} "%.1f"]/s"]
                         progress_bar $now $total 20 $barprefix $barsuffix
@@ -4865,7 +4924,7 @@
 proc progress_bar {current total halfwidth {prefix ""} {suffix ""}} {
     # we use 8 different states per character, so let's multiply the width by
     # 8 and map the percentage to this range
-    set percent [expr {($current * 100 / $total)}]
+    set percent [expr {(double($current) * 100 / double($total))}]
     set progress [expr {int(round(($current * $halfwidth * 8) / $total))}]
     set fullfields [expr {int($progress / 8)}]
     set remainder [expr {$progress % 8}]
@@ -5002,6 +5061,7 @@
 
 if {[isatty stdout] && (![info exists ui_options(ports_quiet)] || $ui_options(ports_quiet) ne "yes")} {
     set ui_options(progress_download) port_progress_download
+    set ui_options(progress_generic)  port_progress_generic
 }
 
 # Get arguments remaining after option processing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140213/4077a6b5/attachment.html>


More information about the macports-changes mailing list