[146719] trunk/base/src
raimue at macports.org
raimue at macports.org
Tue Mar 15 10:59:25 PDT 2016
Revision: 146719
https://trac.macports.org/changeset/146719
Author: raimue at macports.org
Date: 2016-03-15 10:59:25 -0700 (Tue, 15 Mar 2016)
Log Message:
-----------
Move bytesize and filesize to macports_util
The bytesize proc is also used for formatting the reclaim output. Move it to
macports_util so it is available to both the port client and the macports
package.
Modified Paths:
--------------
trunk/base/src/macports1.0/macports_util.tcl
trunk/base/src/port/port.tcl
Modified: trunk/base/src/macports1.0/macports_util.tcl
===================================================================
--- trunk/base/src/macports1.0/macports_util.tcl 2016-03-15 17:55:59 UTC (rev 146718)
+++ trunk/base/src/macports1.0/macports_util.tcl 2016-03-15 17:59:25 UTC (rev 146719)
@@ -176,6 +176,64 @@
}
macports_util::method_wrap lunshift
+
+# bytesize filesize ?unit? ?format?
+# Format an integer representing bytes using given units
+proc bytesize {siz {unit {}} {format {%.3f}}} {
+ if {$unit == {}} {
+ if {$siz > 0x40000000} {
+ set unit "GiB"
+ } elseif {$siz > 0x100000} {
+ set unit "MiB"
+ } elseif {$siz > 0x400} {
+ set unit "KiB"
+ } else {
+ set unit "B"
+ }
+ }
+ switch -- $unit {
+ KiB {
+ set siz [expr {$siz / 1024.0}]
+ }
+ kB {
+ set siz [expr {$siz / 1000.0}]
+ }
+ MiB {
+ set siz [expr {$siz / 1048576.0}]
+ }
+ MB {
+ set siz [expr {$siz / 1000000.0}]
+ }
+ GiB {
+ set siz [expr {$siz / 1073741824.0}]
+ }
+ GB {
+ set siz [expr {$siz / 1000000000.0}]
+ }
+ B { }
+ default {
+ ui_warn "Unknown file size unit '$unit' specified"
+ set unit "B"
+ }
+ }
+ if {[expr {round($siz)}] != $siz} {
+ set siz [format $format $siz]
+ }
+ return "$siz $unit"
+}
+
+# filesize file ?unit?
+# Return size of file in human-readable format
+# In case of any errors, returns -1
+proc filesize {fil {unit {}}} {
+ set siz -1
+ catch {
+ set siz [bytesize [file size $fil] $unit]
+ }
+ return $siz
+}
+
+
################################
# try/catch exception handling #
################################
Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl 2016-03-15 17:55:59 UTC (rev 146718)
+++ trunk/base/src/port/port.tcl 2016-03-15 17:59:25 UTC (rev 146719)
@@ -154,58 +154,6 @@
proc $name {} [list return [expr $args]]
}
-# Format an integer representing bytes using given units
-proc bytesize {siz {unit {}} {format {%.3f}}} {
- if {$unit == {}} {
- if {$siz > 0x40000000} {
- set unit "GiB"
- } elseif {$siz > 0x100000} {
- set unit "MiB"
- } elseif {$siz > 0x400} {
- set unit "KiB"
- } else {
- set unit "B"
- }
- }
- switch -- $unit {
- KiB {
- set siz [expr {$siz / 1024.0}]
- }
- kB {
- set siz [expr {$siz / 1000.0}]
- }
- MiB {
- set siz [expr {$siz / 1048576.0}]
- }
- MB {
- set siz [expr {$siz / 1000000.0}]
- }
- GiB {
- set siz [expr {$siz / 1073741824.0}]
- }
- GB {
- set siz [expr {$siz / 1000000000.0}]
- }
- B { }
- default {
- ui_warn "Unknown file size unit '$unit' specified"
- set unit "B"
- }
- }
- if {[expr {round($siz)}] != $siz} {
- set siz [format $format $siz]
- }
- return "$siz $unit"
-}
-
-proc filesize {fil {unit {}}} {
- set siz {@}
- catch {
- set siz [bytesize [file size $fil] $unit]
- }
- return $siz
-}
-
# Produce an error message, and exit, unless
# we're handling errors in a soft fashion, in which
# case we continue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160315/a231e017/attachment-0001.html>
More information about the macports-changes
mailing list