New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 79349


Ignore:
Timestamp:
06/09/11 23:39:14 (4 years ago)
Author:
jmr@…
Message:

add 'space' action to display disk space used by ports (#27244)

Location:
trunk/base/src/port
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port/port-help.tcl

    r77618 r79349  
    294294} 
    295295 
     296set porthelp(space) { 
     297Show the disk space used by the given ports 
     298 
     299--units <units> Specify units to use. Accepted units are: B, kB, KiB, MB, MiB, 
     300                GB, GiB. The 'B' may be omitted. 
     301} 
     302 
    296303set porthelp(srpm) { 
    297304Creates a srpm for each of the given ports 
  • trunk/base/src/port/port.tcl

    r79259 r79349  
    155155 
    156156 
     157# Format an integer representing bytes using given units 
     158proc bytesize {siz {unit {}}} { 
     159    if {$unit == {}} { 
     160        if {$siz > 0x40000000} { 
     161            set unit "GiB" 
     162        } elseif {$siz > 0x100000} { 
     163            set unit "MiB" 
     164        } elseif {$siz > 0x400} { 
     165            set unit "KiB" 
     166        } else { 
     167            set unit "B" 
     168        } 
     169    } 
     170    switch -- $unit { 
     171        KiB { 
     172            set siz [expr $siz / 1024.0] 
     173        } 
     174        kB { 
     175            set siz [expr $siz / 1000.0] 
     176        } 
     177        MiB { 
     178            set siz [expr $siz / 1048576.0] 
     179        } 
     180        MB { 
     181            set siz [expr $siz / 1000000.0] 
     182        } 
     183        GiB { 
     184            set siz [expr $siz / 1073741824.0] 
     185        } 
     186        GB { 
     187            set siz [expr $siz / 1000000000.0] 
     188        } 
     189        B { } 
     190        default { 
     191            ui_warn "Unknown file size unit '$unit' specified" 
     192            set unit "B" 
     193        } 
     194    } 
     195    if {[expr round($siz)] != $siz} { 
     196        set siz [format {%.3f} $siz] 
     197    } 
     198    return "$siz $unit" 
     199} 
     200 
    157201 
    158202# Produce an error message, and exit, unless 
     
    30853129 
    30863130    return $status 
     3131} 
     3132 
     3133# expand abbreviations of size units 
     3134proc complete_size_units {units} { 
     3135    if {$units == "K" || $units == "Ki"} { 
     3136        return "KiB" 
     3137    } elseif {$units == "k"} { 
     3138        return "kB" 
     3139    } elseif {$units == "Mi"} { 
     3140        return "MiB" 
     3141    } elseif {$units == "M"} { 
     3142        return "MB" 
     3143    } elseif {$units == "Gi"} { 
     3144        return "GiB" 
     3145    } elseif {$units == "G"} { 
     3146        return "GB" 
     3147    } else { 
     3148        return $units 
     3149    } 
     3150} 
     3151 
     3152# Show space used by the given ports' files 
     3153proc action_space {action portlist opts} { 
     3154    global global_options 
     3155    require_portlist portlist 
     3156 
     3157    set units {} 
     3158    if {[info exists global_options(ports_space_units)]} { 
     3159        set units [complete_size_units $global_options(ports_space_units)] 
     3160    } 
     3161    set spaceall 0.0 
     3162    foreachport $portlist { 
     3163        set space 0.0 
     3164        set files [registry::port_registered $portname] 
     3165        if { $files != 0 } { 
     3166            if { [llength $files] > 0 } { 
     3167                foreach file $files { 
     3168                    catch { 
     3169                        set space [expr $space + [file size $file] ] 
     3170                    } 
     3171                } 
     3172                set msg "[bytesize $space $units] $portname" 
     3173                if { $portversion != {} } { 
     3174                    append msg " @$portversion" 
     3175                } 
     3176                puts $msg 
     3177                set spaceall [expr $space + $spaceall] 
     3178            } else { 
     3179                puts "Port $portname does not contain any file or is not active." 
     3180            } 
     3181        } else { 
     3182            puts "Port $portname is not installed." 
     3183        } 
     3184    } 
     3185    if {[llength $portlist] > 1} { 
     3186        puts "[bytesize $spaceall $units] total" 
     3187    } 
     3188    return 0 
    30873189} 
    30883190 
     
    37793881    outdated    [list action_outdated       [ACTION_ARGS_PORTS]] \ 
    37803882    contents    [list action_contents       [ACTION_ARGS_PORTS]] \ 
     3883    space       [list action_space          [ACTION_ARGS_PORTS]] \ 
    37813884    dependents  [list action_dependents     [ACTION_ARGS_PORTS]] \ 
    37823885    rdependents [list action_dependents     [ACTION_ARGS_PORTS]] \ 
     
    39204023                 platforms portdir regex revision variant variants version} 
    39214024    selfupdate  {nosync} 
     4025    space       {{units 1}} 
    39224026    activate    {no-exec} 
    39234027    deactivate  {no-exec} 
Note: See TracChangeset for help on using the changeset viewer.