Ticket #27244: port.tcl-space.patch
File port.tcl-space.patch, 5.0 KB (added by outis, 14 years ago) |
---|
-
port.
old new 152 152 proc _const value { 153 153 return $value 154 154 } 155 155 156 156 157 # Format an integer representing bytes using binary units (KiB, MiB, GiB) 158 proc bytesize {siz {unit {}}} { 159 set scale 0 160 switch -- $unit { 161 K { 162 set unit "KiB" 163 #set scale 1024.0 164 set siz [expr $siz / 1024.0] 165 } 166 M { 167 set unit "MiB" 168 #set scale 1048576.0 169 set siz [expr $siz / 1048576.0] 170 } 171 B { } 172 default { 173 if {$siz > 0x400} { 174 if {$siz > 0x100000} { 175 if {$siz > 0x40000000} { 176 set unit "GiB" 177 set siz [expr $siz / 1073741824.0] 178 } else { 179 set unit "MiB" 180 set siz [expr $siz / 1048576.0] 181 } 182 } else { 183 set unit "KiB" 184 #set scale 1024.0 185 set siz [expr $siz / 1024.0] 186 } 187 } else { 188 set unit "B " 189 } 190 } 191 } 192 if {[expr round($siz)] != $siz} { 193 set siz [format {%.3f} $siz] 194 } 195 return "$siz $unit" 196 } 197 198 157 199 158 200 # Produce an error message, and exit, unless 159 201 # we're handling errors in a soft fashion, in which 160 202 # case we continue 161 203 proc fatal_softcontinue s { … … 3096 3138 registry::close_file_map 3097 3139 3098 3140 return $status 3099 3141 } 3100 3142 3143 # Alternative: calc space from $portdbpath/software/$port/$portversion 3144 proc action_space {action portlist {opts {}}} { 3145 global private_options global_options 3146 set status 0 3147 set spaceall 0.0 3148 require_portlist portlist 3149 if {[array names private_options -exact size_unit] == {}} { 3150 array set private_options {size_unit {}} 3151 } 3152 foreachport $portlist { 3153 set space 0.0 3154 set files [registry::port_registered $portname] 3155 if { $files != 0 } { 3156 if { [llength $files] > 0 } { 3157 foreach file $files { 3158 catch { 3159 set space [expr $space + [file size $file] ] 3160 } 3161 } 3162 #puts [array get variations] 3163 set msg "[bytesize $space $private_options(size_unit)] $portname" 3164 if { $portversion != {} } { 3165 set msg "$msg @$portversion" 3166 } 3167 #set msg "[bytesize $space $private_options(size_unit)] [regsub {/} $portspec(fullname) { @}]" 3168 puts $msg 3169 set spaceall [expr $space + $spaceall] 3170 } else { 3171 puts "Port $portname does not contain any file or is not active." 3172 } 3173 } else { 3174 puts "Port $portname is not installed." 3175 } 3176 } 3177 if {[llength $portlist] > 1} { 3178 puts "[bytesize $spaceall] total" 3179 } 3180 return $status 3181 } 3182 3101 3183 proc action_variants { action portlist opts } { 3102 3184 global global_variations 3103 3185 set status 0 3104 3186 if {[require_portlist portlist]} { 3105 3187 return 1 … … 3771 3853 uninstall [list action_uninstall [ACTION_ARGS_PORTS]] \ 3772 3854 \ 3773 3855 installed [list action_installed [ACTION_ARGS_PORTS]] \ 3774 3856 outdated [list action_outdated [ACTION_ARGS_PORTS]] \ 3775 3857 contents [list action_contents [ACTION_ARGS_PORTS]] \ 3858 space [list action_space [ACTION_ARGS_PORTS]] \ 3776 3859 dependents [list action_dependents [ACTION_ARGS_PORTS]] \ 3777 3860 rdependents [list action_dependents [ACTION_ARGS_PORTS]] \ 3778 3861 deps [list action_deps [ACTION_ARGS_PORTS]] \ 3779 3862 rdeps [list action_deps [ACTION_ARGS_PORTS]] \ 3780 3863 variants [list action_variants [ACTION_ARGS_PORTS]] \ … … 4028 4111 set global_options(ports_autoclean) yes 4029 4112 } 4030 4113 k { 4031 4114 set global_options(ports_autoclean) no 4032 4115 } 4116 B { 4117 set private_options(size_unit) B 4118 } 4119 K { 4120 set private_options(size_unit) K 4121 } 4122 M { 4123 set private_options(size_unit) M 4124 } 4033 4125 t { 4034 4126 set global_options(ports_trace) yes 4035 4127 } 4036 4128 y { 4037 4129 set global_options(ports_dryrun) yes … … 4379 4471 array set ui_options {} 4380 4472 array set global_options {} 4381 4473 array set global_variations {} 4382 4474 4383 4475 # Global options private to this script 4384 array set private_options { }4476 array set private_options {size_unit {}} 4385 4477 4386 4478 # Make sure we get the size of the terminal 4387 4479 # We do this here to save it in the boot_env, in case we determined it manually 4388 4480 term_init_size 4389 4481