Ticket #27245: port.tcl-contents-size.patch

File port.tcl-contents-size.patch, 4.9 KB (added by outis, 13 years ago)

adds "--size" option flag & "files" as alias for action "contents"

  • port.

    old new  
    151151# @see const
    152152proc _const value {
    153153    return $value
    154154}
    155155
     156# Format an integer representing bytes using binary units (KiB, MiB, GiB)
     157proc bytesize {siz {unit {}}} {
     158    set scale 0
     159    switch -- $unit {
     160        K {
     161            set unit "KiB"
     162            #set scale 1024.0
     163            set siz [expr $siz / 1024.0]
     164        }
     165        M {
     166            set unit "MiB"
     167            #set scale 1048576.0
     168            set siz [expr $siz / 1048576.0]
     169        }
     170        B { }
     171        default {
     172            if {$siz > 0x400} {
     173                if {$siz > 0x100000} {
     174                    if {$siz > 0x40000000} {
     175                        set unit "GiB"
     176                        set siz [expr $siz / 1073741824.0]                   
     177                    } else {
     178                        set unit "MiB"
     179                        set siz [expr $siz / 1048576.0]
     180                    }                   
     181                } else {
     182                    set unit "KiB"
     183                    #set scale 1024.0
     184                    set siz [expr $siz / 1024.0]
     185                }
     186            } else {
     187                set unit "B  "
     188            }
     189        }
     190    }
     191    if {[expr round($siz)] != $siz} {
     192        set siz [format {%.3f} $siz]
     193    }
     194    return "$siz $unit"
     195}
     196
     197proc filesize {fil {unit {}}} {
     198    set siz {@}
     199    catch {
     200        set siz [bytesize [file size $fil] $unit]
     201    } errMsg
     202    return $siz
     203}
    156204
    157205
    158206# Produce an error message, and exit, unless
    159207# we're handling errors in a soft fashion, in which
    160208# case we continue
     
    30723120proc action_contents { action portlist opts } {
    30733121    set status 0
    30743122    if {[require_portlist portlist]} {
    30753123        return 1
    30763124    }
     3125    if {[array names global_options -exact ports_${action}_size] != {}} {
     3126        proc line {file} {
     3127            global private_options
     3128            return [format "%12s $file" [filesize $file $private_options(size_unit)]]
     3129        }
     3130    } else {
     3131        proc line {file} {
     3132            return "  $file"
     3133        }
     3134    }
    30773135    foreachport $portlist {
    30783136        if { ![catch {set ilist [registry::installed $portname]} result] } {
    30793137            # set portname again since the one we were passed may not have had the correct case
    30803138            set portname [lindex [lindex $ilist 0] 0]
    30813139        }
    30823140        set files [registry::port_registered $portname]
    30833141        if { $files != 0 } {
    30843142            if { [llength $files] > 0 } {
    30853143                ui_notice "Port $portname contains:"
    30863144                foreach file $files {
    3087                     puts "  $file"
     3145                    puts [line $file]
    30883146                }
    30893147            } else {
    30903148                ui_notice "Port $portname does not contain any files or is not active."
    30913149            }
    30923150        } else {
     
    37713829    uninstall   [list action_uninstall      [ACTION_ARGS_PORTS]] \
    37723830    \
    37733831    installed   [list action_installed      [ACTION_ARGS_PORTS]] \
    37743832    outdated    [list action_outdated       [ACTION_ARGS_PORTS]] \
    37753833    contents    [list action_contents       [ACTION_ARGS_PORTS]] \
     3834    files       [list action_contents       [ACTION_ARGS_PORTS]] \
    37763835    dependents  [list action_dependents     [ACTION_ARGS_PORTS]] \
    37773836    rdependents [list action_dependents     [ACTION_ARGS_PORTS]] \
    37783837    deps        [list action_deps           [ACTION_ARGS_PORTS]] \
    37793838    rdeps       [list action_deps           [ACTION_ARGS_PORTS]] \
    37803839    variants    [list action_variants       [ACTION_ARGS_PORTS]] \
     
    38873946    mirror      {new}
    38883947    lint        {nitpick}
    38893948    select      {list set show}
    38903949    log         {{phase 1} {level 1}}
    38913950    upgrade     {force enforce-variants no-replace}
     3951    contents    {size}
     3952    files       {size}
    38923953}
    38933954
    38943955##
    38953956# Checks whether the given option is valid
    38963957#
     
    40284089                        set global_options(ports_autoclean) yes
    40294090                    }
    40304091                    k {
    40314092                        set global_options(ports_autoclean) no
    40324093                    }
     4094                    B {
     4095                        set private_options(size_unit) B
     4096                    }
     4097                    K {
     4098                        set private_options(size_unit) K
     4099                    }
     4100                    M {
     4101                        set private_options(size_unit) M
     4102                    }
    40334103                    t {
    40344104                        set global_options(ports_trace) yes
    40354105                    }
    40364106                    y {
    40374107                        set global_options(ports_dryrun) yes
     
    43794449array set ui_options        {}
    43804450array set global_options    {}
    43814451array set global_variations {}
    43824452
    43834453# Global options private to this script
    4384 array set private_options {}
     4454array set private_options {size_unit {}}
    43854455
    43864456# Make sure we get the size of the terminal
    43874457# We do this here to save it in the boot_env, in case we determined it manually
    43884458term_init_size
    43894459