Ticket #27245: port.tcl-contents-size.patch
File port.tcl-contents-size.patch, 4.9 KB (added by outis, 14 years ago) |
---|
-
port.
old new 151 151 # @see const 152 152 proc _const value { 153 153 return $value 154 154 } 155 155 156 # Format an integer representing bytes using binary units (KiB, MiB, GiB) 157 proc 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 197 proc filesize {fil {unit {}}} { 198 set siz {@} 199 catch { 200 set siz [bytesize [file size $fil] $unit] 201 } errMsg 202 return $siz 203 } 156 204 157 205 158 206 # Produce an error message, and exit, unless 159 207 # we're handling errors in a soft fashion, in which 160 208 # case we continue … … 3072 3120 proc action_contents { action portlist opts } { 3073 3121 set status 0 3074 3122 if {[require_portlist portlist]} { 3075 3123 return 1 3076 3124 } 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 } 3077 3135 foreachport $portlist { 3078 3136 if { ![catch {set ilist [registry::installed $portname]} result] } { 3079 3137 # set portname again since the one we were passed may not have had the correct case 3080 3138 set portname [lindex [lindex $ilist 0] 0] 3081 3139 } 3082 3140 set files [registry::port_registered $portname] 3083 3141 if { $files != 0 } { 3084 3142 if { [llength $files] > 0 } { 3085 3143 ui_notice "Port $portname contains:" 3086 3144 foreach file $files { 3087 puts " $file"3145 puts [line $file] 3088 3146 } 3089 3147 } else { 3090 3148 ui_notice "Port $portname does not contain any files or is not active." 3091 3149 } 3092 3150 } else { … … 3771 3829 uninstall [list action_uninstall [ACTION_ARGS_PORTS]] \ 3772 3830 \ 3773 3831 installed [list action_installed [ACTION_ARGS_PORTS]] \ 3774 3832 outdated [list action_outdated [ACTION_ARGS_PORTS]] \ 3775 3833 contents [list action_contents [ACTION_ARGS_PORTS]] \ 3834 files [list action_contents [ACTION_ARGS_PORTS]] \ 3776 3835 dependents [list action_dependents [ACTION_ARGS_PORTS]] \ 3777 3836 rdependents [list action_dependents [ACTION_ARGS_PORTS]] \ 3778 3837 deps [list action_deps [ACTION_ARGS_PORTS]] \ 3779 3838 rdeps [list action_deps [ACTION_ARGS_PORTS]] \ 3780 3839 variants [list action_variants [ACTION_ARGS_PORTS]] \ … … 3887 3946 mirror {new} 3888 3947 lint {nitpick} 3889 3948 select {list set show} 3890 3949 log {{phase 1} {level 1}} 3891 3950 upgrade {force enforce-variants no-replace} 3951 contents {size} 3952 files {size} 3892 3953 } 3893 3954 3894 3955 ## 3895 3956 # Checks whether the given option is valid 3896 3957 # … … 4028 4089 set global_options(ports_autoclean) yes 4029 4090 } 4030 4091 k { 4031 4092 set global_options(ports_autoclean) no 4032 4093 } 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 } 4033 4103 t { 4034 4104 set global_options(ports_trace) yes 4035 4105 } 4036 4106 y { 4037 4107 set global_options(ports_dryrun) yes … … 4379 4449 array set ui_options {} 4380 4450 array set global_options {} 4381 4451 array set global_variations {} 4382 4452 4383 4453 # Global options private to this script 4384 array set private_options { }4454 array set private_options {size_unit {}} 4385 4455 4386 4456 # Make sure we get the size of the terminal 4387 4457 # We do this here to save it in the boot_env, in case we determined it manually 4388 4458 term_init_size 4389 4459