| 1 |
#!/usr/bin/env wish |
| 2 |
|
| 3 |
# Copyright 2017-2025 Siep Kroonenberg |
| 4 |
|
| 5 |
# This file is licensed under the GNU General Public License version 2 |
| 6 |
# or any later version. |
| 7 |
|
| 8 |
package require Tk |
| 9 |
|
| 10 |
# security: disable send |
| 11 |
catch {rename send {}} |
| 12 |
|
| 13 |
# unix: make sure TL comes first on process searchpath |
| 14 |
# on windows, a wrapper takes care of this. |
| 15 |
if {$::tcl_platform(platform) ne "windows"} { |
| 16 |
set texbin [file dirname [file normalize [info script]]] |
| 17 |
# prepend texbin to PATH, unless it is already the _first_ |
| 18 |
# path component |
| 19 |
set dirs [split $::env(PATH) ":"] |
| 20 |
if {[lindex $dirs 0] ne $texbin} { |
| 21 |
set ::env(PATH) "${texbin}:$::env(PATH)" |
| 22 |
} |
| 23 |
unset texbin |
| 24 |
unset dirs |
| 25 |
} |
| 26 |
|
| 27 |
set ::instroot [exec kpsewhich -var-value=TEXMFROOT] |
| 28 |
set ::year 0 ; # to be set when connecting to tlmgr |
| 29 |
|
| 30 |
# try to read a configuration variable (gui-lang, tkfontscale) |
| 31 |
# from tlmgr config ($TEXMF[SYS]CONFIG/tlmgr/config |
| 32 |
# failure results in an empty string. |
| 33 |
# this proc will be invoked by tltcl if tlshell is the invoker of tltcl |
| 34 |
proc get_config_var {k} { |
| 35 |
set v "" |
| 36 |
set r [join [list {^\s*} $k {\s*=\s*(\S.*)$}] ""] |
| 37 |
foreach tmf {"TEXMFCONFIG" "TEXMFSYSCONFIG"} { |
| 38 |
if [catch {exec kpsewhich -var-value $tmf} d] { |
| 39 |
break; # apparently there is not yet a TL installation |
| 40 |
} |
| 41 |
|
| 42 |
if [catch {open [file join $d "tlmgr" "config"] r} fid] continue |
| 43 |
while 1 { |
| 44 |
if [chan eof $fid] { |
| 45 |
break |
| 46 |
} |
| 47 |
if [catch {chan gets $fid} l] break |
| 48 |
# we can assume that $k contains no special characters |
| 49 |
if [regexp $r $l m v] { |
| 50 |
set v [regsub {\s*$} $v ""] |
| 51 |
break |
| 52 |
} else { |
| 53 |
# regexp will have unset v |
| 54 |
set v "" |
| 55 |
} |
| 56 |
} |
| 57 |
chan close $fid |
| 58 |
if {$v ne ""} break |
| 59 |
} |
| 60 |
return $v |
| 61 |
} |
| 62 |
|
| 63 |
proc save_config_var {k v} { |
| 64 |
if [catch {exec kpsewhich -var-value "TEXMFCONFIG"} d] {return 0} |
| 65 |
set d [file join $d "tlmgr"] |
| 66 |
if [catch {file mkdir $d}] {return 0} ; # mkdir on existing dir is ok |
| 67 |
set fn [file join $d "config"] |
| 68 |
set oldlines [list] |
| 69 |
set r [join [list {^\s*} $k {\s*=\s*(\S.*)$}] ""] |
| 70 |
# read current config file |
| 71 |
if [file exists $fn] { |
| 72 |
if [catch {open $fn r} fid] {return 0} |
| 73 |
set cnt 0 |
| 74 |
while 1 { |
| 75 |
if [catch {chan gets $fid} l] break |
| 76 |
if [chan eof $fid] break |
| 77 |
incr cnt |
| 78 |
if {! [regexp $r $l]} { |
| 79 |
lappend oldlines $l |
| 80 |
} |
| 81 |
if {$cnt>40} break |
| 82 |
} |
| 83 |
catch {chan close $fid} |
| 84 |
} |
| 85 |
lappend oldlines "$k = $v" |
| 86 |
if [catch {open $fn w} fid] {return 0} |
| 87 |
foreach l $oldlines { |
| 88 |
if [catch {puts $fid $l}] { |
| 89 |
catch {chan close $fid} |
| 90 |
return 0 |
| 91 |
} |
| 92 |
} |
| 93 |
catch {chan close $fid} |
| 94 |
return 1 |
| 95 |
} |
| 96 |
|
| 97 |
# tltcl: declarations and utilities shared with install-tl-gui.tcl |
| 98 |
# tltcl likes to know who was the invoker |
| 99 |
set ::invoker [file tail [info script]] |
| 100 |
if [string match -nocase ".tcl" [string range $::invoker end-3 end]] { |
| 101 |
set ::invoker [string range $::invoker 0 end-4] |
| 102 |
} |
| 103 |
source [file join $::instroot "tlpkg" "tltcl" "tltcl.tcl"] |
| 104 |
|
| 105 |
# now is a good time to ask tlmgr for the _TL_ name of our platform |
| 106 |
set ::our_platform [exec -ignorestderr tlmgr print-platform] |
| 107 |
|
| 108 |
# searchpath and locale: |
| 109 |
# windows: tlshell runs via a wrapper which adjusts the searchpath |
| 110 |
# for the current process. |
| 111 |
# others: tlshell.tcl should be run via a symlink in a directory |
| 112 |
# which also contains (a symlink to) kpsewhich. |
| 113 |
# This directory will be prepended to the searchpath. |
| 114 |
# kpsewhich should disentangle symlinks. |
| 115 |
|
| 116 |
# dis/enable the restore dialog |
| 117 |
set do_restore 0 |
| 118 |
|
| 119 |
# tlcontrib |
| 120 |
set tlcontrib "http://contrib.texlive.info/current" |
| 121 |
|
| 122 |
# dis/enable debug output (only for private development purposes) |
| 123 |
set ddebug 0 |
| 124 |
|
| 125 |
##### general housekeeping ############################################ |
| 126 |
|
| 127 |
# menus: disable tearoff feature |
| 128 |
option add *Menu.tearOff 0 |
| 129 |
|
| 130 |
proc search_nocase {needle haystack} { |
| 131 |
if {$needle eq ""} {return -1} |
| 132 |
if {$haystack eq ""} {return -1} |
| 133 |
return [string first [string tolower $needle] [string tolower $haystack]] |
| 134 |
} |
| 135 |
|
| 136 |
# the stderr and stdout of tlmgr are each read into lists of strings |
| 137 |
set err_log {} |
| 138 |
set out_log {} |
| 139 |
|
| 140 |
#### debug output, ATM only for private development purposes #### |
| 141 |
|
| 142 |
if $ddebug {set dbg_log {}} |
| 143 |
|
| 144 |
proc do_debug {s} { |
| 145 |
if $::ddebug { |
| 146 |
if {$::tcl_platform(platform) ne "windows"} {puts stderr $s} |
| 147 |
# On windows, stderr output goes nowhere. |
| 148 |
# Therefore also debug output for the log dialog. |
| 149 |
lappend ::dbg_log $s |
| 150 |
file mkdir ${::instroot}/temp |
| 151 |
set dbg [open "${::instroot}/temp/mydbglog" a] |
| 152 |
puts $dbg "TCL: $s" |
| 153 |
chan close $dbg |
| 154 |
# Track debug output in the log dialog if it is running: |
| 155 |
if [winfo exists .tllg.dbg.tx] { |
| 156 |
.tllg.dbg.tx configure -state normal |
| 157 |
.tllg.dbg.tx insert end "$s\n" |
| 158 |
if {$::tcl_platform(os) ne "Darwin"} { |
| 159 |
.tllg.dbg.tx configure -state disabled |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} ; # do_debug |
| 164 |
|
| 165 |
### temporary files and directories ######################### |
| 166 |
|
| 167 |
proc maketemp {ext} { |
| 168 |
set fname "" |
| 169 |
foreach i {0 1 2 3 4 5 6 7 8 9} { ; # ten tries |
| 170 |
set fname [file join $::tempsub "[expr {int(10000.0*rand())}]$ext"] |
| 171 |
if {[file exist $fname]} {set fname ""; continue} |
| 172 |
# create empty file. although we just want a name, |
| 173 |
# we must make sure that it can be created. |
| 174 |
set fid [open $fname w] |
| 175 |
chan close $fid |
| 176 |
if {! [file exists $fname]} {error "Cannot create temporary file"} |
| 177 |
if {$::tcl_platform(platform) eq "unix"} { |
| 178 |
file attributes $fname -permissions 0600 |
| 179 |
} |
| 180 |
break |
| 181 |
} |
| 182 |
if {$fname eq ""} {error "Cannot create temporary file"} |
| 183 |
return $fname |
| 184 |
} ; # maketemp |
| 185 |
|
| 186 |
set tempsub "" ; # subdir for temp files, set during initialization |
| 187 |
|
| 188 |
### GUI utilities ##################################################### |
| 189 |
|
| 190 |
# mouse clicks: deal with MacOS platform differences |
| 191 |
if {[tk windowingsystem] eq "aqua"} { |
| 192 |
event add <<RightClick>> <ButtonRelease-2> <Control-ButtonRelease-1> |
| 193 |
} else { |
| 194 |
event add <<RightClick>> <ButtonRelease-3> |
| 195 |
} |
| 196 |
|
| 197 |
## default_bg color, only used for menus under ::plain_unix |
| 198 |
if [catch {ttk::style lookup TFrame -background} ::default_bg] { |
| 199 |
set ::default_bg white |
| 200 |
} |
| 201 |
|
| 202 |
# NOTE |
| 203 |
# text widgets aren't ttk widgets: |
| 204 |
# state disabled => configure -state disabled |
| 205 |
# state !disabled => configure -state normal |
| 206 |
|
| 207 |
# dialog with textbox |
| 208 |
proc long_message {str type {p "."}} { |
| 209 |
# alternate messagebox implemented as custom dialog |
| 210 |
# not all message types are supported |
| 211 |
if {$type ne "ok" && $type ne "okcancel" && $type ne "yesnocancel"} { |
| 212 |
err_exit "Unsupported type $type for long_message" |
| 213 |
} |
| 214 |
create_dlg .tlmg $p |
| 215 |
wm title .tlmg "" |
| 216 |
|
| 217 |
# wallpaper frame; see populate_main |
| 218 |
pack [ttk::frame .tlmg.bg] -fill both -expand 1 |
| 219 |
|
| 220 |
# buttons |
| 221 |
pack [ttk::frame .tlmg.bts] -in .tlmg.bg -side bottom -fill x |
| 222 |
if {$type eq "ok" || $type eq "okcancel"} { |
| 223 |
ttk::button .tlmg.ok -text [__ "Ok"] -command "end_dlg \"ok\" .tlmg" |
| 224 |
ppack .tlmg.ok -in .tlmg.bts -side right |
| 225 |
} |
| 226 |
if {$type eq "yesnocancel"} { |
| 227 |
ttk::button .tlmg.yes -text [__ "Yes"] -command "end_dlg \"yes\" .tlmg" |
| 228 |
ppack .tlmg.yes -in .tlmg.bts -side right |
| 229 |
ttk::button .tlmg.no -text [__ "No"] -command "end_dlg \"no\" .tlmg" |
| 230 |
ppack .tlmg.no -in .tlmg.bts -side right |
| 231 |
} |
| 232 |
if {$type eq "yesnocancel" || $type eq "okcancel"} { |
| 233 |
ttk::button .tlmg.cancel -text [__ "Cancel"] -command \ |
| 234 |
"end_dlg \"cancel\" .tlmg" |
| 235 |
ppack .tlmg.cancel -in .tlmg.bts -side right |
| 236 |
} |
| 237 |
if [winfo exists .tlmg.cancel] { |
| 238 |
bind .tlmg <Escape> {.tlmg.cancel invoke} |
| 239 |
wm protocol .tlmg WM_DELETE_WINDOW {cancel_or_destroy .tlmg.cancel .tlmg} |
| 240 |
} elseif {$type eq "ok"} { |
| 241 |
bind .tlmg <Escape> {.tlmg.ok invoke} |
| 242 |
wm protocol .tlmg WM_DELETE_WINDOW {cancel_or_destroy .tlmg.ok .tlmg} |
| 243 |
} |
| 244 |
|
| 245 |
ppack [ttk::frame .tlmg.tx] -in .tlmg.bg -side top -fill both -expand 1 |
| 246 |
pack [ttk::scrollbar .tlmg.tx.scroll -command ".tlmg.tx.txt yview"] \ |
| 247 |
-side right -fill y |
| 248 |
ppack [text .tlmg.tx.txt -height 20 -width 60 -bd 2 -relief groove \ |
| 249 |
-wrap word -yscrollcommand ".tlmg.tx.scroll set"] -expand 1 -fill both |
| 250 |
|
| 251 |
.tlmg.tx.txt insert end $str |
| 252 |
.tlmg.tx.txt configure -state disabled |
| 253 |
|
| 254 |
# default resizable |
| 255 |
place_dlg .tlmg $p |
| 256 |
tkwait window .tlmg |
| 257 |
return $::dialog_ans |
| 258 |
} ; # long_message |
| 259 |
|
| 260 |
proc any_message {str type {p "."}} { |
| 261 |
if {[string length $str] < 400} { |
| 262 |
if {$type ne "ok"} { |
| 263 |
return [tk_messageBox -message $str -type $type -parent $p \ |
| 264 |
-icon question] |
| 265 |
} else { |
| 266 |
return [tk_messageBox -message $str -type $type -parent $p] |
| 267 |
} |
| 268 |
} else { |
| 269 |
# just hope that tcl will do the right thing with multibyte characters |
| 270 |
if {[string length $str] > 500000} { |
| 271 |
set str [string range $str 0 500000] |
| 272 |
append str "\n....." |
| 273 |
} |
| 274 |
return [long_message $str $type $p] |
| 275 |
} |
| 276 |
} ; # any_message |
| 277 |
|
| 278 |
##### tl global data ################################################## |
| 279 |
|
| 280 |
set ::last_cmd "" |
| 281 |
|
| 282 |
set ::progname [info script] |
| 283 |
regexp {^.*[\\/]([^\\/\.]*)(?:\....)?$} $progname dummy ::progname |
| 284 |
set ::procid [pid] |
| 285 |
|
| 286 |
# package repositories |
| 287 |
array unset ::repos |
| 288 |
|
| 289 |
# mirrors: dict of dicts of lists of urls per country per continent |
| 290 |
# moved to tltcl.tcl |
| 291 |
#set ::mirrors [dict create] |
| 292 |
|
| 293 |
# dict of (local and global) package dicts |
| 294 |
set ::pkgs [dict create] |
| 295 |
|
| 296 |
# platforms |
| 297 |
set ::platforms [dict create] |
| 298 |
|
| 299 |
set ::have_remote 0 ; # remote packages info not yet loaded |
| 300 |
set ::need_update_tlmgr 0 |
| 301 |
set ::n_updates 0 |
| 302 |
set ::tlshell_updatable 0 |
| 303 |
|
| 304 |
## package data to be displayed ## |
| 305 |
|
| 306 |
# sorted display data for packages; package data stored as lists |
| 307 |
set ::filtered [dict create] |
| 308 |
|
| 309 |
# selecting packages for display: status and detail |
| 310 |
set ::stat_opt "inst" |
| 311 |
set ::dtl_opt "all" |
| 312 |
# searching packages for display; also search short descriptions? |
| 313 |
set ::search_desc 0 |
| 314 |
|
| 315 |
### enabling and disabling user interaction based on global data |
| 316 |
|
| 317 |
proc selective_dis_enable {} { |
| 318 |
# disable actions which make no sense at the time |
| 319 |
|
| 320 |
# buttons in the middle section |
| 321 |
set pkg_buttons [list .mrk_inst .mrk_upd .mrk_rem .upd_tlmgr .upd_all] |
| 322 |
foreach b [list .mrk_inst .mrk_upd .mrk_rem .upd_tlmgr .upd_all] { |
| 323 |
$b state !disabled |
| 324 |
} |
| 325 |
if $::do_restore {.mrk_rest state !disabled} |
| 326 |
|
| 327 |
if {!$::have_remote} { |
| 328 |
foreach b [list .mrk_inst .mrk_upd .upd_tlmgr .upd_all] { |
| 329 |
$b state disabled |
| 330 |
} |
| 331 |
} elseif {!$::n_updates} { |
| 332 |
foreach b [list .mrk_upd .upd_tlmgr .upd_all] { |
| 333 |
$b state disabled |
| 334 |
} |
| 335 |
} elseif $::need_update_tlmgr { |
| 336 |
foreach b [list .mrk_inst .mrk_upd] { |
| 337 |
$b state disabled |
| 338 |
} |
| 339 |
if {$::tcl_platform(platform) eq "windows"} { |
| 340 |
.upd_all state disabled |
| 341 |
} |
| 342 |
} elseif {!$::need_update_tlmgr} { |
| 343 |
.upd_tlmgr state disabled |
| 344 |
} |
| 345 |
|
| 346 |
# platforms menu item |
| 347 |
if {$::tcl_platform(platform) ne "windows"} { |
| 348 |
if {!$::have_remote || $::need_update_tlmgr} { |
| 349 |
.mn.opt entryconfigure $::inx_platforms -state disabled |
| 350 |
} else { |
| 351 |
.mn.opt entryconfigure $::inx_platforms -state normal |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
# 64-bit windows |
| 356 |
# we disable this menu, but we may possibly resurrect it later |
| 357 |
# for windows on arm support; therefore 'if {0 && ...} |
| 358 |
if {0 && $::tcl_platform(platform) eq "windows" && $::wprocessor eq "AMD64"} { |
| 359 |
dis_enable_w64 |
| 360 |
} |
| 361 |
}; # selective_dis_enable |
| 362 |
|
| 363 |
proc total_dis_enable {y_n} { |
| 364 |
# to be invoked when tlmgr becomes busy or idle, i.e. |
| 365 |
# if it starts with a tlmgr command through run_cmds |
| 366 |
# or read_line notices the command(s) ha(s|ve) ended. |
| 367 |
# This proc should cover all active interface elements of the main window. |
| 368 |
# But if actions are initiated via a dialog, the main window can instead |
| 369 |
# be deactivated by a grab and focus on the dialog. |
| 370 |
|
| 371 |
if {!$y_n} { ; # disable |
| 372 |
set ::busy [__ "Running"] |
| 373 |
. configure -menu .mn_empty |
| 374 |
foreach c [winfo children .] { |
| 375 |
if {$c ne ".showlogs" && [winfo class $c] in $::active_cls} { |
| 376 |
# this should cover all relevant widgets in the main window |
| 377 |
$c state disabled |
| 378 |
} |
| 379 |
} |
| 380 |
} else { ; # enable |
| 381 |
. configure -menu .mn |
| 382 |
foreach c [winfo children .] { |
| 383 |
if {[winfo class $c] in $::active_cls} { |
| 384 |
$c state !disabled |
| 385 |
} |
| 386 |
} |
| 387 |
set ::busy [__ "Idle"] |
| 388 |
selective_dis_enable |
| 389 |
} |
| 390 |
} ; # total_dis_enable |
| 391 |
|
| 392 |
##### handling tlmgr via pipe and stderr tempfile ##################### |
| 393 |
|
| 394 |
set ::prmpt "tlmgr>" |
| 395 |
set ::busy [__ "Running"] |
| 396 |
|
| 397 |
# copy logs to log window yes/no |
| 398 |
set ::show_output 0 |
| 399 |
|
| 400 |
# about [chan] gets: |
| 401 |
# if a second parameter, in this case l, is supplied |
| 402 |
# then this variable receives the result, with EOL stripped, |
| 403 |
# and the return value is the string length, possibly 0 |
| 404 |
# EOF is indicated by a return value of -1. |
| 405 |
|
| 406 |
proc read_err_tempfile {} { |
| 407 |
if [info exists ::err] { |
| 408 |
set len 0 |
| 409 |
while 1 { |
| 410 |
set len [chan gets $::err l] |
| 411 |
if {$len >= 0} { |
| 412 |
lappend ::err_log $l |
| 413 |
} else { |
| 414 |
break |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
} ; # read_err_tempfile |
| 419 |
|
| 420 |
proc err_exit {{m ""}} { |
| 421 |
do_debug "error exit" |
| 422 |
read_err_tempfile |
| 423 |
if {$m ne ""} { |
| 424 |
set ::err_log [linsert $::err_log 0 $m] |
| 425 |
} |
| 426 |
any_message [join $::err_log "\n"] "ok" |
| 427 |
exit |
| 428 |
} ; # err_exit |
| 429 |
|
| 430 |
# Capture stdout of tlmgr into a pipe $::tlshl, |
| 431 |
# stderr into a temp file file $::err_file which is set at initialization. |
| 432 |
|
| 433 |
proc start_tlmgr {{args ""}} { |
| 434 |
# Start the TeX Live Manager shell interface. |
| 435 |
# Below, vwait ::done_waiting forces tlshell |
| 436 |
# to process initial tlmgr output before continuing. |
| 437 |
unset -nocomplain ::done_waiting |
| 438 |
do_debug "opening tlmgr" |
| 439 |
# -gui -. -gui-lang |
| 440 |
for {set i 0} {$i < [llength $args]} {incr i} { |
| 441 |
if {[lindex $args $i] eq "-lang"} { |
| 442 |
set args [lreplace $args $i $i "-gui-lang"] |
| 443 |
} |
| 444 |
} |
| 445 |
set cmd [list "|tlmgr" {*}$args "--machine-readable" "shell" 2>>$::err_file] |
| 446 |
if [catch {open $cmd w+} ::tlshl] { |
| 447 |
tk_messageBox -message [get_stacktrace] |
| 448 |
exit |
| 449 |
} |
| 450 |
set ::perlpid [pid $::tlshl] |
| 451 |
do_debug "done opening tlmgr" |
| 452 |
set ::err [open $::err_file r] |
| 453 |
|
| 454 |
if {$::tcl_platform(platform) eq "windows"} { |
| 455 |
set system_enc [encoding system] |
| 456 |
if {$system_enc eq "utf-8"} { |
| 457 |
# When the tclkit.exe manifest specifies 'activeCodePage' as UTF-8, |
| 458 |
# [encoding system] returns 'utf-8'. However, external processes often |
| 459 |
# still output in the system's original ANSI code page (e.g., CP932 for |
| 460 |
# Japanese). We query the registry to get the 'true' system ANSI code |
| 461 |
# page (ACP) to correctly decode piped output from these external tools. |
| 462 |
package require registry |
| 463 |
set regPath "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage" |
| 464 |
if {![catch {registry get $regPath "ACP"} acp_num]} { |
| 465 |
if {$acp_num eq "65001"} { |
| 466 |
# truly utf-8 |
| 467 |
set system_enc "utf-8" |
| 468 |
} elseif {"cp$acp_num" in [encoding names]} { |
| 469 |
set system_enc "cp$acp_num" |
| 470 |
} else { |
| 471 |
# ACP not supported by Tcl ...what to do? |
| 472 |
} |
| 473 |
} |
| 474 |
} |
| 475 |
chan configure $::tlshl -encoding $system_enc -profile replace -translation auto |
| 476 |
} |
| 477 |
|
| 478 |
chan configure $::tlshl -buffering line -blocking 0 |
| 479 |
chan event $::tlshl readable read_line |
| 480 |
vwait ::done_waiting |
| 481 |
} ; # start_tlmgr |
| 482 |
|
| 483 |
proc close_tlmgr {} { |
| 484 |
run_cmd_waiting "quit" |
| 485 |
} |
| 486 |
|
| 487 |
# read a line of tlmgr output |
| 488 |
proc read_line {} { |
| 489 |
# a caller of run_cmd needs to explicitly invoke 'vwait ::done_waiting' |
| 490 |
# if it wants to wait for the command to finish |
| 491 |
set l "" ; # will contain the line to be read |
| 492 |
if {([catch {chan gets $::tlshl l} len] || [chan eof $::tlshl])} { |
| 493 |
# copy as much of stderr as possible to ::err_log |
| 494 |
catch {read_err_tempfile ; chan close $::err} |
| 495 |
if [chan eof $::tlshl] { |
| 496 |
catch {chan close $::tlshl} |
| 497 |
unset -nocomplain ::tlshl |
| 498 |
unset -nocomplain ::err |
| 499 |
set ::perlpid 0 |
| 500 |
set ::done_waiting 1 |
| 501 |
} else { |
| 502 |
#do_debug "read_line: failing to read " |
| 503 |
puts stderr "Read failure; tlmgr command was $::last_cmd" |
| 504 |
# note. the normal way to terminate is terminating the GUI shell. |
| 505 |
# This closes stdin of tlmgr shell. |
| 506 |
err_exit |
| 507 |
} |
| 508 |
} elseif {$len >= 0} { |
| 509 |
# do_debug "read: $l" |
| 510 |
if $::ddebug {puts $::flid $l} |
| 511 |
if {[string first $::prmpt $l] == 0} { |
| 512 |
# prompt line: we are done with the current command |
| 513 |
total_dis_enable 1 ; # this may have to be redone later |
| 514 |
# catch up with stderr |
| 515 |
read_err_tempfile |
| 516 |
if $::show_output { |
| 517 |
do_debug "prompt found, $l" |
| 518 |
log_widget_finish |
| 519 |
} |
| 520 |
# for vwait: |
| 521 |
set ::done_waiting 1 |
| 522 |
set ::show_output 0 |
| 523 |
} else { |
| 524 |
# regular output |
| 525 |
lappend ::out_log $l |
| 526 |
if $::show_output { |
| 527 |
log_widget_add $l |
| 528 |
} |
| 529 |
} |
| 530 |
} |
| 531 |
} ; # read_line |
| 532 |
|
| 533 |
# copy error strings to error page in logs dialog .tllg and send it to top. |
| 534 |
# This by itself does not map the logs dialog .tllg |
| 535 |
|
| 536 |
proc show_err_log {} { |
| 537 |
#do_debug "show_err_log" |
| 538 |
.tllg.err.tx configure -state normal |
| 539 |
.tllg.err.tx delete 1.0 end |
| 540 |
if {[llength $::err_log] > 0} { |
| 541 |
foreach l $::err_log {.tllg.err.tx insert end "$l\n"} |
| 542 |
.tllg.err.tx yview moveto 1 |
| 543 |
.tllg.logs select .tllg.err |
| 544 |
} |
| 545 |
if {$::tcl_platform(os) ne "Darwin"} { |
| 546 |
# os x: text widget disabled => no selection possible |
| 547 |
.tllg.err.tx configure -state disabled |
| 548 |
} |
| 549 |
} ; # show_err_log |
| 550 |
|
| 551 |
proc log_widget_init {} { |
| 552 |
show_logs ; # create the logs dialog |
| 553 |
set ::busy [__ "Running"] |
| 554 |
.tllg.close state disabled |
| 555 |
} |
| 556 |
|
| 557 |
proc log_widget_add l { |
| 558 |
.tllg.log.tx configure -state normal |
| 559 |
.tllg.log.tx insert end "$l\n" |
| 560 |
if {$::tcl_platform(os) ne "Darwin"} { |
| 561 |
.tllg.log.tx configure -state disabled |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
proc log_widget_finish {} { |
| 566 |
.tllg.log.tx yview moveto 1 |
| 567 |
.tllg.logs select .tllg.log |
| 568 |
# error log on top if it contains anything |
| 569 |
show_err_log |
| 570 |
if {$::tcl_platform(os) ne "Darwin"} { |
| 571 |
.tllg.log.tx configure -state disabled |
| 572 |
} |
| 573 |
set ::busy [__ "Idle"] |
| 574 |
.tllg.close state !disabled |
| 575 |
bind .tllg <Escape> {.tllg.close invoke} |
| 576 |
} |
| 577 |
|
| 578 |
##### running tlmgr commands ##### |
| 579 |
|
| 580 |
# run a list of commands |
| 581 |
proc run_cmds {cmds {show 0}} { |
| 582 |
set ::show_output $show |
| 583 |
do_debug "run_cmds \"$cmds\"" |
| 584 |
if $::ddebug {puts $::flid "\n$cmds"} |
| 585 |
set ::out_log {} |
| 586 |
set ::err_log {} |
| 587 |
if $show { |
| 588 |
show_logs |
| 589 |
.tllg.status configure -text [__ "Running"] |
| 590 |
.tllg.close state disabled |
| 591 |
} |
| 592 |
set l [llength $cmds] |
| 593 |
for {set i 0} {$i<$l} {incr i} { |
| 594 |
if {! [info exists ::tlshl]} { |
| 595 |
err_exit "Back end gone. Last command: \n $::last_cmd" |
| 596 |
} |
| 597 |
set cmd [lindex $cmds $i] |
| 598 |
set ::last_cmd $cmd |
| 599 |
unset -nocomplain ::done_waiting |
| 600 |
# disable widgets for each new command, |
| 601 |
# since read_line will re-enable them |
| 602 |
# when a particular command is finished |
| 603 |
total_dis_enable 0 |
| 604 |
chan puts $::tlshl $cmd |
| 605 |
chan flush $::tlshl |
| 606 |
if {$i < [expr {$l-1}]} {vwait ::done_waiting} |
| 607 |
} |
| 608 |
} ; # run_cmds |
| 609 |
|
| 610 |
# run a single command |
| 611 |
proc run_cmd {cmd {show 0}} { |
| 612 |
run_cmds [list $cmd] $show |
| 613 |
} ; # run_cmd |
| 614 |
|
| 615 |
proc run_cmd_waiting {cmd} { |
| 616 |
run_cmd $cmd 0 |
| 617 |
vwait ::done_waiting |
| 618 |
} ; # run_cmd_waiting |
| 619 |
|
| 620 |
##### Handling package info ##### |
| 621 |
|
| 622 |
# what invokes what? |
| 623 |
# The main 'globals' are (excepting dicts and arrays): |
| 624 |
|
| 625 |
# ::have_remote is initialized to false. It is set to true by |
| 626 |
# get_packages_info_remote, and remains true except temporarily at |
| 627 |
# a change of repository. |
| 628 |
|
| 629 |
# The other globals ones are ::n_updates, ::need_update_tlmgr and |
| 630 |
# ::tlshell_updatable. These are initially set to 0 and re-calculated |
| 631 |
# by update_globals. |
| 632 |
|
| 633 |
# update_globals is invoked by get_packages_info_remote and |
| 634 |
# update_local_revnumbers. It enables and disables buttons as appropriate. |
| 635 |
|
| 636 |
# displayed global status info is updated by update_globals. |
| 637 |
# update button/menu states are set at initialization and updated |
| 638 |
# by update_globals, both via the selective_dis_enable proc |
| 639 |
|
| 640 |
# The repositories play a small part in this front end. Tlmgr mostly works |
| 641 |
# with a virtual repository, which is the combined set of repositories, |
| 642 |
# with pinning applied if there is more than one repository. |
| 643 |
# But get_packages_info_remote must invoke |
| 644 |
# show_repos to display updated verification info. |
| 645 |
# show_repos is also invoked by initialize. |
| 646 |
|
| 647 |
# get_packages_info_local is invoked only once, at initialization. After |
| 648 |
# installations and removals, the collected information is updated by |
| 649 |
# update_local_revnumbers. |
| 650 |
# Both procs also invoke get_platforms |
| 651 |
|
| 652 |
# get_packages_info_remote should be invoked before collect_filtered if |
| 653 |
# ::have_remote is false. Afterwards, ::have_remote will be true. |
| 654 |
# There will be no need to invoke get_packages_info_remote again except |
| 655 |
# at a change of repository by repos_commit. |
| 656 |
# get_packages_info_remote invokes update_globals, show_repos |
| 657 |
# and get_platforms. |
| 658 |
|
| 659 |
# update_local_revnumbers will be invoked after any updates. It also |
| 660 |
# invokes update_globals. |
| 661 |
|
| 662 |
# collect_filtered does not only filter, but also organize the |
| 663 |
# information to be displayed. It invokes display_packages_info. |
| 664 |
# It is invoked at initialization, when filtering options change and |
| 665 |
# at the end of install-, remove- and update procs. |
| 666 |
|
| 667 |
# display_packages_info is mostly invoked by collect_filtered, but |
| 668 |
# also when the search term or the search option changes. |
| 669 |
|
| 670 |
proc is_updatable {nm} { |
| 671 |
set pk [dict get $::pkgs $nm] |
| 672 |
set lr [dict get $pk localrev] |
| 673 |
set rr [dict get $pk remoterev] |
| 674 |
return [expr {$lr > 0 && $rr > 0 && $rr > $lr}] |
| 675 |
} |
| 676 |
|
| 677 |
proc display_updated_globals {} { |
| 678 |
if {$::have_remote && $::need_update_tlmgr} { |
| 679 |
.topfll.luptodate configure -text [__ "Needs updating"] |
| 680 |
} elseif $::have_remote { |
| 681 |
.topfll.luptodate configure -text [__ "Up to date"] |
| 682 |
} else { |
| 683 |
.topfll.luptodate configure -text [__ "Unknown"] |
| 684 |
} |
| 685 |
# ... and status of update buttons |
| 686 |
selective_dis_enable |
| 687 |
} |
| 688 |
|
| 689 |
proc update_globals {} { |
| 690 |
if {! $::have_remote} return |
| 691 |
set ::n_updates 0 |
| 692 |
foreach nm [dict keys $::pkgs] { |
| 693 |
if [is_updatable $nm] {incr ::n_updates} |
| 694 |
} |
| 695 |
set ::need_update_tlmgr [is_updatable texlive.infra] |
| 696 |
set ::tlshell_updatable [is_updatable tlshell] |
| 697 |
|
| 698 |
# also update displayed status info |
| 699 |
display_updated_globals |
| 700 |
} |
| 701 |
|
| 702 |
# The package display treeview widget in the main window has columns |
| 703 |
# for both local and remote revision numbers. |
| 704 |
# It gets its data from $::filtered rather than directly from $::pkgs. |
| 705 |
# ::pkgs should already be up to date. |
| 706 |
|
| 707 |
# I added a field 'marked' to ::pkgs. It is displayed in the first treeview |
| 708 |
# column. This looks better than the treeview tag facilities. |
| 709 |
# In ::pkgs, 'marked' is represented as a boolean. |
| 710 |
# In ::filtered and .pkglist they are represented as unicode symbols. |
| 711 |
|
| 712 |
# display packages obeying both filter and search string. |
| 713 |
# even on a relatively slow system, regenerating .pkglist from ::filtered |
| 714 |
# at every keystroke is acceptably responsive. |
| 715 |
# with future more advanced search options, this scheme may not suffice. |
| 716 |
|
| 717 |
proc display_packages_info {} { |
| 718 |
# do_debug [get_stacktrace] |
| 719 |
set curr [.pkfilter.search_e get] |
| 720 |
.pkglist delete [.pkglist children {}] |
| 721 |
dict for {nm pk} $::filtered { |
| 722 |
set do_show 0 |
| 723 |
if {$curr eq ""} { |
| 724 |
# empty search string |
| 725 |
set do_show 1 |
| 726 |
} elseif {[search_nocase $curr $nm] >= 0} { |
| 727 |
set do_show 1 |
| 728 |
} elseif {$::search_desc && \ |
| 729 |
[search_nocase $curr [dict get $::pkgs $nm shortdesc]] >= 0} { |
| 730 |
set do_show 1 |
| 731 |
} |
| 732 |
if $do_show { |
| 733 |
.pkglist insert {} end -id $nm -values $pk |
| 734 |
} |
| 735 |
} |
| 736 |
} ; # display_packages_info |
| 737 |
|
| 738 |
proc for_other_platform {nm} { |
| 739 |
set r [string last "." $nm] |
| 740 |
if {$r < 0} { |
| 741 |
return 0 |
| 742 |
} else { |
| 743 |
set n [string range $nm 0 [expr {$r-1}]] |
| 744 |
set p [string range $nm [expr {$r+1}] end] |
| 745 |
# p a platform identifier of an installed platform? |
| 746 |
if [dict exists $::platforms $p] { |
| 747 |
return [expr {! [dict get $::platforms $p "cur"]}] |
| 748 |
} else { |
| 749 |
return 0 |
| 750 |
} |
| 751 |
} |
| 752 |
} |
| 753 |
|
| 754 |
# (re)create ::filtered dictionary; disregard search string in selection |
| 755 |
# The value associated with each key/package is a list, not another dict. |
| 756 |
proc collect_filtered {} { |
| 757 |
do_debug \ |
| 758 |
"collect_filtered for $::stat_opt and $::dtl_opt" |
| 759 |
if {$::stat_opt ne "inst" && ! $::have_remote} { |
| 760 |
# have_remote should have been ensured when changing stat_opt from inst |
| 761 |
err_exit "collect_filtered should not have been invoked at this time" |
| 762 |
} |
| 763 |
foreach nm [dict keys $::filtered] { |
| 764 |
dict unset ::filtered $nm |
| 765 |
} |
| 766 |
foreach nm [lsort [dict keys $::pkgs]] { |
| 767 |
# do not list packages for platforms which are not installed |
| 768 |
if [for_other_platform $nm] continue |
| 769 |
set pk [dict get $::pkgs $nm] |
| 770 |
set do_show 1 |
| 771 |
set mrk [mark_sym [dict get $pk marked]] |
| 772 |
set lr [dict get $pk localrev] |
| 773 |
set rr [dict get $pk remoterev] |
| 774 |
set ct [dict get $pk category] |
| 775 |
if {$::stat_opt eq "inst" && $lr == 0} { |
| 776 |
set do_show 0 |
| 777 |
} elseif {$::stat_opt eq "notins" && $lr > 0} { |
| 778 |
set do_show 0 |
| 779 |
} elseif {$::stat_opt eq "upd" && ($lr == 0 || $rr == 0 || $rr <= $lr)} { |
| 780 |
set do_show 0 |
| 781 |
} |
| 782 |
if {! $do_show} continue |
| 783 |
if {$::dtl_opt eq "schm" && $ct ne "Scheme"} { |
| 784 |
set do_show 0 |
| 785 |
} elseif {$::dtl_opt eq "coll" && \ |
| 786 |
$ct ne "Scheme" && $ct ne "Collection"} { |
| 787 |
set do_show 0 |
| 788 |
} |
| 789 |
if {! $do_show} continue |
| 790 |
|
| 791 |
# collect data to be displayed for $nm |
| 792 |
dict lappend ::filtered $nm $mrk |
| 793 |
dict lappend ::filtered $nm $nm |
| 794 |
set v [dict get $pk localrev] |
| 795 |
set lv [dict get $pk lcatv] |
| 796 |
if {$v eq "0" || $v == 0} { |
| 797 |
set v "" ; # can this happen? |
| 798 |
} elseif {$lv != 0 && $lv ne ""} { |
| 799 |
set v "$v ($lv)" |
| 800 |
} |
| 801 |
dict lappend ::filtered $nm $v |
| 802 |
set v [dict get $pk remoterev] |
| 803 |
set rv [dict get $pk rcatv] |
| 804 |
if {$v eq "0" || $v == 0} { |
| 805 |
set v "" |
| 806 |
} elseif {$rv != 0 && $rv ne ""} { |
| 807 |
set v "$v ($rv)" |
| 808 |
} |
| 809 |
dict lappend ::filtered $nm $v |
| 810 |
dict lappend ::filtered $nm [dict get $pk shortdesc] |
| 811 |
} |
| 812 |
} ; # collect_filtered |
| 813 |
|
| 814 |
proc collect_and_display_filtered {} { |
| 815 |
collect_filtered |
| 816 |
display_packages_info |
| 817 |
} |
| 818 |
|
| 819 |
proc get_platforms {} { |
| 820 |
# guarantee fresh start |
| 821 |
foreach k $::platforms {dict unset ::platforms $k} |
| 822 |
set ::platforms [dict create] |
| 823 |
# find binary packages for pdftex; 'platform list' not available on windows |
| 824 |
foreach k [dict keys $::pkgs {pdftex.*}] { |
| 825 |
# {pdftex.*} is a glob pattern, not a regexp: '.' is a literal |
| 826 |
set plname [string range $k 7 end] |
| 827 |
if {[dict get $::pkgs $k localrev] > 0} { |
| 828 |
dict set ::platforms $plname "cur" 1 |
| 829 |
#dict set ::platforms $plname "fut" 1 |
| 830 |
} else { |
| 831 |
dict set ::platforms $plname "cur" 0 |
| 832 |
#dict set ::platforms $plname "fut" 0 |
| 833 |
} |
| 834 |
} |
| 835 |
} |
| 836 |
|
| 837 |
# get fresh package list. invoked at program start |
| 838 |
# some local packages may not be available online. |
| 839 |
# to test, create local dual-platform installation from dvd, try to update |
| 840 |
# from more recent linux-only installation |
| 841 |
|
| 842 |
proc get_packages_info_local {} { |
| 843 |
# start from scratch; see also update_local_revnumbers |
| 844 |
foreach nm [dict keys $::pkgs] { |
| 845 |
dict unset ::pkgs $nm |
| 846 |
} |
| 847 |
set ::have_remote 0 |
| 848 |
set ::need_update_tlmgr 0 |
| 849 |
set ::updatable 0 |
| 850 |
set ::tlshell_updatable 0 |
| 851 |
|
| 852 |
run_cmd_waiting \ |
| 853 |
"info --only-installed --data name,localrev,cat-version,category,shortdesc" |
| 854 |
set re {^([^,]+),([0-9]+),([^,]*),([^,]*),(.*)$} |
| 855 |
foreach l $::out_log { |
| 856 |
if [regexp $re $l m nm lrev lcatv catg pdescr] { |
| 857 |
# double-quotes in short description: remove outer, unescape inner |
| 858 |
if {[string index $pdescr 0] eq "\""} { |
| 859 |
set pdescr [string range $pdescr 1 end-1] |
| 860 |
} |
| 861 |
set pdescr [string map {\\\" \"} $pdescr] |
| 862 |
dict set ::pkgs $nm \ |
| 863 |
[list "marked" 0 "localrev" $lrev "lcatv" $lcatv "remoterev" 0 \ |
| 864 |
"rcatv" 0 "category" $catg shortdesc $pdescr] |
| 865 |
} |
| 866 |
} |
| 867 |
get_platforms |
| 868 |
} ; # get_packages_info_local |
| 869 |
|
| 870 |
proc abort_load {} { |
| 871 |
# try to close back end forcibly |
| 872 |
catch {chan close $::tlshl} |
| 873 |
if {$::tcl_platform(platform) eq "windows"} { |
| 874 |
catch {exec -ignorestderr taskkill /pid $::perlpid /t /f} |
| 875 |
} else { |
| 876 |
catch {exec -ignorestderr kill -9 $::perlpid} |
| 877 |
# should also be ok for darwin |
| 878 |
} |
| 879 |
# start new tlshell process |
| 880 |
exec $::progname & |
| 881 |
|
| 882 |
# end current tlshell process nicely |
| 883 |
exit |
| 884 |
# kill current tlshell process forcibly if necessary |
| 885 |
if {$::tcl_platform(platform) eq "windows"} { |
| 886 |
catch {exec -ignorestderr taskkill /pid [pid] /t /f} |
| 887 |
} else { |
| 888 |
catch {exec -ignorestderr kill -9 [pid]} |
| 889 |
} |
| 890 |
} ; # abort load |
| 891 |
|
| 892 |
# toplevel with abort button in case loading of a repository takes too long. |
| 893 |
# it can be closed when loading finishes |
| 894 |
proc splash_loading {} { |
| 895 |
|
| 896 |
create_dlg .loading . |
| 897 |
|
| 898 |
wm title .loading [__ "Loading"] |
| 899 |
|
| 900 |
# wallpaper |
| 901 |
pack [ttk::frame .loading.bg -padding 3p] -fill both -expand 1 |
| 902 |
|
| 903 |
set lbl [__ \ |
| 904 |
"If loading takes too long, press Abort and choose another repository."] |
| 905 |
append lbl "\n([__ "Options"] \/ [__ "Repositories"] ...)" |
| 906 |
ppack [ttk::label .loading.l0 -text $lbl \ |
| 907 |
-wraplength [expr {60*$::cw}] -justify left] \ |
| 908 |
-in .loading.bg -anchor w |
| 909 |
|
| 910 |
pack [ttk::frame .loading.tfr] -in .loading.bg -expand 1 -fill x |
| 911 |
pack [ttk::scrollbar .loading.scroll -command ".loading.tx yview"] \ |
| 912 |
-in .loading.tfr -side right -fill y |
| 913 |
ppack [text .loading.tx -height 5 -wrap word \ |
| 914 |
-yscrollcommand ".loading.scroll set"] \ |
| 915 |
-in .loading.tfr -expand 1 -fill both |
| 916 |
pack [ttk::frame .loading.buttons] -in .loading.bg -expand 1 -fill x |
| 917 |
ttk::button .loading.close -text [__ "Close"] -command {end_dlg "" .loading} |
| 918 |
ppack .loading.close -in .loading.buttons -side right |
| 919 |
.loading.close configure -state disabled |
| 920 |
ttk::button .loading.abo -text [__ "Abort"] -command abort_load |
| 921 |
ppack .loading.abo -in .loading.buttons -side right |
| 922 |
wm protocol .loading {cancel_or_destroy .loading.abo .loading} |
| 923 |
wm resizable .loading 0 0 |
| 924 |
place_dlg .loading . |
| 925 |
} ; # splash_loading |
| 926 |
|
| 927 |
|
| 928 |
proc track_err {} { |
| 929 |
set inx0 [llength $::err_log] |
| 930 |
read_err_tempfile |
| 931 |
.loading.tx configure -state normal |
| 932 |
for {set i $inx0} {$i < [llength $::err_log]} {incr i} { |
| 933 |
.loading.tx insert end "[lindex $::err_log $i]\n" |
| 934 |
} |
| 935 |
.loading.tx configure -state disabled |
| 936 |
update idletasks |
| 937 |
if {![info exists ::loaded]} { |
| 938 |
after 500 track_err |
| 939 |
} else { |
| 940 |
.loading.close state !disabled |
| 941 |
.loading.abo state disabled |
| 942 |
.loading.tx configure -state normal |
| 943 |
.loading.tx insert end [__ "Done loading"] |
| 944 |
.loading.tx configure -state disabled |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
# remote: preserve information on installed packages |
| 949 |
proc get_packages_info_remote {} { |
| 950 |
# remove non-local database entries |
| 951 |
foreach k [dict keys $::pkgs] { |
| 952 |
if {! [dict get $::pkgs $k localrev]} { |
| 953 |
dict unset ::pkgs $k |
| 954 |
} |
| 955 |
} |
| 956 |
set ::need_update_tlmgr 0 |
| 957 |
set ::updatable 0 |
| 958 |
set ::tlshell_updatable 0 |
| 959 |
|
| 960 |
splash_loading |
| 961 |
|
| 962 |
unset -nocomplain ::loaded |
| 963 |
track_err |
| 964 |
set catv "rcat-version" |
| 965 |
|
| 966 |
if [catch {run_cmd \ |
| 967 |
"info --data name,remoterev,$catv,category,shortdesc"}] { |
| 968 |
do_debug [get_stacktrace] |
| 969 |
tk_messageBox -message [__ "A configured repository is unavailable."] |
| 970 |
return 0 |
| 971 |
} |
| 972 |
vwait ::done_waiting |
| 973 |
set ::loaded 1 |
| 974 |
set re {^([^,]+),([0-9]+),([^,]*),([^,]*),(.*)$} |
| 975 |
foreach l $::out_log { |
| 976 |
if [regexp $re $l m nm rrev rcatv catg pdescr] { |
| 977 |
# double-quotes in short description: remove outer, unescape inner |
| 978 |
if {[string index $pdescr 0] eq "\""} { |
| 979 |
set pdescr [string range $pdescr 1 end-1] |
| 980 |
} |
| 981 |
set pdescr [string map {\\\" \"} $pdescr] |
| 982 |
if [catch {dict get $::pkgs $nm} pk] { |
| 983 |
# package entry does not yet exist, create it |
| 984 |
dict set ::pkgs $nm [list "marked" 0 "localrev" 0 "lcatv" 0] |
| 985 |
} |
| 986 |
dict set ::pkgs $nm "remoterev" $rrev |
| 987 |
dict set ::pkgs $nm "rcatv" $rcatv |
| 988 |
dict set ::pkgs $nm "category" $catg |
| 989 |
dict set ::pkgs $nm "shortdesc" $pdescr |
| 990 |
} |
| 991 |
} |
| 992 |
get_platforms ; # derive from $::pkgs |
| 993 |
|
| 994 |
set ::have_remote 1 |
| 995 |
update_globals |
| 996 |
show_repos |
| 997 |
return 1 |
| 998 |
} ; # get_packages_info_remote |
| 999 |
|
| 1000 |
## update ::pkgs after installing packages without going online again. |
| 1001 |
proc update_local_revnumbers {} { |
| 1002 |
do_debug "update_local_revnumbers" |
| 1003 |
run_cmd_waiting "info --only-installed --data name,localrev,lcat-version" |
| 1004 |
set re {^([^,]+),([0-9]+),(.*)$} |
| 1005 |
dict for {pk pk_dict} $::pkgs { |
| 1006 |
do_debug "zeroing local data for $pk" |
| 1007 |
dict set pk_dict "localrev" 0 |
| 1008 |
dict set pk_dict "lcatv" 0 |
| 1009 |
dict set ::pkgs $pk $pk_dict |
| 1010 |
} |
| 1011 |
foreach l $::out_log { |
| 1012 |
if [regexp $re $l m pk lr lv] { |
| 1013 |
set pk_dict [dict get $::pkgs $pk] |
| 1014 |
dict set pk_dict "localrev" $lr |
| 1015 |
dict set pk_dict "lcatv" $lv |
| 1016 |
dict set pk_dict "rcatv" $lv |
| 1017 |
dict set ::pkgs $pk $pk_dict |
| 1018 |
} |
| 1019 |
} |
| 1020 |
get_platforms |
| 1021 |
update_globals |
| 1022 |
} ; # update_local_revnumbers |
| 1023 |
|
| 1024 |
##### Logs notebook ############################## |
| 1025 |
|
| 1026 |
# if invoked via run_cmds, it tracks progress of (a) tlmgr command(s). |
| 1027 |
# run_cmds will temporarily disable the close button |
| 1028 |
# and set .tllg.status to busy via total_dis_enable 0. |
| 1029 |
# otherwise, it shows the output of the last completed (list of) command(s). |
| 1030 |
|
| 1031 |
# Note that run_cmds clears ::out_log and ::err_log, but not ::dbg_log. |
| 1032 |
|
| 1033 |
proc show_logs {} { |
| 1034 |
create_dlg .tllg . |
| 1035 |
wm title .tllg Logs |
| 1036 |
|
| 1037 |
# wallpaper |
| 1038 |
pack [ttk::frame .tllg.bg] -fill both -expand 1 |
| 1039 |
|
| 1040 |
# close button and busy label |
| 1041 |
pack [ttk::frame .tllg.bottom] -in .tllg.bg -side bottom -fill x |
| 1042 |
ttk::button .tllg.close -text [__ "Close"] -command {end_dlg 0 .tllg} |
| 1043 |
ppack .tllg.close -in .tllg.bottom -side right -anchor e |
| 1044 |
ppack [ttk::label .tllg.status -textvariable ::busy -anchor w] \ |
| 1045 |
-in .tllg.bottom -side left |
| 1046 |
bind .tllg <Escape> {.tllg.close invoke} |
| 1047 |
wm protocol .tllg WM_DELETE_WINDOW \ |
| 1048 |
{cancel_or_destroy .tllg.close .tllg} |
| 1049 |
|
| 1050 |
# notebook pages and scrollbars |
| 1051 |
ttk::frame .tllg.log |
| 1052 |
pack [ttk::scrollbar .tllg.log.scroll -command ".tllg.log.tx yview"] \ |
| 1053 |
-side right -fill y |
| 1054 |
ppack [text .tllg.log.tx -height 10 -wrap word \ |
| 1055 |
-yscrollcommand ".tllg.log.scroll set"] \ |
| 1056 |
-expand 1 -fill both |
| 1057 |
.tllg.log.tx configure -state normal |
| 1058 |
foreach l $::out_log { |
| 1059 |
.tllg.log.tx insert end "$l\n" |
| 1060 |
} |
| 1061 |
if {$::tcl_platform(os) ne "Darwin"} {.tllg.log.tx configure -state disabled} |
| 1062 |
.tllg.log.tx yview moveto 1 |
| 1063 |
|
| 1064 |
ttk::frame .tllg.err |
| 1065 |
pack [ttk::scrollbar .tllg.err.scroll -command ".tllg.err.tx yview"] \ |
| 1066 |
-side right -fill y |
| 1067 |
ppack [text .tllg.err.tx -height 10 -wrap word \ |
| 1068 |
-yscrollcommand ".tllg.err.scroll set"] \ |
| 1069 |
-expand 1 -fill both |
| 1070 |
.tllg.err.tx configure -state normal |
| 1071 |
foreach l $::err_log { |
| 1072 |
.tllg.err.tx configure -state normal |
| 1073 |
.tllg.err.tx insert end "$l\n" |
| 1074 |
} |
| 1075 |
if {$::tcl_platform(os) ne "Darwin"} {.tllg.err.tx configure -state disabled} |
| 1076 |
.tllg.err.tx yview moveto 1 |
| 1077 |
|
| 1078 |
if $::ddebug { |
| 1079 |
ttk::frame .tllg.dbg |
| 1080 |
pack [ttk::scrollbar .tllg.dbg.scroll -command ".tllg.dbg.tx yview"] \ |
| 1081 |
-side right -fill y |
| 1082 |
ppack [text .tllg.dbg.tx -height 10 -bd 2 -relief groove -wrap word \ |
| 1083 |
-yscrollcommand ".tllg.dbg.scroll set"] \ |
| 1084 |
-expand 1 -fill both |
| 1085 |
.tllg.dbg.tx configure -state normal |
| 1086 |
foreach l $::dbg_log { |
| 1087 |
.tllg.dbg.tx insert end "$l\n" |
| 1088 |
} |
| 1089 |
if {$::tcl_platform(os) ne "Darwin"} { |
| 1090 |
.tllg.dbg.tx configure -state disabled |
| 1091 |
} |
| 1092 |
.tllg.dbg.tx yview moveto 1 |
| 1093 |
} |
| 1094 |
|
| 1095 |
# collect pages in notebook widget |
| 1096 |
pack [ttk::notebook .tllg.logs] -in .tllg.bg -side top -fill both -expand 1 |
| 1097 |
.tllg.logs add .tllg.log -text [__ "Output"] |
| 1098 |
.tllg.logs add .tllg.err -text [__ "Other"] |
| 1099 |
if $::ddebug { |
| 1100 |
.tllg.logs add .tllg.dbg -text "Debug" |
| 1101 |
raise .tllg.dbg .tllg.logs |
| 1102 |
} |
| 1103 |
raise .tllg.err .tllg.logs |
| 1104 |
raise .tllg.log .tllg.logs |
| 1105 |
|
| 1106 |
# default resizable |
| 1107 |
place_dlg .tllg . |
| 1108 |
} ; # show_logs |
| 1109 |
|
| 1110 |
##### repositories ############################################### |
| 1111 |
|
| 1112 |
### mirrors |
| 1113 |
#mangle_name {n} {} ; moved to tltcl.tcl |
| 1114 |
#proc read_mirrors {} {} ; moved to tltcl.tcl |
| 1115 |
|
| 1116 |
proc pick_local_repo {} { |
| 1117 |
set nw_repo [.tlr.cur cget -text] |
| 1118 |
if {! [file isdirectory $nw_repo]} { |
| 1119 |
set nw_repo $::env(HOME) ; # HOME also o.k. for windows |
| 1120 |
} |
| 1121 |
while 1 { |
| 1122 |
set nw_repo [browse4dir $nw_repo .tlr] |
| 1123 |
if {$nw_repo ne "" && ! [possible_repository $nw_repo]} { |
| 1124 |
tk_messageBox -message [__ "%s not a repository" $nw_repo] -parent .tlr |
| 1125 |
continue |
| 1126 |
} else { |
| 1127 |
.tlr.save state !disabled |
| 1128 |
break |
| 1129 |
} |
| 1130 |
} |
| 1131 |
if {$nw_repo ne ""} { |
| 1132 |
.tlr.new delete 0 end |
| 1133 |
.tlr.new insert end $nw_repo |
| 1134 |
} |
| 1135 |
} ; # pick_local_repo |
| 1136 |
|
| 1137 |
proc get_repos_from_tlmgr {} { |
| 1138 |
array unset ::repos |
| 1139 |
run_cmd_waiting "option repository" |
| 1140 |
set rps "" |
| 1141 |
foreach l $::out_log { |
| 1142 |
if [regexp {repository\t(.*)$} $l dum rps] break |
| 1143 |
} |
| 1144 |
if {$rps ne ""} { |
| 1145 |
set reps [split $rps " "] |
| 1146 |
set nr [llength $reps] |
| 1147 |
foreach rp $reps { |
| 1148 |
# decode spaces and % |
| 1149 |
set rp [string map {"%20" " "} $rp] |
| 1150 |
set rp [string map {"%25" "%"} $rp] |
| 1151 |
if {! [regexp {^(.+)#(.+)$} $rp dum r t]} { |
| 1152 |
# no tag; use repository as its own tag |
| 1153 |
set r $rp |
| 1154 |
set t $rp |
| 1155 |
} |
| 1156 |
if {$nr == 1} { |
| 1157 |
set t "main" |
| 1158 |
} |
| 1159 |
set ::repos($t) $r |
| 1160 |
} |
| 1161 |
if {"main" ni [array names ::repos]} { |
| 1162 |
array unset ::repos |
| 1163 |
} |
| 1164 |
} |
| 1165 |
}; # get_repos_from_tlmgr |
| 1166 |
|
| 1167 |
proc set_repos_in_tlmgr {} { |
| 1168 |
# tlmgr has no command to replace a single repository; |
| 1169 |
# we need to compose a string for opt_location ourselves from $::repos. |
| 1170 |
# a single repository should not get a tag. |
| 1171 |
# apparently, we can safely ignore bogus pinning data. |
| 1172 |
set nr [array size ::repos] |
| 1173 |
set opt_repos "" |
| 1174 |
set rp "" |
| 1175 |
foreach nm [array names ::repos] { |
| 1176 |
if {$nr==1} { |
| 1177 |
if {$nm ne "main"} { |
| 1178 |
err_exit "Internal error" |
| 1179 |
} else { |
| 1180 |
# pinning command only supported for multiple repositories |
| 1181 |
set rp $::repos(main) |
| 1182 |
} |
| 1183 |
} else { |
| 1184 |
if {$nm eq $::repos($nm)} { |
| 1185 |
set rp $nm |
| 1186 |
} else { |
| 1187 |
set rp $::repos($nm) |
| 1188 |
append rp "#$nm" |
| 1189 |
} |
| 1190 |
} |
| 1191 |
# encode % and spaces |
| 1192 |
set rp [string map {"%" "%25"} $rp] |
| 1193 |
set rp [string map {" " "%20"} $rp] |
| 1194 |
append opt_repos " $rp" |
| 1195 |
} |
| 1196 |
run_cmd_waiting "repository set [string range $opt_repos 1 end]" |
| 1197 |
}; # set_repos_in_tlmgr |
| 1198 |
|
| 1199 |
proc show_repos {} { |
| 1200 |
# this proc lists the configured repository/ies |
| 1201 |
# in the upper left portion of the main window. |
| 1202 |
# it makes one call to the back end, but no need to go online. |
| 1203 |
set w .toprepo |
| 1204 |
foreach ch [winfo children $w] {destroy $ch} |
| 1205 |
set nms [array names ::repos] |
| 1206 |
set c [llength $nms] |
| 1207 |
grid [ttk::frame $w.repoheadframe] \ |
| 1208 |
-row 0 -column 0 -columnspan 3 -sticky w |
| 1209 |
pack [ttk::label $w.head -font hfont] \ |
| 1210 |
-in $w.repoheadframe -side left |
| 1211 |
pack [ttk::label $w.load -text ""] \ |
| 1212 |
-in $w.repoheadframe -side left -anchor sw |
| 1213 |
if {$c <= 0} { |
| 1214 |
$w.head configure -text [__ "No repositories"] |
| 1215 |
return |
| 1216 |
} elseif {$c == 1} { |
| 1217 |
$w.head configure -text [__ "Repository"] |
| 1218 |
} else { |
| 1219 |
$w.head configure -text [__ "Multiple repositories"] |
| 1220 |
} |
| 1221 |
if {! $::have_remote} { |
| 1222 |
$w.load configure -text " ([__ "Not loaded"])" |
| 1223 |
} |
| 1224 |
# the $::repos array already contains the configured repositories. |
| 1225 |
# 'repository status' adds verification info and actual selected mirror. |
| 1226 |
set repodict [dict create] |
| 1227 |
if $::have_remote { |
| 1228 |
run_cmd_waiting "repository status" |
| 1229 |
# a number code for verification status |
| 1230 |
set re {^(\S+) (\S+)/tlpkg/texlive.tlpdb (-?\d+) (.*)$} |
| 1231 |
foreach l $::out_log { |
| 1232 |
if [regexp $re $l dum nm rp n d] { |
| 1233 |
# dummy tag repository verification_code description |
| 1234 |
# restore spaces and percent characters in nm and rp |
| 1235 |
set nm [string map {"%20" " "} $nm] |
| 1236 |
set nm [string map {"%25" "%"} $nm] |
| 1237 |
set rp [string map {"%20" " "} $rp] |
| 1238 |
set rp [string map {"%25" "%"} $rp] |
| 1239 |
dict set repodict $nm "url" $rp |
| 1240 |
dict set repodict $nm "vericode" $n |
| 1241 |
dict set repodict $nm "veridescr" $d |
| 1242 |
} |
| 1243 |
} |
| 1244 |
# the selected mirror is needed in the win64 code, so is a global. |
| 1245 |
if {$::repos(main) eq $::any_mirror} { |
| 1246 |
set ::actual_main [dict get $repodict "main" "url"] |
| 1247 |
} else { |
| 1248 |
set ::actual_main $::repos(main) |
| 1249 |
} |
| 1250 |
} |
| 1251 |
set rw 0 |
| 1252 |
foreach nm [array names ::repos] { |
| 1253 |
incr rw |
| 1254 |
pgrid [ttk::label $w.u$nm -text $::repos($nm) -justify left] \ |
| 1255 |
-sticky nw -row $rw -column 0 |
| 1256 |
if {$::repos($nm) eq $::any_mirror && $::have_remote} { |
| 1257 |
$w.u$nm configure -text \ |
| 1258 |
"$::any_mirror\n[__ "Actual repository"]:\n$::actual_main" |
| 1259 |
} |
| 1260 |
if {[array size ::repos] > 1 && $nm ne $::repos($nm)} { |
| 1261 |
pgrid [ttk::label $w.n$nm -text "($nm)"] \ |
| 1262 |
-sticky nw -row $rw -column 1 |
| 1263 |
} |
| 1264 |
if $::have_remote { |
| 1265 |
pgrid [ttk::label $w.v$nm -text \ |
| 1266 |
"verification: [dict get $repodict $nm "veridescr"]"] \ |
| 1267 |
-sticky nw -row $rw -column 2 |
| 1268 |
} |
| 1269 |
} |
| 1270 |
} ; # show_repos |
| 1271 |
|
| 1272 |
proc repos_commit {} { |
| 1273 |
set changes 0 |
| 1274 |
# set repositories then add pinning if appropriate |
| 1275 |
set new_repo [forward_slashify [.tlr.new get]] |
| 1276 |
if {! [regexp {^\s*$} $new_repo]} { |
| 1277 |
# repository entry widget non-empty: use it |
| 1278 |
if {$::repos(main) ne $new_repo} { |
| 1279 |
set ::repos(main) $new_repo |
| 1280 |
set changes 1 |
| 1281 |
} |
| 1282 |
} |
| 1283 |
set had_contrib 0 |
| 1284 |
if $::toggle_contrib { |
| 1285 |
set changes 1 |
| 1286 |
foreach nm [array names ::repos] { |
| 1287 |
if {$::repos($nm) eq $::tlcontrib} { |
| 1288 |
set had_contrib 1 |
| 1289 |
run_cmds [list "pinning remove $nm --all" \ |
| 1290 |
"pinning remove $::repos($nm) --all"] 0 |
| 1291 |
vwait ::done_waiting |
| 1292 |
array unset ::repos $nm |
| 1293 |
} |
| 1294 |
} |
| 1295 |
if {! $had_contrib} { |
| 1296 |
set ::repos(tlcontrib) $::tlcontrib |
| 1297 |
} |
| 1298 |
} |
| 1299 |
if $changes { |
| 1300 |
set_repos_in_tlmgr |
| 1301 |
close_tlmgr |
| 1302 |
start_tlmgr |
| 1303 |
if {$::toggle_contrib && ! $had_contrib} { |
| 1304 |
run_cmd_waiting "pinning add tlcontrib \"*\"" |
| 1305 |
} |
| 1306 |
} |
| 1307 |
} ; # repos_commit |
| 1308 |
|
| 1309 |
proc dis_enable_reposave {} { |
| 1310 |
if [possible_repository [.tlr.new get]] { |
| 1311 |
.tlr.save state !disabled |
| 1312 |
} else { |
| 1313 |
.tlr.save state disabled |
| 1314 |
} |
| 1315 |
} |
| 1316 |
|
| 1317 |
proc save_load_repo {} { |
| 1318 |
repos_commit |
| 1319 |
end_dlg "" .tlr |
| 1320 |
# reload remote package information |
| 1321 |
set ::have_remote 0 |
| 1322 |
get_packages_info_remote |
| 1323 |
collect_and_display_filtered |
| 1324 |
} |
| 1325 |
|
| 1326 |
proc select_mir {m} { |
| 1327 |
.tlr.new delete 0 end; .tlr.new insert end $m |
| 1328 |
.tlr.save state !disabled |
| 1329 |
} |
| 1330 |
|
| 1331 |
# main repository dialog |
| 1332 |
proc repository_dialog {} { |
| 1333 |
|
| 1334 |
# dialog with |
| 1335 |
# - popup menu of mirrors (parse tlpkg/installer/ctan-mirrors.pl) |
| 1336 |
# - text entry box |
| 1337 |
# - directory browser button |
| 1338 |
# - ok and cancel buttons |
| 1339 |
|
| 1340 |
create_dlg .tlr . |
| 1341 |
wm title .tlr [__ "Main Repository"] |
| 1342 |
|
| 1343 |
# wallpaper frame; see populate_main |
| 1344 |
pack [ttk::frame .tlr.bg] -expand 1 -fill x |
| 1345 |
|
| 1346 |
pack [ttk::frame .tlr.info] -in .tlr.bg -expand 1 -fill x |
| 1347 |
grid columnconfigure .tlr.info 1 -weight 1 |
| 1348 |
set row -1 |
| 1349 |
|
| 1350 |
# current repository |
| 1351 |
incr row |
| 1352 |
pgrid [ttk::label .tlr.lcur -text [__ "Current:"]] \ |
| 1353 |
-in .tlr.info -row $row -column 0 -sticky w |
| 1354 |
pgrid [ttk::label .tlr.cur -text $::repos(main)] \ |
| 1355 |
-in .tlr.info -row 0 -column 1 -sticky w |
| 1356 |
# proposed new repository |
| 1357 |
incr row |
| 1358 |
pgrid [ttk::label .tlr.lnew -text [__ "New"]] \ |
| 1359 |
-in .tlr.info -row $row -column 0 -sticky w |
| 1360 |
pgrid [ttk::entry .tlr.new] \ |
| 1361 |
-in .tlr.info -row $row -column 1 -columnspan 2 -sticky ew |
| 1362 |
.tlr.new insert 0 $::repos(main) |
| 1363 |
bind .tlr.new <KeyRelease> dis_enable_reposave |
| 1364 |
|
| 1365 |
### three ways to specify a repository ### |
| 1366 |
pack [ttk::frame .tlr.mirbuttons] -in .tlr.bg -fill x |
| 1367 |
# 1. default remote repository |
| 1368 |
ttk::button .tlr.ctan -text [__ "Any CTAN mirror"] -command { |
| 1369 |
.tlr.new delete 0 end |
| 1370 |
.tlr.new insert end $::any_mirror |
| 1371 |
.tlr.save state !disabled |
| 1372 |
} |
| 1373 |
ppack .tlr.ctan -in .tlr.mirbuttons -side left -fill x |
| 1374 |
# 2. specific repository: create a cascading dropdown menu of mirrors |
| 1375 |
mirror_menu .tlr.mir select_mir |
| 1376 |
ppack .tlr.mir -in .tlr.mirbuttons -side left -fill x |
| 1377 |
# 3. local repository |
| 1378 |
ttk::button .tlr.browse -text [__ "Local directory..."] -command { |
| 1379 |
.tlr.new delete 0 end; .tlr.new insert end [pick_local_repo]} |
| 1380 |
ppack .tlr.browse -in .tlr.mirbuttons -side left -fill x |
| 1381 |
|
| 1382 |
### add/remove tlcontrib ### |
| 1383 |
ttk::label .tlr.contribt -text [__ "tlcontrib additional repository"] \ |
| 1384 |
-font bfont |
| 1385 |
pack .tlr.contribt -in .tlr.bg -anchor w -padx 3p -pady [list 10p 3p] |
| 1386 |
pack [ttk::label .tlr.contribl] -in .tlr.bg -anchor w -padx 3p -pady 3p |
| 1387 |
ttk::checkbutton .tlr.contribb -variable ::toggle_contrib |
| 1388 |
pack .tlr.contribb -in .tlr.bg -anchor w -padx 3p -pady [list 3p 10p] |
| 1389 |
set ::toggle_contrib 0 |
| 1390 |
set has_contrib 0 |
| 1391 |
foreach nm [array names ::repos] { |
| 1392 |
if {$::repos($nm) eq $::tlcontrib} { |
| 1393 |
set has_contrib 1 |
| 1394 |
set contrib_tag $nm |
| 1395 |
break |
| 1396 |
} |
| 1397 |
} |
| 1398 |
if $has_contrib { |
| 1399 |
.tlr.contribl configure -text [__ "tlcontrib repository is included"] |
| 1400 |
.tlr.contribb configure -text [__ "Remove tlcontrib repository"] |
| 1401 |
} else { |
| 1402 |
.tlr.contribl configure -text [__ "tlcontrib repository is not included"] |
| 1403 |
.tlr.contribb configure -text [__ "Add tlcontrib repository"] |
| 1404 |
} |
| 1405 |
|
| 1406 |
# two ways to close the dialog |
| 1407 |
pack [ttk::frame .tlr.closebuttons] -pady [list 10p 0p] -in .tlr.bg -fill x |
| 1408 |
ttk::button .tlr.save -text [__ "Save and Load"] -command save_load_repo |
| 1409 |
ppack .tlr.save -in .tlr.closebuttons -side right |
| 1410 |
dis_enable_reposave |
| 1411 |
ttk::button .tlr.cancel -text [__ "Cancel"] -command {end_dlg "" .tlr} |
| 1412 |
ppack .tlr.cancel -in .tlr.closebuttons -side right |
| 1413 |
bind .tlr <Escape> {.tlr.cancel invoke} |
| 1414 |
|
| 1415 |
wm protocol .tlr WM_DELETE_WINDOW \ |
| 1416 |
{cancel_or_destroy .tlr.cancel .tlr} |
| 1417 |
wm resizable .tlr 1 0 |
| 1418 |
place_dlg .tlr . |
| 1419 |
} ; # repository_dialog |
| 1420 |
|
| 1421 |
### platforms |
| 1422 |
|
| 1423 |
# ::platforms is a dictionary of dictionaries. |
| 1424 |
# each element dictionary has keys cur and fut indicating |
| 1425 |
# current and future status (i.e. being installed), |
| 1426 |
# with values 0 meaning 'not installed' and 1 meaning 'installed'. |
| 1427 |
# elsewhere, we shall only be interested in cur. |
| 1428 |
# within the treeview list, we shall use the usual unicode mark symbols. |
| 1429 |
|
| 1430 |
# for windows, there is no platforms menu entry, |
| 1431 |
# and the platforms dialog returns immediately, i.e. is a no-op. |
| 1432 |
|
| 1433 |
proc toggle_pl_marked {pl cl} { |
| 1434 |
# toggle_pl_marked is triggered by a mouse click only in column #1. |
| 1435 |
# 'fut'[ure] should get updated in ::platforms _and_ in .tlpl.pl. |
| 1436 |
|
| 1437 |
if {$cl ne "#1"} return |
| 1438 |
if {$pl eq $::our_platform} { |
| 1439 |
tk_messageBox -message \ |
| 1440 |
[__ "Cannot remove own platform %s" $::our_platform] -parent .tlpl |
| 1441 |
return |
| 1442 |
} |
| 1443 |
set m1 [expr {[dict get $::platforms $pl "fut"] ? 0 : 1}] |
| 1444 |
dict set ::platforms $pl "fut" $m1 |
| 1445 |
set m0 [dict get $::platforms $pl "cur"] |
| 1446 |
if {$m1 eq $m0} { |
| 1447 |
.tlpl.pl tag remove "changed" $pl |
| 1448 |
} else { |
| 1449 |
.tlpl.pl tag add "changed" $pl |
| 1450 |
} |
| 1451 |
.tlpl.pl set $pl "stat" [mark_sym $m1] |
| 1452 |
# any changes to apply? |
| 1453 |
.tlpl.do state disabled |
| 1454 |
dict for {pname pdict} $::platforms { |
| 1455 |
if {[dict get $pdict "fut"] ne [dict get $pdict "cur"]} { |
| 1456 |
.tlpl.do state !disabled |
| 1457 |
break |
| 1458 |
} |
| 1459 |
} |
| 1460 |
} ; # toggle_pl_marked |
| 1461 |
|
| 1462 |
proc platforms_commit {} { |
| 1463 |
set pl_add {} |
| 1464 |
set pl_remove {} |
| 1465 |
dict for {pname pdict} $::platforms { |
| 1466 |
if {[dict get $pdict "cur"] ne [dict get $pdict "fut"]} { |
| 1467 |
if {[dict get $pdict "fut"]} { |
| 1468 |
lappend pl_add $pname |
| 1469 |
} else { |
| 1470 |
lappend pl_remove $pname |
| 1471 |
} |
| 1472 |
} |
| 1473 |
} |
| 1474 |
if {[llength $pl_add] == 0 && [llength $pl_remove] == 0} return |
| 1475 |
set cmds {} |
| 1476 |
if {[llength $pl_add] > 0} { |
| 1477 |
set cmd "platform add " |
| 1478 |
append cmd [join $pl_add " "] |
| 1479 |
lappend cmds $cmd |
| 1480 |
} |
| 1481 |
if {[llength $pl_remove] > 0} { |
| 1482 |
set cmd "platform remove " |
| 1483 |
append cmd [join $pl_remove " "] |
| 1484 |
lappend cmds $cmd |
| 1485 |
} |
| 1486 |
run_cmds $cmds 1 |
| 1487 |
vwait ::done_waiting |
| 1488 |
update_local_revnumbers |
| 1489 |
collect_and_display_filtered |
| 1490 |
|
| 1491 |
} ; # platforms_commit |
| 1492 |
|
| 1493 |
# the platforms dialog |
| 1494 |
proc platforms_select {} { |
| 1495 |
if {$::tcl_platform(platform) eq "windows"} return |
| 1496 |
|
| 1497 |
create_dlg .tlpl |
| 1498 |
wm title .tlpl [__ "Platforms"] |
| 1499 |
if $::plain_unix {wm attributes .tlpl -type dialog} |
| 1500 |
|
| 1501 |
# wallpaper frame |
| 1502 |
pack [ttk::frame .tlpl.bg] -expand 1 -fill both |
| 1503 |
|
| 1504 |
# buttons |
| 1505 |
pack [ttk::frame .tlpl.but] -in .tlpl.bg -side bottom -fill x |
| 1506 |
ttk::button .tlpl.do -text [__ "Apply and close"] -command { |
| 1507 |
disable_dlg .tlpl |
| 1508 |
platforms_commit |
| 1509 |
end_dlg "" .tlpl |
| 1510 |
} |
| 1511 |
ttk::button .tlpl.dont -text [__ "Close"] -command \ |
| 1512 |
{end_dlg "" .tlpl} |
| 1513 |
ppack .tlpl.do -in .tlpl.but -side right |
| 1514 |
ppack .tlpl.dont -in .tlpl.but -side left |
| 1515 |
bind .tlpl <Escape> {.tlpl.dont invoke} |
| 1516 |
|
| 1517 |
pack [ttk::label .tlpl.bold -text [__ "Changed entries are bold"] \ |
| 1518 |
-font bfont] -in .tlpl.bg -side bottom |
| 1519 |
|
| 1520 |
# platforms treeview; do we need a scrollbar? |
| 1521 |
|
| 1522 |
pack [ttk::frame .tlpl.fpl] -in .tlpl.bg -fill both -expand 1 |
| 1523 |
ttk::treeview .tlpl.pl -columns {stat plat} -show headings \ |
| 1524 |
-height [dict size $::platforms] -yscrollcommand {.tlpl.plsb set} |
| 1525 |
ppack .tlpl.pl -in .tlpl.fpl -side left -fill both -expand 1 |
| 1526 |
ttk::scrollbar .tlpl.plsb -orient vertical \ |
| 1527 |
-command {.tlpl.pl yview} |
| 1528 |
ppack .tlpl.plsb -in .tlpl.fpl -side right -fill y -expand 1 |
| 1529 |
.tlpl.pl column stat -width [expr {$::cw * 3}] |
| 1530 |
.tlpl.pl heading plat -text [__ "platform"] -anchor w |
| 1531 |
.tlpl.pl column plat -width [expr {$::cw * 20}] |
| 1532 |
# tag for indicating changed entries |
| 1533 |
.tlpl.pl tag configure "changed" -font bfont |
| 1534 |
|
| 1535 |
dict for {pname pdict} $::platforms { |
| 1536 |
dict set ::platforms $pname "fut" [dict get $pdict "cur"] |
| 1537 |
} |
| 1538 |
foreach pname [lsort [dict keys $::platforms]] { |
| 1539 |
.tlpl.pl insert {} end -id $pname -values \ |
| 1540 |
[list [mark_sym [dict get $::platforms $pname "cur"]] $pname] |
| 1541 |
} |
| 1542 |
set_tree_col_width .tlpl.pl "plat" |
| 1543 |
|
| 1544 |
bind .tlpl.pl <space> {toggle_pl_marked [.tlpl.pl focus] "#1"} |
| 1545 |
bind .tlpl.pl <Return> {toggle_pl_marked [.tlpl.pl focus] "#1"} |
| 1546 |
# only toggle when column is #1 |
| 1547 |
bind .tlpl.pl <ButtonRelease-1> \ |
| 1548 |
{toggle_pl_marked \ |
| 1549 |
[.tlpl.pl identify item %x %y] \ |
| 1550 |
[.tlpl.pl identify column %x %y]} |
| 1551 |
|
| 1552 |
# enable commit button only if changes are requested |
| 1553 |
.tlpl.do state disabled |
| 1554 |
wm resizable .tlpl 0 1 |
| 1555 |
place_dlg .tlpl . |
| 1556 |
} ; # platforms_select |
| 1557 |
|
| 1558 |
### paper sizes |
| 1559 |
|
| 1560 |
# for the simple options: |
| 1561 |
proc set_all_papers {p} { |
| 1562 |
run_cmd "paper paper $p" 1 |
| 1563 |
} |
| 1564 |
|
| 1565 |
# the next few procs are for the advanced paper selection dialog |
| 1566 |
|
| 1567 |
proc paper_diff {} { |
| 1568 |
# check for different values and update widgets accordingly |
| 1569 |
set n [lindex [array names ::papers] 0] |
| 1570 |
set p $::papers($n) |
| 1571 |
set ::allpapers $p |
| 1572 |
set ::paperchanges 0 |
| 1573 |
.tlpap.do state disabled |
| 1574 |
foreach nm [array names ::papers] { |
| 1575 |
.tlpap.radios.$nm configure -font TkDefaultFont |
| 1576 |
if {$::papers($nm) ne $p} {set ::allpapers ""} |
| 1577 |
if {$::papers($nm) ne $::prevpapers($nm)} { |
| 1578 |
.tlpap.radios.$nm configure -font bfont |
| 1579 |
set ::paperchanges 1 |
| 1580 |
.tlpap.do state !disabled |
| 1581 |
} |
| 1582 |
} |
| 1583 |
} |
| 1584 |
|
| 1585 |
proc allpapers_adv {} { |
| 1586 |
# ::allpapers has already been set |
| 1587 |
set ::paperchanges 0 |
| 1588 |
.tlpap.do state disabled |
| 1589 |
foreach nm [array names ::papers] { |
| 1590 |
set ::papers($nm) $::allpapers |
| 1591 |
} |
| 1592 |
paper_diff |
| 1593 |
} |
| 1594 |
|
| 1595 |
proc commit_papers {} { |
| 1596 |
foreach nm [array names ::papers] { |
| 1597 |
if {$::papers($nm) ne $::prevpapers($nm)} { |
| 1598 |
set cmd "paper $nm paper $::papers($nm)" |
| 1599 |
if [catch {run_cmd_waiting $cmd} res] { |
| 1600 |
puts "failed paper setting: $res" |
| 1601 |
} |
| 1602 |
} |
| 1603 |
} |
| 1604 |
# clean up no longer needed globals |
| 1605 |
foreach nm [array names ::papers] {unset -nocomplain ::papers($nm)} |
| 1606 |
foreach nm [array names ::prevpapers] {unset -nocomplain ::prevpapers($nm)} |
| 1607 |
unset -nocomplain ::allpapers |
| 1608 |
unset -nocomplain ::paperchanges |
| 1609 |
} |
| 1610 |
|
| 1611 |
proc papersize_advanced {} { |
| 1612 |
# dialog for settings paper size for: |
| 1613 |
# all | pdftex | dvipdfmx | context | dvips | psutils | xdvi |
| 1614 |
# on windows, xdvi is omitted |
| 1615 |
# we could have handled papers somewhat like the platforms dialog, |
| 1616 |
# but radio buttons seem more natural, |
| 1617 |
# and there are not enough items to worry about scrollability. |
| 1618 |
# we create a grid with the radio buttons and a column 'changed'. |
| 1619 |
|
| 1620 |
## a non-existent engine 'dummy' to test handling of missing entries |
| 1621 |
#set ::papers(dummy) "" |
| 1622 |
foreach nm {"pdftex" "dvipdfmx" "context" "dvips" "psutils" "xdvi"} { |
| 1623 |
set ::papers($nm) "" |
| 1624 |
} |
| 1625 |
if {$::tcl_platform(platform) eq "windows"} { |
| 1626 |
unset -nocomplain ::papers(xdvi) |
| 1627 |
} |
| 1628 |
foreach nm [array names ::papers] { |
| 1629 |
if {[catch {run_cmd_waiting "paper $nm paper"} ::papers($nm)] || |
| 1630 |
([llength $::err_log]<1)} { |
| 1631 |
unset -nocomplain ::papers($nm) |
| 1632 |
} else { |
| 1633 |
set l [lindex $::err_log 0] |
| 1634 |
set r [string last "): " $l] |
| 1635 |
if {$r<0} { |
| 1636 |
unset -nocomplain ::papers($nm) |
| 1637 |
continue |
| 1638 |
} else { |
| 1639 |
set r [expr {$r+3}] |
| 1640 |
set ::papers($nm) [string tolower [string range $l $r end]] |
| 1641 |
} |
| 1642 |
if {$::papers($nm) ne "a4" && $::papers($nm) ne "letter"} { |
| 1643 |
set $::papers($nm) "" |
| 1644 |
} |
| 1645 |
} |
| 1646 |
} |
| 1647 |
set nms [array names ::papers] ; # invalid names have now been weeded out |
| 1648 |
if {[llength $nms] < 1} { |
| 1649 |
tk_messageBox -title [__ "Error"] -message [__ "No paper sizes available"] |
| 1650 |
# we did not yet start building the dialog, so we can just: |
| 1651 |
return |
| 1652 |
} |
| 1653 |
set nm0 [lindex $nms 0] |
| 1654 |
set ::allpapers $::papers($nm0) |
| 1655 |
foreach nm $nms { |
| 1656 |
set ::prevpapers($nm) $::papers($nm) |
| 1657 |
if {$::papers($nm) ne $::allpapers} {set ::allpapers ""} |
| 1658 |
} |
| 1659 |
set ::paperchanges 0 |
| 1660 |
|
| 1661 |
# build gui |
| 1662 |
create_dlg .tlpap |
| 1663 |
wm title .tlpap [__ "Paper sizes"] |
| 1664 |
if $::plain_unix {wm attributes .tlpap -type dialog} |
| 1665 |
|
| 1666 |
# wallpaper frame |
| 1667 |
pack [ttk::frame .tlpap.bg] -expand 1 -fill both |
| 1668 |
|
| 1669 |
# grid with radio buttons |
| 1670 |
pack [ttk::frame .tlpap.radios] -in .tlpap.bg |
| 1671 |
|
| 1672 |
foreach {p c} {"a4" 1 "letter" 2} { |
| 1673 |
pgrid [ttk::label .tlpap.radios.head$p \ |
| 1674 |
-text [string totitle $p] -font bfont] -row 0 -column $c |
| 1675 |
} |
| 1676 |
grid [ttk::separator .tlpap.radios.sep0 -orient horizontal] \ |
| 1677 |
-row 1 -column 0 -columnspan 3 -sticky ew |
| 1678 |
pgrid [ttk::label .tlpap.radios.lall -text [__ "All"]] \ |
| 1679 |
-row 2 -column 0 -sticky e |
| 1680 |
foreach {p c} {"a4" 1 "letter" 2} { |
| 1681 |
pgrid [ttk::radiobutton .tlpap.radios.${p}all -value $p \ |
| 1682 |
-variable ::allpapers -command allpapers_adv] -row 2 -column $c |
| 1683 |
} |
| 1684 |
grid [ttk::separator .tlpap.radios.sep1 -orient horizontal] \ |
| 1685 |
-row 3 -column 0 -columnspan 3 -sticky ew |
| 1686 |
set rw 3 |
| 1687 |
foreach nm $nms { |
| 1688 |
incr rw |
| 1689 |
pgrid [ttk::label .tlpap.radios.$nm -text $nm] \ |
| 1690 |
-row $rw -column 0 -sticky e |
| 1691 |
foreach {p c} {"a4" 1 "letter" 2} { |
| 1692 |
pgrid [ttk::radiobutton .tlpap.radios.$p$nm -value $p \ |
| 1693 |
-variable ::papers($nm) -command paper_diff] -row $rw -column $c |
| 1694 |
} |
| 1695 |
} |
| 1696 |
incr rw |
| 1697 |
grid [ttk::separator .tlpap.radios.sep2 -orient horizontal] \ |
| 1698 |
-row $rw -column 0 -columnspan 3 -sticky ew |
| 1699 |
|
| 1700 |
# buttons |
| 1701 |
pack [ttk::frame .tlpap.but] -in .tlpap.bg -side bottom -fill x |
| 1702 |
ttk::button .tlpap.do -text [__ "Apply and close"] -command { |
| 1703 |
disable_dlg .tlpap |
| 1704 |
commit_papers |
| 1705 |
end_dlg "" .tlpap |
| 1706 |
} |
| 1707 |
ttk::button .tlpap.dont -text [__ "Close"] -command \ |
| 1708 |
{end_dlg "" .tlpap} |
| 1709 |
ppack .tlpap.do -in .tlpap.but -side right |
| 1710 |
ppack .tlpap.dont -in .tlpap.but -side right |
| 1711 |
.tlpap.do state disabled |
| 1712 |
bind .tlpap <Escape> {.tlpap.dont invoke} |
| 1713 |
|
| 1714 |
pack [ttk::label .tlpap.bold -text [__ "Changed entries are bold"] \ |
| 1715 |
-font bfont] -in .tlpap.bg -side bottom |
| 1716 |
|
| 1717 |
wm resizable .tlpap 0 0 |
| 1718 |
place_dlg .tlpap . |
| 1719 |
} |
| 1720 |
|
| 1721 |
##### restore from backup ##### |
| 1722 |
|
| 1723 |
# This is currently rather dangerous. |
| 1724 |
# ::do_restore is set to 0 or 1 near the top of this source. |
| 1725 |
# This code, currently disbled, has not been tested in a while. |
| 1726 |
|
| 1727 |
if $::do_restore { |
| 1728 |
# dictionary of backups, with mapping to list of available revisions |
| 1729 |
set bks {} |
| 1730 |
|
| 1731 |
proc enable_restore {y_n} { |
| 1732 |
set st [expr {$y_n ? !disabled : disabled}] |
| 1733 |
.tlbk.bklist state $st |
| 1734 |
.tlbk.all state $st |
| 1735 |
.tlbk.done state $st |
| 1736 |
} ; # enable_restore |
| 1737 |
|
| 1738 |
proc finish_restore {} { |
| 1739 |
vwait ::done_waiting |
| 1740 |
# now log_widget_finish should have run and re-enabled its close button. |
| 1741 |
# We won't wait for the log dialog to close, but we will |
| 1742 |
# update the packages display in the main window. |
| 1743 |
update_local_revnumbers |
| 1744 |
collect_and_display_filtered |
| 1745 |
} ; # finish_restore |
| 1746 |
|
| 1747 |
proc restore_all {} { |
| 1748 |
run_cmd "restore --force --all" 1 |
| 1749 |
finish_restore |
| 1750 |
} ; # restore_all |
| 1751 |
|
| 1752 |
proc restore_this {} { |
| 1753 |
set id [.tlbk.bklist focus] |
| 1754 |
if {$id eq {}} return |
| 1755 |
set r [.tlbk.bklist set $id rev] |
| 1756 |
if {$r eq {}} return |
| 1757 |
set p [.tlbk.bklist set $id pkg] |
| 1758 |
if {$p eq {}} { |
| 1759 |
set id [.tlbk.bklist parent $id] |
| 1760 |
if {$id ne {}} {set p [.tlbk.bklist set $id pkg]} |
| 1761 |
} |
| 1762 |
if {$p eq {}} return |
| 1763 |
set ans [tk_messageBox -message [__ "Restore %s to revision %s?" $p $r] \ |
| 1764 |
-type okcancel -parent .tlbk] |
| 1765 |
if {$ans ne {ok}} return |
| 1766 |
run_cmd "restore --force $p $r" 1 |
| 1767 |
finish_restore |
| 1768 |
} ; # restore_this |
| 1769 |
|
| 1770 |
proc bklist_callback_click {x y} { |
| 1771 |
set cl [.tlbk.bklist identify column $x $y] |
| 1772 |
if {$cl eq "#0"} return |
| 1773 |
set id [.tlbk.bklist identify item $x $y] |
| 1774 |
.tlbk.bklist focus $id |
| 1775 |
restore_this |
| 1776 |
} ; # bklist_callback_click |
| 1777 |
|
| 1778 |
proc restore_backups_dialog {} { |
| 1779 |
run_cmd_waiting "option autobackup" |
| 1780 |
set re {autobackup\t(.*)$} |
| 1781 |
set abk 0 |
| 1782 |
foreach l $::out_log { |
| 1783 |
if [regexp $re $l m abk] break |
| 1784 |
} |
| 1785 |
if {$abk == 0} { |
| 1786 |
tk_messageBox -message [__ "No backups configured"] |
| 1787 |
return |
| 1788 |
} |
| 1789 |
run_cmd_waiting "option backupdir" |
| 1790 |
set re {backupdir\t(.*)$} |
| 1791 |
set bdir "" |
| 1792 |
foreach l $::out_log { |
| 1793 |
if [regexp $re $l m bdir] break |
| 1794 |
} |
| 1795 |
if {$bdir eq ""} { |
| 1796 |
tk_messageBox -message [__ "No backup directory defined"] |
| 1797 |
return |
| 1798 |
} |
| 1799 |
set bdir [file join [exec kpsewhich -var-value TEXMFROOT] $bdir] |
| 1800 |
if {! [file isdirectory $bdir]} { |
| 1801 |
tk_messageBox -message [__ "Backup directory %s does not exist" $bdir] |
| 1802 |
return |
| 1803 |
} |
| 1804 |
set pwd0 [pwd] |
| 1805 |
cd $bdir |
| 1806 |
set backups [lsort [glob -nocomplain *.tar.xz]] |
| 1807 |
if {[llength $backups] == 0} { |
| 1808 |
tk_messageBox -message [__ "No backups found in $bdir"] |
| 1809 |
return |
| 1810 |
} |
| 1811 |
# dictionary of backups; package => list of available revisions |
| 1812 |
set ::bks [dict create] |
| 1813 |
set re {^(.*)\.r(\d+)\.tar\.xz$} |
| 1814 |
foreach b $backups { |
| 1815 |
if [regexp $re $b m pk r] { |
| 1816 |
if {$pk in [dict keys $::bks]} { |
| 1817 |
dict lappend ::bks $pk $r |
| 1818 |
} else { |
| 1819 |
dict set ::bks $pk [list $r] |
| 1820 |
} |
| 1821 |
} |
| 1822 |
} |
| 1823 |
if {[llength [dict keys $::bks]] == 0} { |
| 1824 |
tk_messageBox -message [__ "No packages in backup directory %s" $bdir] |
| 1825 |
return |
| 1826 |
} |
| 1827 |
# invert sort order of revisions for each package |
| 1828 |
foreach pk [dict keys $::bks] { |
| 1829 |
dict set ::bks $pk [lsort -decreasing [dict get $::bks $pk]] |
| 1830 |
} |
| 1831 |
toplevel .tlbk -class Dialog |
| 1832 |
wm withdraw .tlbk |
| 1833 |
wm transient .tlbk . |
| 1834 |
wm title .tlbk [__ "Restore from backup"] |
| 1835 |
if $::plain_unix {wm attributes .tlbk -type dialog} |
| 1836 |
|
| 1837 |
# wallpaper frame; see populate_main |
| 1838 |
pack [ttk::frame .tlbk.bg] -expand 1 -fill x |
| 1839 |
|
| 1840 |
# the displayed list of backed-up packages |
| 1841 |
pack [ttk::frame .tlbk.fbk] -in .tlbk.bg -side top |
| 1842 |
# package names not in #0, because we want to trigger actions |
| 1843 |
# without automatically opening a parent. |
| 1844 |
pack [ttk::treeview .tlbk.bklist -columns {"pkg" "rev"} \ |
| 1845 |
-show {tree headings} -height 8 -selectmode browse \ |
| 1846 |
-yscrollcommand {.tlbk.bkvsb set}] -in .tlbk.fbk -side left |
| 1847 |
pack [ttk::scrollbar .tlbk.bkvsb -orient vertical -command \ |
| 1848 |
{.tlbk.bklist yview}] -in .tlbk.fbk -side right -fill y |
| 1849 |
|
| 1850 |
.tlbk.bklist heading "pkg" -text [__ "Package"] -anchor w |
| 1851 |
.tlbk.bklist heading "rev" -text [__ "Revision"] -anchor w |
| 1852 |
|
| 1853 |
.tlbk.bklist column "#0" -width [expr {$::cw * 2}] |
| 1854 |
.tlbk.bklist column "pkg" -width [expr {$::cw * 25}] |
| 1855 |
.tlbk.bklist column "rev" -width [expr {$::cw * 12}] |
| 1856 |
|
| 1857 |
# fill .tlbk.bklist. Use the last available revision. |
| 1858 |
# Remember that $::bks is sorted and revisions inversely sorted |
| 1859 |
# id must be unique in the entire list: rev does not qualify |
| 1860 |
# must as well use $id for package items too |
| 1861 |
set id 0 |
| 1862 |
dict for {pk rlist} $::bks { |
| 1863 |
# package |
| 1864 |
.tlbk.bklist insert {} end -id [incr id] \ |
| 1865 |
-values [list $pk [lindex $rlist 0]] -open 0 |
| 1866 |
set l [llength $rlist] |
| 1867 |
# additional revisions |
| 1868 |
if {$l > 1} { |
| 1869 |
set idparent $id |
| 1870 |
for {set i 1} {$i<$l} {incr i} { |
| 1871 |
.tlbk.bklist insert $idparent end -id [incr id] \ |
| 1872 |
-values [list "" [lindex $rlist $i]] |
| 1873 |
} |
| 1874 |
} |
| 1875 |
} |
| 1876 |
|
| 1877 |
# since we can only restore one non-last revision at a time, it is better |
| 1878 |
# to only show one non-last revision at a time too. |
| 1879 |
bind .tlbk.bklist <<TreeviewOpen>> { |
| 1880 |
foreach p [.tlbk.bklist children {}] { |
| 1881 |
if {$p ne [.tlbk.bklist focus]} { |
| 1882 |
.tlbk.bklist item $p -open 0 |
| 1883 |
} |
| 1884 |
} |
| 1885 |
} |
| 1886 |
# restoring a single package |
| 1887 |
bind .tlbk.bklist <<RightClick>> {bklist_callback_click %x %y} |
| 1888 |
bind .tlbk.bklist <space> restore_this |
| 1889 |
|
| 1890 |
# frame with buttons |
| 1891 |
pack [ttk::frame .tlbk.fbut] -in .tlbk.bg -side bottom -fill x |
| 1892 |
ppack [ttk::button .tlbk.all -text [__ "Restore all"] -command restore_all] \ |
| 1893 |
-in .tlbk.fbut -side right |
| 1894 |
ppack [ttk::button .tlbk.done -text [__ "Close"] -command { |
| 1895 |
end_dlg "" .tlbk}] -in .tlbk.fbut -side right |
| 1896 |
|
| 1897 |
place_dlg .tlbk . |
| 1898 |
wm resizable .tlbk 0 0 |
| 1899 |
tkwait .tlbk |
| 1900 |
} ; # restore_backups_dialog |
| 1901 |
|
| 1902 |
} ; # if $::do_restore |
| 1903 |
|
| 1904 |
##### Supporting procs and callbacks ################## |
| 1905 |
|
| 1906 |
##### package-related ##### |
| 1907 |
|
| 1908 |
### updating |
| 1909 |
|
| 1910 |
proc update_tlmgr_w32 {} { |
| 1911 |
close_tlmgr |
| 1912 |
# don't try pipes or capturing, because of |
| 1913 |
# tlmgr's acrobatics with nested command prompts |
| 1914 |
wm iconify . |
| 1915 |
exec -ignorestderr cmd /k "start cmd /k tlmgr update --self" |
| 1916 |
exec $::progname & |
| 1917 |
destroy . |
| 1918 |
} |
| 1919 |
|
| 1920 |
proc update_tlmgr {} { |
| 1921 |
if {! $::need_update_tlmgr} { |
| 1922 |
tk_messageBox -message [__ "Nothing to do!"] |
| 1923 |
return |
| 1924 |
} |
| 1925 |
if {$::tcl_platform(platform) eq "windows"} { |
| 1926 |
update_tlmgr_w32 |
| 1927 |
return |
| 1928 |
} |
| 1929 |
run_cmd "update --self" 1 |
| 1930 |
vwait ::done_waiting |
| 1931 |
# tlmgr restarts itself automatically |
| 1932 |
update_local_revnumbers |
| 1933 |
.topfr.linfra configure -text \ |
| 1934 |
"tlmgr: r[dict get $::pkgs texlive.infra localrev]" |
| 1935 |
collect_and_display_filtered |
| 1936 |
} ; # update_tlmgr |
| 1937 |
|
| 1938 |
proc update_all {} { |
| 1939 |
set updated_tlmgr 0 |
| 1940 |
if $::need_update_tlmgr { |
| 1941 |
if {$::tcl_platform(platform) eq "windows"} { |
| 1942 |
return ; # just to be sure; 'update all' button should be disabled |
| 1943 |
} |
| 1944 |
run_cmd "update --self" 1 |
| 1945 |
vwait ::done_waiting |
| 1946 |
# tlmgr restarts itself automatically |
| 1947 |
update_local_revnumbers |
| 1948 |
set updated_tlmgr 1 |
| 1949 |
} |
| 1950 |
# tlmgr restarts itself automatically |
| 1951 |
# tk_messageBox -message [__ "Update self first!"] |
| 1952 |
# return |
| 1953 |
if {! $::n_updates && !$updated_tlmgr} { |
| 1954 |
tk_messageBox -message [__ "Nothing to do!"] |
| 1955 |
return |
| 1956 |
} elseif $::n_updates { |
| 1957 |
run_cmd "update --all" 1 |
| 1958 |
vwait ::done_waiting |
| 1959 |
update_local_revnumbers |
| 1960 |
} |
| 1961 |
collect_and_display_filtered |
| 1962 |
} ; # update_all |
| 1963 |
|
| 1964 |
### doing something with some packages |
| 1965 |
|
| 1966 |
proc pkglist_from_option {opt {pk ""}} { |
| 1967 |
if {$opt eq "marked"} { |
| 1968 |
set pks {} |
| 1969 |
dict for {p props} $::pkgs { |
| 1970 |
if [dict get $props "marked"] {lappend pks $p} |
| 1971 |
} |
| 1972 |
} elseif {$opt eq "focus"} { |
| 1973 |
set p [.pkglist focus] |
| 1974 |
if {$p ne {}} {lappend pks $p} |
| 1975 |
} elseif {$opt eq "name"} { |
| 1976 |
lappend pks $pk |
| 1977 |
} |
| 1978 |
return $pks |
| 1979 |
} ; # pkglist_from_option |
| 1980 |
|
| 1981 |
proc install_pkgs {sel_opt {pk ""}} { |
| 1982 |
set pks [pkglist_from_option $sel_opt $pk] |
| 1983 |
# check whether packages are installed |
| 1984 |
set pre_installed {} |
| 1985 |
set todo {} |
| 1986 |
foreach p $pks { |
| 1987 |
if {[dict get $::pkgs $p localrev] > 0} { |
| 1988 |
lappend pre_installed $p |
| 1989 |
} else { |
| 1990 |
lappend todo $p |
| 1991 |
} |
| 1992 |
} |
| 1993 |
if {[llength $todo] == 0} { |
| 1994 |
tk_messageBox -message [__ "Nothing to do!"] -type ok -icon info |
| 1995 |
return |
| 1996 |
} |
| 1997 |
run_cmd_waiting "install --dry-run $todo" |
| 1998 |
# check whether dependencies are going to be installed |
| 1999 |
set r {^(\S+)\s+i\s} |
| 2000 |
set deps {} |
| 2001 |
foreach l $::out_log { |
| 2002 |
if {[regexp $r $l d p] && $p ni $pks} { |
| 2003 |
lappend deps $p |
| 2004 |
} |
| 2005 |
} |
| 2006 |
if {[llength $deps] > 0} { |
| 2007 |
set ans \ |
| 2008 |
[any_message \ |
| 2009 |
[__ "Also installing dependencies\n\n%s" $deps] \ |
| 2010 |
"okcancel"] |
| 2011 |
if {$ans eq "cancel"} return |
| 2012 |
} |
| 2013 |
run_cmd "install $todo" 1 |
| 2014 |
vwait ::done_waiting |
| 2015 |
if {[llength $pre_installed] > 0} { |
| 2016 |
lappend ::err_log [__ "Already installed: %s" $pre_installed] |
| 2017 |
show_err_log |
| 2018 |
} |
| 2019 |
update_local_revnumbers |
| 2020 |
if {$sel_opt eq "marked"} unmark_all |
| 2021 |
collect_and_display_filtered |
| 2022 |
} ; # install_pkgs |
| 2023 |
|
| 2024 |
proc update_pkgs {sel_opt {pk ""}} { |
| 2025 |
set pks [pkglist_from_option $sel_opt $pk] |
| 2026 |
# check whether packages are installed |
| 2027 |
set not_inst {} |
| 2028 |
set uptodate {} |
| 2029 |
set todo {} |
| 2030 |
foreach p $pks { |
| 2031 |
set lv [dict get $::pkgs $p localrev] |
| 2032 |
if {[dict get $::pkgs $p localrev] == 0} { |
| 2033 |
lappend not_inst $p |
| 2034 |
} else { |
| 2035 |
set rv [dict get $::pkgs $p remoterev] |
| 2036 |
if {$lv >= $rv} { |
| 2037 |
lappend uptodate $p |
| 2038 |
} else { |
| 2039 |
lappend todo $p |
| 2040 |
} |
| 2041 |
} |
| 2042 |
} |
| 2043 |
if {[llength $todo] == 0} { |
| 2044 |
tk_messageBox -message [__ "Nothing to do!"] -type ok -icon info |
| 2045 |
return |
| 2046 |
} |
| 2047 |
run_cmd_waiting "update --dry-run $todo" |
| 2048 |
# check whether dependencies are going to be updated |
| 2049 |
set r {^(\S+)\s+u\s} |
| 2050 |
set deps {} |
| 2051 |
foreach l $::out_log { |
| 2052 |
if {[regexp $r $l d p] && $p ni $pks} { |
| 2053 |
lappend deps $p |
| 2054 |
} |
| 2055 |
} |
| 2056 |
if {[llength $deps] > 0} { |
| 2057 |
set ans [any_message [__ "Also updating dependencies\n\n%s?" $deps] \ |
| 2058 |
"yesnocancel"] |
| 2059 |
switch $ans { |
| 2060 |
"cancel" return |
| 2061 |
"yes" {run_cmd "update $todo" 1} |
| 2062 |
"no" { |
| 2063 |
set deps {} |
| 2064 |
run_cmd_waiting "update --dry-run --no-depends $todo" |
| 2065 |
foreach l $::out_log { |
| 2066 |
if {[regexp $r $l u p] && $p ni $pks} { |
| 2067 |
lappend deps $p |
| 2068 |
} |
| 2069 |
} |
| 2070 |
if {[llength $deps] > 0} { |
| 2071 |
set ans [any_message \ |
| 2072 |
[__ "Updating some dependencies %s anyway. Continue?" $deps] \ |
| 2073 |
"okcancel"] |
| 2074 |
if {$ans eq "cancel"} return |
| 2075 |
} |
| 2076 |
run_cmd "update --no-depends $todo" 1 |
| 2077 |
} |
| 2078 |
} |
| 2079 |
} else { |
| 2080 |
run_cmd "update $todo" 1 |
| 2081 |
} |
| 2082 |
vwait ::done_waiting |
| 2083 |
if {[llength $not_inst] > 0} { |
| 2084 |
lappend ::err_log [__ "Skipped because not installed: %s" $not_inst] |
| 2085 |
} |
| 2086 |
if {[llength $uptodate] > 0} { |
| 2087 |
lappend ::err_log [__ "Skipped because already up to date: %s" $uptodate] |
| 2088 |
} |
| 2089 |
if {[llength $not_inst] > 0 || [llength $uptodate] > 0} { |
| 2090 |
show_err_log |
| 2091 |
} |
| 2092 |
update_local_revnumbers |
| 2093 |
if {$sel_opt eq "marked"} unmark_all |
| 2094 |
collect_and_display_filtered |
| 2095 |
} ; # update_pkgs |
| 2096 |
|
| 2097 |
proc remove_pkgs {sel_opt {pk ""}} { |
| 2098 |
set pks [pkglist_from_option $sel_opt $pk] |
| 2099 |
# check whether packages are installed |
| 2100 |
set not_inst {} |
| 2101 |
set todo {} |
| 2102 |
foreach p $pks { |
| 2103 |
if {[dict get $::pkgs $p localrev] > 0} { |
| 2104 |
lappend todo $p |
| 2105 |
} else { |
| 2106 |
lappend not_inst $p |
| 2107 |
} |
| 2108 |
} |
| 2109 |
run_cmd_waiting "remove --dry-run $todo" |
| 2110 |
# check whether dependencies are going to be removed |
| 2111 |
set r {^(\S+)\s+d\s} |
| 2112 |
set deps {} |
| 2113 |
foreach l $::out_log { |
| 2114 |
if {[regexp $r $l d p] && $p ni $pks} { |
| 2115 |
lappend deps $p |
| 2116 |
} |
| 2117 |
} |
| 2118 |
if {[llength $todo] == 0} { |
| 2119 |
tk_messageBox -message [__ "Nothing to do!"] -type ok -icon info |
| 2120 |
return |
| 2121 |
} |
| 2122 |
if {[llength $deps] > 0} { |
| 2123 |
set ans [any_message [__ "Also remove dependencies\n\n%s?" $deps] \ |
| 2124 |
"yesnocancel"] |
| 2125 |
switch $ans { |
| 2126 |
"cancel" return |
| 2127 |
"yes" {run_cmd "remove $todo" 1} |
| 2128 |
"no" { |
| 2129 |
set deps {} |
| 2130 |
run_cmd_waiting "remove --dry-run --no-depends $todo" |
| 2131 |
foreach l $::out_log { |
| 2132 |
if {[regexp $r $l d p] && $p ni $pks} { |
| 2133 |
lappend deps $p |
| 2134 |
} |
| 2135 |
} |
| 2136 |
if {[llength $deps] > 0} { |
| 2137 |
set ans [any_message \ |
| 2138 |
[__ "Removing some dependencies %s anyway. Continue?" $deps] \ |
| 2139 |
"okcancel"] |
| 2140 |
if {$ans eq "cancel"} return |
| 2141 |
} |
| 2142 |
run_cmd "remove --no-depends $todo" 1 |
| 2143 |
} |
| 2144 |
} |
| 2145 |
} else { |
| 2146 |
run_cmd "remove $todo" 1 |
| 2147 |
} |
| 2148 |
vwait ::done_waiting |
| 2149 |
if {[llength $not_inst] > 0} { |
| 2150 |
lappend ::err_log "Skipped because not installed: $not_inst" |
| 2151 |
show_err_log |
| 2152 |
} |
| 2153 |
update_local_revnumbers |
| 2154 |
if {$sel_opt eq "marked"} unmark_all |
| 2155 |
collect_and_display_filtered |
| 2156 |
} ; # remove_pkgs |
| 2157 |
|
| 2158 |
# restoring packages is a rather different story, controlled by the |
| 2159 |
# contents of the backup directory. see further up. |
| 2160 |
|
| 2161 |
##### varous callbacks ##### |
| 2162 |
|
| 2163 |
proc restart_self {} { |
| 2164 |
do_debug "trying to restart" |
| 2165 |
if {$::progname eq ""} { |
| 2166 |
tk_messageBox -message "progname not found; not restarting" |
| 2167 |
return |
| 2168 |
} |
| 2169 |
close_tlmgr |
| 2170 |
exec $::progname & |
| 2171 |
# on windows, it may take several seconds before |
| 2172 |
# the old tlshell disappears. |
| 2173 |
# oh well, windows is still windows.... |
| 2174 |
destroy . |
| 2175 |
} ; # restart_self |
| 2176 |
|
| 2177 |
proc toggle_marked_pkg {itm cl} { |
| 2178 |
# toggle_marked_pkg is triggered by a mouse click only in column #1. |
| 2179 |
# 'marked' should get updated in ::pkgs, ::filtered and in .pkglist. |
| 2180 |
|
| 2181 |
if {$cl ne "#1"} return |
| 2182 |
# clicking in the header: |
| 2183 |
if {$itm eq ""} return |
| 2184 |
# $mrk: negation of current value of marked for $itm |
| 2185 |
set mrk [expr {[dict get $::pkgs $itm "marked"] ? 0 : 1}] |
| 2186 |
dict set ::pkgs $itm "marked" $mrk |
| 2187 |
set m [mark_sym $mrk] |
| 2188 |
dict set ::filtered $itm [lreplace [dict get $::filtered $itm] 0 0 $m] |
| 2189 |
.pkglist set $itm mk $m |
| 2190 |
} ; # toggle_marked_pkg |
| 2191 |
|
| 2192 |
proc unmark_all {} { |
| 2193 |
foreach nm [dict keys $::pkgs] { |
| 2194 |
dict set ::pkgs $nm "marked" 0 |
| 2195 |
} |
| 2196 |
set m [mark_sym 0] |
| 2197 |
foreach nm [dict keys $::filtered] { |
| 2198 |
dict set ::filtered $nm [lreplace [dict get $::filtered $nm] 0 0 $m] |
| 2199 |
} |
| 2200 |
foreach nm [.pkglist children {}] { |
| 2201 |
.pkglist set $nm mk $m |
| 2202 |
} |
| 2203 |
} ; # unmark_all |
| 2204 |
|
| 2205 |
proc mark_displayed {} { |
| 2206 |
set m [mark_sym 1] |
| 2207 |
foreach nm [.pkglist children {}] { |
| 2208 |
dict set ::pkgs $nm "marked" 1 |
| 2209 |
dict set ::filtered $nm [lreplace [dict get $::filtered $nm] 0 0 $m] |
| 2210 |
.pkglist set $nm mk $m |
| 2211 |
} |
| 2212 |
} ; # mark_displayed |
| 2213 |
|
| 2214 |
##### package popup ##### |
| 2215 |
|
| 2216 |
proc do_package_popup_menu {x y X Y} { |
| 2217 |
# as focused item, the identity of the clicked item will be |
| 2218 |
# globally available: |
| 2219 |
if {[.pkglist identify region $x $y] ne "cell"} {return} |
| 2220 |
.pkglist focus [.pkglist identify item $x $y] |
| 2221 |
# recreate menu with only applicable items |
| 2222 |
set lr [dict get $::pkgs [.pkglist focus] "localrev"] |
| 2223 |
set rr [dict get $::pkgs [.pkglist focus] "remoterev"] |
| 2224 |
.pkg_popup delete 0 end |
| 2225 |
|
| 2226 |
.pkg_popup add command -label [__ "Info"] -command { |
| 2227 |
run_cmd "info [.pkglist focus]" 1; vwait ::done_waiting |
| 2228 |
} |
| 2229 |
if {$::have_remote && ! $::need_update_tlmgr && $rr > 0 && $lr == 0} { |
| 2230 |
.pkg_popup add command -label [__ "Install"] -command { |
| 2231 |
install_pkgs "focus" |
| 2232 |
} |
| 2233 |
} |
| 2234 |
if {$::have_remote && ! $::need_update_tlmgr && $lr > 0 && $rr > $lr} { |
| 2235 |
.pkg_popup add command -label [__ "Update"] -command { |
| 2236 |
update_pkgs "focus" |
| 2237 |
} |
| 2238 |
} |
| 2239 |
if {$lr > 0} { |
| 2240 |
.pkg_popup add command -label [__ "Remove"] -command { |
| 2241 |
remove_pkgs "focus" |
| 2242 |
} |
| 2243 |
} |
| 2244 |
.pkg_popup add command -label [__ "Reporting bugs"] -command { |
| 2245 |
run_cmd "bug [.pkglist focus]" 1; vwait ::done_waiting |
| 2246 |
} |
| 2247 |
.pkg_popup post [expr {$X - 2}] [expr {$Y - 2}] |
| 2248 |
focus .pkg_popup |
| 2249 |
} ; # do_package_popup_menu |
| 2250 |
|
| 2251 |
#### gui options #### |
| 2252 |
|
| 2253 |
proc set_language {l} { |
| 2254 |
set ::lang $l |
| 2255 |
load_translations |
| 2256 |
rebuild_interface |
| 2257 |
if {! [save_config_var "gui-lang" $::lang]} { |
| 2258 |
tk_messageBox -message [__"Cannot save language setting"] |
| 2259 |
} |
| 2260 |
} |
| 2261 |
|
| 2262 |
proc set_fontscale {s} { |
| 2263 |
set ::tkfontscale $s |
| 2264 |
redo_fonts |
| 2265 |
rebuild_interface |
| 2266 |
if {[dict get $::pkgs texlive.infra localrev] >= 54766} { |
| 2267 |
if {! [save_config_var "tkfontscale" $::tkfontscale]} { |
| 2268 |
tk_messageBox -message [__"Cannot save font scale setting"] |
| 2269 |
} |
| 2270 |
} |
| 2271 |
} |
| 2272 |
|
| 2273 |
proc zoom {n} { |
| 2274 |
if {$n <= 0} {set n 1} |
| 2275 |
set_fontscale [expr {$n*$::tkfontscale}] |
| 2276 |
} |
| 2277 |
|
| 2278 |
##### running external commands ##### |
| 2279 |
# for when a simple 'set var [exec command]' won't do |
| 2280 |
|
| 2281 |
# For capturing an external command, we need a separate output channel, |
| 2282 |
# but we reuse ::out_log. |
| 2283 |
# stderr is bundled with stdout so ::err_log should stay empty. |
| 2284 |
proc read_capture {} { |
| 2285 |
set l "" ; # will contain the line to be read |
| 2286 |
if {([catch {chan gets $::capt l} len] || [chan eof $::capt])} { |
| 2287 |
catch {chan close $::capt} |
| 2288 |
log_widget_finish |
| 2289 |
set ::done_waiting 1 |
| 2290 |
} elseif {$len >= 0} { |
| 2291 |
lappend ::out_log $l |
| 2292 |
log_widget_add $l |
| 2293 |
} |
| 2294 |
}; # read_capture |
| 2295 |
|
| 2296 |
proc run_external {cmd {mess ""}} { |
| 2297 |
set ::out_log {} |
| 2298 |
set ::err_log {} |
| 2299 |
if {$mess ne ""} {lappend ::out_log $mess} |
| 2300 |
unset -nocomplain ::done_waiting |
| 2301 |
# treat cmd as a list, possibly of one element |
| 2302 |
# using a list enables a direct invocation, bypassing a shell |
| 2303 |
set cmd0 [lindex $cmd 0] |
| 2304 |
set cmd [lreplace $cmd 0 0 "|$cmd0"] |
| 2305 |
set cmd [list {*}$cmd 2>@1] |
| 2306 |
if [catch {open $cmd r} ::capt] { |
| 2307 |
tk_messageBox -message "Failure to launch $cmd" |
| 2308 |
} |
| 2309 |
chan configure $::capt -buffering line -blocking 0 |
| 2310 |
chan event $::capt readable read_capture |
| 2311 |
log_widget_init |
| 2312 |
} |
| 2313 |
|
| 2314 |
proc about_cmd {} { |
| 2315 |
set msg "\u00a9 2017-2025 Siep Kroonenberg\n\n" |
| 2316 |
append msg [__ "GUI interface for TeX Live Manager\nImplemented in Tcl/Tk"] |
| 2317 |
tk_messageBox -message $msg |
| 2318 |
} |
| 2319 |
|
| 2320 |
proc tlshell_help {} { |
| 2321 |
set msg \ |
| 2322 |
[__ "This TeX Live Manager front-end should be pretty self-explanatory. |
| 2323 |
Note that it does not cover the full functionality of tlmgr. Notably, it does not cover user mode or backup and restore. |
| 2324 |
Consult the 'Tlmgr Help' menu for full documentation on tlmgr itself."] |
| 2325 |
tk_messageBox -message $msg |
| 2326 |
} |
| 2327 |
|
| 2328 |
proc tlmgr_help {} { |
| 2329 |
set ::env(NOPERLDOC) 1 |
| 2330 |
long_message [exec tlmgr --help] ok |
| 2331 |
} |
| 2332 |
|
| 2333 |
## no arbitrary commands: no way to know what data have to be updated |
| 2334 |
#proc custom_command {} { |
| 2335 |
# create_dlg .tlcust . |
| 2336 |
# wm title .tlcust [__ "Custom command"] |
| 2337 |
# pack [ttk::frame .tlcust.bg] -expand 1 -fill x |
| 2338 |
# |
| 2339 |
# ppack [ttk::entry .tlcust.e] \ |
| 2340 |
# -in .tlcust.bg -side left -fill x -expand 1 |
| 2341 |
# ppack [ttk::button .tlcust.b -text [__ "Go"] -command run_entry] \ |
| 2342 |
# -in .tlcust.bg -side left |
| 2343 |
# bind .tlcust.e <Return> run_entry |
| 2344 |
# bind .tlcust <Escape> {end_dlg "" .tlcust} |
| 2345 |
# wm .tlcust resizable 1 0 |
| 2346 |
# place_dlg .tlcust . |
| 2347 |
#} |
| 2348 |
|
| 2349 |
##### main window ##### |
| 2350 |
|
| 2351 |
proc try_loading_remote {} { |
| 2352 |
if {[possible_repository $::repos(main)]} { |
| 2353 |
get_packages_info_remote |
| 2354 |
collect_and_display_filtered |
| 2355 |
} else { |
| 2356 |
set mes [__ "%s is not a local or remote repository. |
| 2357 |
Please configure a valid repository" $::repos(main)] |
| 2358 |
append mes "\n([__ "Options"] \/ [__ "Repositories"] ...)" |
| 2359 |
tk_messageBox -message $mes -title [__ "Error"] -type ok -icon error |
| 2360 |
} |
| 2361 |
} |
| 2362 |
|
| 2363 |
##### w64 binaries #################################################### |
| 2364 |
|
| 2365 |
# Although w64 binaries can be added if windows is only an |
| 2366 |
# additional platform, the extra w64 command-prompt can only be |
| 2367 |
# added from within windows. The situation is a bit difficult to |
| 2368 |
# explain to begin with, so it seems better to offer the option only |
| 2369 |
# for a native windows install. |
| 2370 |
|
| 2371 |
# I would have liked to avoid pointless downloads, |
| 2372 |
# but comparing dates is fraught with problems: |
| 2373 |
# - remote file info is reported differently by different protocols |
| 2374 |
# - the date of a local file may be installation time |
| 2375 |
# - spurious differences due to local time and daylight saving time |
| 2376 |
# we CAN timestamp zipfiles to their latest member |
| 2377 |
# with 'unzip -T', but this can only be done AFTER downloading. |
| 2378 |
# See also tcl commands 'file mtime', and 'clock scan' |
| 2379 |
|
| 2380 |
if 0 { |
| 2381 |
# $::wprocessor will later decide whether a w64 menu will be created. |
| 2382 |
if {$::tcl_platform(platform) eq "windows"} { |
| 2383 |
set ::wprocessor $::env(PROCESSOR_ARCHITECTURE) |
| 2384 |
# in case of 32-bit programs on 64-bit system: |
| 2385 |
if [info exists ::env(PROCESSOR_ARCHITEW6432)] { |
| 2386 |
set ::wprocessor $::env(PROCESSOR_ARCHITEW6432) |
| 2387 |
} |
| 2388 |
} |
| 2389 |
|
| 2390 |
proc w64_about {} { |
| 2391 |
# read and display file with warning message |
| 2392 |
set fn [exec kpsewhich -format texmfscripts help-w64.txt] |
| 2393 |
if {$fn eq "" || [catch {open $fn} wf]} { |
| 2394 |
tk_messageBox -message "Failed to open help-w64.txt" |
| 2395 |
return 0 |
| 2396 |
} |
| 2397 |
set s "" |
| 2398 |
while {! [catch {chan gets $wf} line] && ! [chan eof $wf]} { |
| 2399 |
set s [string cat $s "\n" $line] |
| 2400 |
} |
| 2401 |
chan close $wf |
| 2402 |
long_message [string range $s 1 end] "okcancel" |
| 2403 |
} |
| 2404 |
|
| 2405 |
set ::w64_zipdir "${::instroot}/bin/win64/zip" |
| 2406 |
set ::w64_zipname "tl-win64" |
| 2407 |
|
| 2408 |
proc create_w64_shortcut {} { |
| 2409 |
# delegate the creation of a start menu shortcut to powershell. |
| 2410 |
# consider failure non-fatal |
| 2411 |
set shortcutfile \ |
| 2412 |
[file join \ |
| 2413 |
[expr {$::multiuser ? $::env(programdata) : $::env(appdata)}] \ |
| 2414 |
"microsoft\\windows\\start menu\\programs" \ |
| 2415 |
"TeX Live $::year" \ |
| 2416 |
"TeX Live $::year 64-bit.lnk"] |
| 2417 |
set shortcut_bsl [string map {\/ \\} $shortcutfile] |
| 2418 |
|
| 2419 |
set inst_bsl [string map {\/ \\} $::instroot] |
| 2420 |
set path_add "${inst_bsl}\\bin\\win64;${inst_bsl}\\bin\\win32;" |
| 2421 |
# below, escape '%' for the sake of tcl, probably unnecessary here |
| 2422 |
# i believe '%' has no special significance for powershell. |
| 2423 |
set shargs "/k path ${path_add}\%PATH\% && title TeX Live 64-bit" |
| 2424 |
set cmd [string cat \ |
| 2425 |
"\$ws = new-object -comobject wscript.shell;" \ |
| 2426 |
"\$s = \$ws.createshortcut('$shortcut_bsl');" \ |
| 2427 |
"\$s.targetpath = 'cmd';" \ |
| 2428 |
"\$s.arguments = '$shargs';" \ |
| 2429 |
"\$s.workingdirectory = '\%userprofile\%';" \ |
| 2430 |
"\$s.save()"] |
| 2431 |
# powershell will silently overwrite an existing shortcut |
| 2432 |
set res [catch {exec cmd /c powershell.exe -NoLogo -NonInteractive \ |
| 2433 |
-NoProfile -command $cmd}] |
| 2434 |
if {$res || ![file exists $shortcutfile]} { |
| 2435 |
return 0 |
| 2436 |
} |
| 2437 |
return 1 |
| 2438 |
} |
| 2439 |
|
| 2440 |
proc remove_w64 {} { |
| 2441 |
total_dis_enable 0 |
| 2442 |
update idletasks |
| 2443 |
# remove shortcut |
| 2444 |
set shortcutfile \ |
| 2445 |
[file join \ |
| 2446 |
[expr {$::multiuser ? $::env(programdata) : $::env(appdata)}] \ |
| 2447 |
"microsoft\\windows\\start menu\\programs" \ |
| 2448 |
"TeX Live $::year" \ |
| 2449 |
"TeX Live $::year 64-bit.lnk"] |
| 2450 |
file delete -force $shortcutfile |
| 2451 |
cd $::instroot |
| 2452 |
set w64dir [file join $::instroot "bin" "win64"] |
| 2453 |
total_dis_enable 1 |
| 2454 |
update idletasks |
| 2455 |
catch {file delete -force $w64dir} |
| 2456 |
if {[file exists $shortcutfile] || [file exists $w64dir]} { |
| 2457 |
tk_messageBox -message "$w64dir not completely removed" |
| 2458 |
dis_enable_w64 |
| 2459 |
return 0 |
| 2460 |
} else { |
| 2461 |
tk_messageBox -message "$w64dir completely removed" |
| 2462 |
dis_enable_w64 |
| 2463 |
return 1 |
| 2464 |
} |
| 2465 |
} |
| 2466 |
|
| 2467 |
proc make_64_dirs {} { |
| 2468 |
if [catch {file mkdir "$::instroot/bin/win64/zip"}] { |
| 2469 |
tk_messageBox -message "Cannot create required directory" |
| 2470 |
return 0 |
| 2471 |
} |
| 2472 |
return 1 |
| 2473 |
} |
| 2474 |
|
| 2475 |
# local or remote source: these are separate submenu entries |
| 2476 |
|
| 2477 |
proc get_remote_w64 {} { |
| 2478 |
|
| 2479 |
set curl "$::instroot/tlpkg/installer/curl/curl.exe" |
| 2480 |
set url "" |
| 2481 |
if {[string first {://} $::repos(main)]<0} { |
| 2482 |
# local repository, we assume w64 not included |
| 2483 |
set url "" |
| 2484 |
} elseif $::have_remote { |
| 2485 |
set url $::actual_main |
| 2486 |
} else { |
| 2487 |
set url $::repos(main) |
| 2488 |
if {$url eq $::any_mirror} { |
| 2489 |
set url "" |
| 2490 |
} |
| 2491 |
} |
| 2492 |
# we are currently in $::w64_zipdir |
| 2493 |
if [file exists ${::w64_zipname}.zip] { |
| 2494 |
# here and elsewhere, we do not consider a rename failure fatal |
| 2495 |
catch {file rename -force ${::w64_zipname}.zip ${::w64_zipname}_old.zip} |
| 2496 |
} |
| 2497 |
set notfound 1 |
| 2498 |
set ntries 1 |
| 2499 |
while {$notfound && $ntries<6} { |
| 2500 |
if {$url eq ""} { |
| 2501 |
# ask curl for a specific mirror |
| 2502 |
if [catch {exec $curl -Ls -o nul -w %{url_effective} $::any_mirror} url] { |
| 2503 |
tk_messageBox -message "Cannot get any mirror" |
| 2504 |
return 0 |
| 2505 |
} |
| 2506 |
} |
| 2507 |
set c [string last "/texlive" $url] |
| 2508 |
if {$c<0} { |
| 2509 |
lappend ::err_log "Mirror $url no good at try $ntries" |
| 2510 |
continue |
| 2511 |
} |
| 2512 |
set url [string range $url 0 $c] ; # the new value includes a final '/' |
| 2513 |
set url "${url}win32/TLW64/${::w64_zipname}.zip" |
| 2514 |
# download options: |
| 2515 |
# -s: silent; -f: silent fail; -o: target name; -R: preserve time |
| 2516 |
incr ntries |
| 2517 |
set notfound [catch { |
| 2518 |
exec -keepnewline -ignorestderr $curl -s -f -o ${::w64_zipname}.zip -R $url |
| 2519 |
}] |
| 2520 |
if {!$notfound} { |
| 2521 |
lappend ::err_log "Success after $ntries tries" |
| 2522 |
return 1 |
| 2523 |
} else { |
| 2524 |
set url "" |
| 2525 |
} |
| 2526 |
} |
| 2527 |
tk_messageBox -message \ |
| 2528 |
"No success after $ntries tries.\nFailed to download ${::w64_zipname}.zip" |
| 2529 |
return 0 |
| 2530 |
} |
| 2531 |
|
| 2532 |
proc get_local_w64 {} { |
| 2533 |
# we are currently in $::w64_zipdir |
| 2534 |
# invoke file browser |
| 2535 |
set zipfile [tk_getOpenFile \ |
| 2536 |
-filetypes {{"Zip files" {.zip .ZIP}}} \ |
| 2537 |
-initialfile "${::w64_zipname}.zip" \ |
| 2538 |
-title "Zipfile with 64-bit binaries"] |
| 2539 |
if {$zipfile eq ""} { |
| 2540 |
return 0 |
| 2541 |
} else { |
| 2542 |
if {[file normalize $zipfile] ne "${::w64_zipdir}/${::w64_zipname}.zip"} { |
| 2543 |
# nothing to be done if zipfile is at its intended location |
| 2544 |
if [file exists "${::w64_zipname}.zip"] { |
| 2545 |
file rename -force "${::w64_zipname}.zip" "${::w64_zipname}_old.zip" |
| 2546 |
# ignore failure; below, we shall just try to overwrite |
| 2547 |
} |
| 2548 |
if [catch {file copy -force $zipfile ${::w64_zipname}.zip}] { |
| 2549 |
tk_messageBox -message \ |
| 2550 |
"Cannot copy $zipfile to ${::w64_zipdir}/${::w64_zipname}.zip" |
| 2551 |
return 0 |
| 2552 |
} |
| 2553 |
} |
| 2554 |
} |
| 2555 |
return 1 |
| 2556 |
} |
| 2557 |
|
| 2558 |
proc dis_enable_w64 {} { |
| 2559 |
if [file exists [file join $::instroot "bin" "win64"]] { |
| 2560 |
.mn.w64 entryconfigure $::inx_remove64 -state normal |
| 2561 |
} else { |
| 2562 |
.mn.w64 entryconfigure $::inx_remove64 -state disabled |
| 2563 |
} |
| 2564 |
if [file exists [file join $::w64_zipdir "${::w64_zipname}.zip"]] { |
| 2565 |
.mn.w64 entryconfigure $::inx_sync64 -state normal |
| 2566 |
} else { |
| 2567 |
.mn.w64 entryconfigure $::inx_sync64 -state disabled |
| 2568 |
} |
| 2569 |
} |
| 2570 |
|
| 2571 |
proc sync_w64_w32 {} { |
| 2572 |
# disable interface, but only if invoked directly |
| 2573 |
set caller [lindex [info level 1] 0] |
| 2574 |
if {$caller ne "add_or_update_w64"} { |
| 2575 |
total_dis_enable 0 |
| 2576 |
update idletasks |
| 2577 |
} |
| 2578 |
# try to clear out bin/win64 |
| 2579 |
foreach f [glob -nocomplain -directory $::instroot/bin/win64 *] { |
| 2580 |
if {![file isdirectory $f]} { |
| 2581 |
catch {file delete $f} |
| 2582 |
} |
| 2583 |
} |
| 2584 |
cd $::instroot; # actually already done by invoker |
| 2585 |
if [catch { |
| 2586 |
exec unzip -d $::instroot -qo ${::w64_zipdir}/${::w64_zipname}.zip} r] { |
| 2587 |
tk_messageBox -message "$r:\nDid not succeed in extracting all win64 files" |
| 2588 |
return 0 |
| 2589 |
} |
| 2590 |
cd $::instroot/bin/win64 |
| 2591 |
# all 64-bit executable files should have corresponding 32-bit files |
| 2592 |
set sync_mess {} |
| 2593 |
foreach f [glob -nocomplain *] { |
| 2594 |
# exempt .dll files |
| 2595 |
if {[string tolower [string range $f end-3 end]] ne ".dll"} { |
| 2596 |
if {! [file exists ../win32/$f] && ![file isdirectory $f]} { |
| 2597 |
if [catch {file delete $f}] { |
| 2598 |
lappend sync_mess $f |
| 2599 |
} |
| 2600 |
} |
| 2601 |
} |
| 2602 |
} |
| 2603 |
cd $::instroot |
| 2604 |
if {$caller ne "add_or_update_w64"} { |
| 2605 |
total_dis_enable 1 |
| 2606 |
update idletasks |
| 2607 |
} |
| 2608 |
return $sync_mess |
| 2609 |
} |
| 2610 |
|
| 2611 |
proc add_or_update_w64 {lr} { |
| 2612 |
if {! [file exists ${::w64_zipname}.zip]} { |
| 2613 |
# 'about' message if no prior w64 |
| 2614 |
w64_about |
| 2615 |
} |
| 2616 |
set ok 1 |
| 2617 |
# below, fatal errors in invoked procs produce error message boxes |
| 2618 |
# so nothing remains but abandoning the effort. |
| 2619 |
if {! [make_64_dirs]} {set ok 0} |
| 2620 |
|
| 2621 |
if {$ok && [catch {cd $::w64_zipdir}]} { |
| 2622 |
tk_messageBox -message "Cannot access $::w64_zipdir" |
| 2623 |
set ok 0 |
| 2624 |
} |
| 2625 |
if {! $ok} {return 0} |
| 2626 |
|
| 2627 |
# operations below may take time: disable interface |
| 2628 |
total_dis_enable 0 |
| 2629 |
update idletasks |
| 2630 |
if {$lr eq "remote"} { |
| 2631 |
if {! [get_remote_w64]} { |
| 2632 |
set ok 0 |
| 2633 |
} |
| 2634 |
} else { |
| 2635 |
if {! [get_local_w64]} { |
| 2636 |
set ok 0 |
| 2637 |
} |
| 2638 |
} |
| 2639 |
if $ok { |
| 2640 |
# unpack new zip selectively |
| 2641 |
set mess [sync_w64_w32] ; # a list of filenames |
| 2642 |
if {[llength $mess]>0} { |
| 2643 |
set mess [linsert $mess 0 \ |
| 2644 |
"The following files should have been deleted from bin/w64 but were not:"] |
| 2645 |
} |
| 2646 |
# now w64 shortcut for cmd.exe using powershell invocation |
| 2647 |
if [create_w64_shortcut] { |
| 2648 |
lappend mess "64-bit TeXLive shortcut created" |
| 2649 |
} else { |
| 2650 |
lappend mess "Failed to create 64-bit TeXLive shortcut" |
| 2651 |
} |
| 2652 |
lappend mess "Downloaded and installed 64-bit binaries." |
| 2653 |
lappend mess "Done" |
| 2654 |
any_message [join $mess "\n"] ok |
| 2655 |
} |
| 2656 |
|
| 2657 |
total_dis_enable 1 |
| 2658 |
update idletasks |
| 2659 |
return 1 |
| 2660 |
} |
| 2661 |
}; # if 0 |
| 2662 |
##### main window ##################################################### |
| 2663 |
|
| 2664 |
proc populate_main {} { |
| 2665 |
|
| 2666 |
wm withdraw . |
| 2667 |
|
| 2668 |
wm title . "TeX Live Shell" |
| 2669 |
|
| 2670 |
## menu ## |
| 2671 |
|
| 2672 |
# dummy empty menu to replace the real menu .mn in disabled states. |
| 2673 |
# the "File" cascade should ensure that the dummy menu |
| 2674 |
# occupies the same vertical space as the real menu. |
| 2675 |
menu .mn_empty |
| 2676 |
.mn_empty add cascade -label [__ "File"] -menu .mn_empty.file -underline 0 |
| 2677 |
if $::plain_unix { |
| 2678 |
.mn_empty configure -borderwidth 0 |
| 2679 |
.mn_empty configure -background $::default_bg |
| 2680 |
menu .mn_empty.file |
| 2681 |
} |
| 2682 |
# real menu |
| 2683 |
menu .mn |
| 2684 |
. configure -menu .mn |
| 2685 |
if $::plain_unix { |
| 2686 |
.mn configure -borderwidth 0 |
| 2687 |
.mn configure -background $::default_bg |
| 2688 |
|
| 2689 |
# plain_unix: avoid a possible RenderBadPicture error on quitting |
| 2690 |
# when there is a menu. |
| 2691 |
# 'send' bypasses the bug by changing the shutdown sequence. |
| 2692 |
# 'tk appname <something>' restores 'send'. |
| 2693 |
bind . <Destroy> { |
| 2694 |
catch {tk appname appname} |
| 2695 |
} |
| 2696 |
} |
| 2697 |
|
| 2698 |
.mn add cascade -label [__ "File"] -menu .mn.file -underline 0 |
| 2699 |
menu .mn.file |
| 2700 |
.mn.file add command -label [__ "Load repository"] \ |
| 2701 |
-command try_loading_remote |
| 2702 |
.mn.file add command -command {destroy .} -label [__ "Exit"] -underline 1 |
| 2703 |
|
| 2704 |
.mn add cascade -label [__ "Actions"] -menu .mn.act -underline 0 |
| 2705 |
menu .mn.act |
| 2706 |
.mn.act add command -label [__ "Regenerate filename database"] -command \ |
| 2707 |
{run_external "mktexlsr" [__ "Regenerating filename database..."]} |
| 2708 |
.mn.act add command -label [__ "Regenerate formats"] -command \ |
| 2709 |
{run_external "fmtutil-sys --all" [__ "Rebuilding formats..."]} |
| 2710 |
.mn.act add command -label [__ "Regenerate fontmaps"] -command \ |
| 2711 |
{run_external "updmap-sys" [__ "Rebuilding fontmap files..."]} |
| 2712 |
#.mn.act add command -label [__ "Custom command"] -command custom_command |
| 2713 |
|
| 2714 |
.mn add cascade -label [__ "Options"] -menu .mn.opt -underline 0 |
| 2715 |
|
| 2716 |
# need to keep track of indices of this submenu |
| 2717 |
menu .mn.opt |
| 2718 |
set inx -1 |
| 2719 |
incr inx |
| 2720 |
.mn.opt add command -label "[__ "Repositories"] ..." \ |
| 2721 |
-command repository_dialog |
| 2722 |
incr inx |
| 2723 |
.mn.opt add cascade -label [__ "Paper ..."] -menu .mn.opt.paper |
| 2724 |
incr inx |
| 2725 |
|
| 2726 |
menu .mn.opt.paper |
| 2727 |
foreach p {A4 Letter} { |
| 2728 |
.mn.opt.paper add command -label $p -command \ |
| 2729 |
"set_all_papers [string tolower $p]" |
| 2730 |
} |
| 2731 |
.mn.opt.paper add command -label "[__ "Advanced"] ..." \ |
| 2732 |
-command papersize_advanced |
| 2733 |
|
| 2734 |
|
| 2735 |
if {$::tcl_platform(platform) ne "windows"} { |
| 2736 |
incr inx |
| 2737 |
set ::inx_platforms $inx |
| 2738 |
.mn.opt add command -label "[__ "Platforms"] ..." -command platforms_select |
| 2739 |
} |
| 2740 |
|
| 2741 |
if {0 && $::tcl_platform(platform) eq "windows" && $::wprocessor eq "AMD64"} { |
| 2742 |
.mn add cascade -label "64-bit Windows" -menu .mn.w64 |
| 2743 |
menu .mn.w64 |
| 2744 |
set inx -1 |
| 2745 |
incr inx |
| 2746 |
.mn.w64 add command -label [__ "About"] -command w64_about |
| 2747 |
incr inx |
| 2748 |
.mn.w64 add command -label [__ "Add/replace 64-bit binaries"] \ |
| 2749 |
-command "add_or_update_w64 remote" |
| 2750 |
incr inx |
| 2751 |
.mn.w64 add command -label [__ "Add/replace from local file"] \ |
| 2752 |
-command "add_or_update_w64 local" |
| 2753 |
incr inx |
| 2754 |
set ::inx_sync64 $inx |
| 2755 |
.mn.w64 add command -label [__ "Resynchronize with 32-bit"] \ |
| 2756 |
-command sync_w64_w32 |
| 2757 |
incr inx |
| 2758 |
set ::inx_remove64 $inx |
| 2759 |
.mn.w64 add command -label [__ "Remove 64-bit binaries"] \ |
| 2760 |
-command remove_w64 |
| 2761 |
} |
| 2762 |
|
| 2763 |
if {[llength $::langs] > 1} { |
| 2764 |
.mn add cascade -label [__ "GUI language"] \ |
| 2765 |
-menu .mn.lang |
| 2766 |
menu .mn.lang |
| 2767 |
foreach l [lsort $::langs] { |
| 2768 |
if {$l eq $::lang} { |
| 2769 |
set mlabel "$l *" |
| 2770 |
} else { |
| 2771 |
set mlabel $l |
| 2772 |
} |
| 2773 |
.mn.lang add command -label $mlabel \ |
| 2774 |
-command "set_language $l" |
| 2775 |
} |
| 2776 |
} |
| 2777 |
|
| 2778 |
.mn add cascade -label [__ "GUI font scaling"] \ |
| 2779 |
-menu .mn.fscale |
| 2780 |
menu .mn.fscale |
| 2781 |
.mn.fscale add command -label \ |
| 2782 |
"[__ "Current:"] [format {%.2f} $::tkfontscale]" |
| 2783 |
foreach s {0.6 0.8 1 1.2 1.6 2 2.5 3 3.8 5 6 7.5 9} { |
| 2784 |
.mn.fscale add command -label $s -command "set_fontscale $s" |
| 2785 |
} |
| 2786 |
|
| 2787 |
# browser-style keyboard shortcuts for scaling |
| 2788 |
bind . <Control-KeyRelease-minus> {zoom 0.8} |
| 2789 |
bind . <Control-KeyRelease-equal> {zoom 1.25} |
| 2790 |
bind . <Control-Shift-KeyRelease-equal> {zoom 1.25} |
| 2791 |
bind . <Control-KeyRelease-plus> {zoom 1.25} |
| 2792 |
bind . <Control-KeyRelease-0> {set_fontscale 1} |
| 2793 |
if {$::tcl_platform(os) eq "Darwin"} { |
| 2794 |
bind . <Command-KeyRelease-minus> {zoom 0.8} |
| 2795 |
bind . <Command-KeyRelease-equal> {zoom 1.25} |
| 2796 |
bind . <Command-Shift-KeyRelease-equal> {zoom 1.25} |
| 2797 |
bind . <Command-KeyRelease-plus> {zoom 1.25} |
| 2798 |
bind . <Command-KeyRelease-0> {set_fontscale 1} |
| 2799 |
} |
| 2800 |
|
| 2801 |
.mn add cascade -label [__ "Help"] -menu .mn.help -underline 0 |
| 2802 |
menu .mn.help |
| 2803 |
.mn.help add command -label [__ "About"] -command about_cmd |
| 2804 |
.mn.help add command -label [__ "TLShell Help"] -command tlshell_help |
| 2805 |
.mn.help add command -label [__ "Tlmgr Help"] -command tlmgr_help |
| 2806 |
|
| 2807 |
## menu end |
| 2808 |
|
| 2809 |
# wallpaper frame |
| 2810 |
# it is possible to set a background color for a toplevel, but on |
| 2811 |
# MacOS I did not find a way to determine the right $::default_bg |
| 2812 |
# color. Instead, all toplevels are given a wallpaper ttk::frame |
| 2813 |
# with the default ttk::frame color, which seems to work |
| 2814 |
# everywhere. |
| 2815 |
pack [ttk::frame .bg] -expand 1 -fill both |
| 2816 |
.bg configure -padding 5p |
| 2817 |
|
| 2818 |
# bottom of main window |
| 2819 |
pack [ttk::frame .endbuttons] -in .bg -side bottom -fill x |
| 2820 |
ttk::label .busy -textvariable ::busy -font hfont -anchor w |
| 2821 |
ppack .busy -in .endbuttons -side left |
| 2822 |
ppack [ttk::button .q -text [__ Quit] -command {destroy .}] \ |
| 2823 |
-in .endbuttons -side right |
| 2824 |
ppack [ttk::button .r -text [__ "Restart self"] -command restart_self] \ |
| 2825 |
-in .endbuttons -side right |
| 2826 |
ppack [ttk::button .t -text [__ "Restart tlmgr"] \ |
| 2827 |
-command {close_tlmgr; start_tlmgr}] \ |
| 2828 |
-in .endbuttons -side right |
| 2829 |
ttk::button .showlogs -text [__ "Show logs"] -command show_logs |
| 2830 |
ppack .showlogs -in .endbuttons -side right |
| 2831 |
|
| 2832 |
# top of main window |
| 2833 |
ppack [ttk::frame .topf] -in .bg -side top -anchor w -fill x |
| 2834 |
|
| 2835 |
if $::ddebug { |
| 2836 |
ppack [ttk::label .topf.test -text [info nameofexecutable]] |
| 2837 |
ppack [ttk::label .topf.test2 -text $::progname] |
| 2838 |
ppack [ttk::label .topf.test3 -text \ |
| 2839 |
[string range $::env(PATH) 0 59]] |
| 2840 |
} |
| 2841 |
|
| 2842 |
# left info frame |
| 2843 |
pack [ttk::frame .topfl] -in .topf -side left -anchor nw |
| 2844 |
|
| 2845 |
# subframe for repositories, to be filled by show_repos |
| 2846 |
pack [ttk::frame .toprepo] -in .topfl -side top -anchor w |
| 2847 |
|
| 2848 |
# various info (left frame) |
| 2849 |
pack [ttk::frame .topfll] -in .topfl -side top -anchor nw -pady {6p 0p} |
| 2850 |
ttk::label .topfll.lluptodate -text [__ "TL Manager up to date?"] -anchor w |
| 2851 |
pgrid .topfll.lluptodate -row 2 -column 0 -sticky w |
| 2852 |
ttk::label .topfll.luptodate -text [__ "Unknown"] -anchor w |
| 2853 |
pgrid .topfll.luptodate -row 2 -column 1 -sticky w |
| 2854 |
|
| 2855 |
ttk::label .topfll.llcmd -text [__ "Last tlmgr command:"] -anchor w |
| 2856 |
|
| 2857 |
pgrid .topfll.llcmd -row 3 -column 0 -sticky w |
| 2858 |
ttk::label .topfll.lcmd -textvariable ::last_cmd \ |
| 2859 |
-wraplength [expr {60*$::cw}] -justify left -anchor w |
| 2860 |
pgrid .topfll.lcmd -row 3 -column 1 -sticky w |
| 2861 |
|
| 2862 |
# right info frame |
| 2863 |
ppack [ttk::frame .topfr] -in .topf -side right -anchor ne |
| 2864 |
if {$::tcl_platform(platform) eq "windows"} { |
| 2865 |
pack [ttk::label .topfr.ladmin] -side top -anchor e |
| 2866 |
} |
| 2867 |
pack [ttk::label .topfr.lroot] -side top -anchor e |
| 2868 |
.topfr.lroot configure -text [__ "Root at %s" $::instroot] |
| 2869 |
pack [ttk::label .topfr.linfra] -side top -anchor e |
| 2870 |
pack [ttk::label .topfr.lshell] -side top -anchor e |
| 2871 |
|
| 2872 |
pack [ttk::separator .sp -orient horizontal] \ |
| 2873 |
-in .bg -side top -fill x -pady 3p |
| 2874 |
|
| 2875 |
# controls frame, between info frame and package list |
| 2876 |
pack [ttk::frame .middle] -in .bg -side top -fill x |
| 2877 |
pack [ttk::frame .pkcontrol] \ |
| 2878 |
-in .middle -side left -anchor nw -fill x |
| 2879 |
|
| 2880 |
# package list display options |
| 2881 |
ttk::label .lpack -text [string toupper [__ "Package list"]] \ |
| 2882 |
-font hfont |
| 2883 |
pack .lpack -in .pkcontrol -side top -padx 3p -pady {6p 6p} -anchor w |
| 2884 |
|
| 2885 |
pack [ttk::frame .pkfilter -relief groove -borderwidth 2 -padding 3p] \ |
| 2886 |
-in .pkcontrol -side top -anchor nw |
| 2887 |
# on my current linux, groove works only with a dimensionless borderwidth |
| 2888 |
|
| 2889 |
# separator columns |
| 2890 |
grid columnconfigure .pkfilter 1 -minsize 20p |
| 2891 |
grid [ttk::separator .pkfilter.sep1 -orient vertical] \ |
| 2892 |
-column 1 -row 0 -rowspan 5 -sticky ns |
| 2893 |
grid columnconfigure .pkfilter 3 -minsize 20p |
| 2894 |
grid [ttk::separator .pkfilter.sep3 -orient vertical] \ |
| 2895 |
-column 3 -row 0 -rowspan 5 -sticky ns |
| 2896 |
|
| 2897 |
# filter on status: inst, all, upd |
| 2898 |
ttk::label .pkfilter.lstat -font bfont -text [__ "Status"] |
| 2899 |
ttk::radiobutton .pkfilter.inst -text [__ "Installed"] -value inst \ |
| 2900 |
-variable ::stat_opt -command collect_and_display_filtered |
| 2901 |
ttk::radiobutton .pkfilter.notins -text [__ "Not installed"] -value notins \ |
| 2902 |
-variable ::stat_opt -command { |
| 2903 |
if {! $::have_remote} get_packages_info_remote |
| 2904 |
collect_and_display_filtered |
| 2905 |
} |
| 2906 |
ttk::radiobutton .pkfilter.alls -text [__ "All"] -value all \ |
| 2907 |
-variable ::stat_opt -command { |
| 2908 |
if {! $::have_remote} get_packages_info_remote |
| 2909 |
collect_and_display_filtered |
| 2910 |
} |
| 2911 |
ttk::radiobutton .pkfilter.upd -text [__ "Updatable"] -value upd \ |
| 2912 |
-variable ::stat_opt -command { |
| 2913 |
if {! $::have_remote} get_packages_info_remote |
| 2914 |
collect_and_display_filtered |
| 2915 |
} |
| 2916 |
grid .pkfilter.lstat -column 0 -row 0 -sticky w -padx {3p 50p} |
| 2917 |
pgrid .pkfilter.inst -column 0 -row 1 -sticky w |
| 2918 |
pgrid .pkfilter.notins -column 0 -row 2 -sticky w |
| 2919 |
pgrid .pkfilter.alls -column 0 -row 3 -sticky w |
| 2920 |
pgrid .pkfilter.upd -column 0 -row 4 -sticky w |
| 2921 |
|
| 2922 |
# filter on detail level: all, coll, schm |
| 2923 |
ttk::label .pkfilter.ldtl -font bfont -text [__ "Detail >> Global"] |
| 2924 |
ttk::radiobutton .pkfilter.alld -text [__ All] -value all \ |
| 2925 |
-variable ::dtl_opt -command collect_and_display_filtered |
| 2926 |
ttk::radiobutton .pkfilter.coll -text [__ "Collections and schemes"] \ |
| 2927 |
-value coll -variable ::dtl_opt -command collect_and_display_filtered |
| 2928 |
ttk::radiobutton .pkfilter.schm -text [__ "Only schemes"] -value schm \ |
| 2929 |
-variable ::dtl_opt -command collect_and_display_filtered |
| 2930 |
pgrid .pkfilter.ldtl -column 2 -row 0 -sticky w |
| 2931 |
pgrid .pkfilter.alld -column 2 -row 1 -sticky w |
| 2932 |
pgrid .pkfilter.coll -column 2 -row 2 -sticky w |
| 2933 |
pgrid .pkfilter.schm -column 2 -row 3 -sticky w |
| 2934 |
|
| 2935 |
# search interface |
| 2936 |
ttk::label .pkfilter.search_l -font bfont -text [__ "Search"] |
| 2937 |
ttk::entry .pkfilter.search_e -width 30 |
| 2938 |
ttk::radiobutton .pkfilter.search_n -variable ::search_desc \ |
| 2939 |
-value 0 -text [__ "By name"] |
| 2940 |
ttk::radiobutton .pkfilter.search_d -variable ::search_desc \ |
| 2941 |
-value 1 -text [__ "By name and description"] |
| 2942 |
pgrid .pkfilter.search_l -column 4 -row 0 -sticky w |
| 2943 |
pgrid .pkfilter.search_e -column 4 -row 1 -sticky w |
| 2944 |
pgrid .pkfilter.search_n -column 4 -row 2 -sticky w |
| 2945 |
pgrid .pkfilter.search_d -column 4 -row 3 -sticky w |
| 2946 |
|
| 2947 |
bind .pkfilter.search_e <KeyRelease> display_packages_info |
| 2948 |
bind .pkfilter.search_n <ButtonRelease> \ |
| 2949 |
{set ::search_desc 0; display_packages_info} |
| 2950 |
bind .pkfilter.search_d <ButtonRelease> \ |
| 2951 |
{set ::search_desc 1; display_packages_info} |
| 2952 |
|
| 2953 |
# actions |
| 2954 |
pack [ttk::frame .pkact] -in .middle -side right -anchor ne |
| 2955 |
ttk::button .mrk_inst -text [__ "Install marked"] -command { |
| 2956 |
install_pkgs "marked"} |
| 2957 |
ppack .mrk_inst -in .pkact -side top -fill x |
| 2958 |
ttk::button .mrk_upd -text [__ "Update marked"] -command { |
| 2959 |
update_pkgs "marked"} |
| 2960 |
ppack .mrk_upd -in .pkact -side top -fill x |
| 2961 |
ttk::button .mrk_rem -text [__ "Remove marked"] -command { |
| 2962 |
remove_pkgs "marked"} |
| 2963 |
ppack .mrk_rem -in .pkact -side top -fill x |
| 2964 |
if $::do_restore { |
| 2965 |
ttk::button .mrk_rest -text "[__ "Restore from backup"] ..." -command \ |
| 2966 |
restore_backups_dialog |
| 2967 |
ppack .mrk_rest -in .pkact -side top -fill x |
| 2968 |
} |
| 2969 |
ttk::button .upd_tlmgr -text [__ "Update tlmgr"] -command update_tlmgr |
| 2970 |
ppack .upd_tlmgr -in .pkact -side top -fill x |
| 2971 |
ttk::button .upd_all -text [__ "Update all"] -command update_all |
| 2972 |
ppack .upd_all -in .pkact -side top -fill x |
| 2973 |
|
| 2974 |
# marking all/none |
| 2975 |
pack [ttk::frame .pksel] \ |
| 2976 |
-in .bg -pady 6p -side top -fill x |
| 2977 |
pack [ttk::button .mrk_all -text [__ "Mark all displayed"] \ |
| 2978 |
-command mark_displayed] -in .pksel -side left |
| 2979 |
pack [ttk::button .mrk_none -text [__ "Mark none"] -command unmark_all] \ |
| 2980 |
-in .pksel -padx 6p -side left |
| 2981 |
ttk::label .binwarn \ |
| 2982 |
-text [__ "Only packages for installed platforms are displayed"] |
| 2983 |
pack .binwarn -in .pksel -padx 3p -side right -anchor s |
| 2984 |
|
| 2985 |
# packages list itself |
| 2986 |
pack [ttk::frame .fpkg] -in .bg -side top -fill both -expand 1 |
| 2987 |
ttk::treeview .pkglist -columns \ |
| 2988 |
{mk name localrev remoterev shortdesc} \ |
| 2989 |
-show headings -height 8 -selectmode extended \ |
| 2990 |
-yscrollcommand {.pkvsb set} |
| 2991 |
.pkglist heading mk -text "" -anchor w |
| 2992 |
.pkglist heading name -text [__ "Name"] -anchor w |
| 2993 |
.pkglist heading localrev -text [__ "Local rev. (ver.)"] -anchor w |
| 2994 |
.pkglist heading remoterev -text [__ "Remote rev. (ver.)"] -anchor w |
| 2995 |
.pkglist heading shortdesc -text [__ "Description"] -anchor w |
| 2996 |
.pkglist column mk -width [expr {$::cw * 3}] -stretch 0 |
| 2997 |
# column widths are resizable: no need to accommodate the longest names |
| 2998 |
.pkglist column name -width [expr {$::cw * 25}] -stretch 1 |
| 2999 |
.pkglist column localrev -width [expr {$::cw * 18}] -stretch 0 |
| 3000 |
.pkglist column remoterev -width [expr {$::cw * 18}] -stretch 0 |
| 3001 |
.pkglist column shortdesc -width [expr {$::cw * 50}] -stretch 1 |
| 3002 |
|
| 3003 |
ttk::scrollbar .pkvsb -orient vertical -command {.pkglist yview} |
| 3004 |
ppack .pkglist -in .fpkg -side left -expand 1 -fill both |
| 3005 |
ppack .pkvsb -in .fpkg -side left -fill y |
| 3006 |
|
| 3007 |
# "#1" refers to the first column (with mark symbols) |
| 3008 |
bind .pkglist <space> {toggle_marked_pkg [.pkglist focus] "#1"} |
| 3009 |
bind .pkglist <Return> {toggle_marked_pkg [.pkglist focus] "#1"} |
| 3010 |
# only toggle when column is "mk" i.e. #1 |
| 3011 |
bind .pkglist <ButtonRelease-1> {toggle_marked_pkg [ |
| 3012 |
.pkglist identify item %x %y] [.pkglist identify column %x %y]} |
| 3013 |
|
| 3014 |
menu .pkg_popup ; # entries added on-the-fly |
| 3015 |
bind .pkglist <<RightClick>> {do_package_popup_menu %x %y %X %Y} |
| 3016 |
if $::plain_unix { |
| 3017 |
bind .pkg_popup <Leave> {.pkg_popup unpost} |
| 3018 |
} |
| 3019 |
|
| 3020 |
wm protocol . WM_DELETE_WINDOW {cancel_or_destroy .q .} |
| 3021 |
wm resizable . 1 1 |
| 3022 |
wm state . normal |
| 3023 |
raise . |
| 3024 |
} |
| 3025 |
|
| 3026 |
proc display_all_data {} { |
| 3027 |
# (re)display all data |
| 3028 |
if {$::tcl_platform(platform) eq "windows"} { |
| 3029 |
.topfr.ladmin configure -text \ |
| 3030 |
[expr {$::multiuser ? [__ "Multi-user"] : [__ "Single-user"]}] |
| 3031 |
} |
| 3032 |
# revision numbers for tlmgr and tlshell |
| 3033 |
.topfr.linfra configure -text \ |
| 3034 |
"tlmgr: r[dict get $::pkgs texlive.infra localrev]" |
| 3035 |
.topfr.lshell configure -text \ |
| 3036 |
"tlshell: r[dict get $::pkgs tlshell localrev]" |
| 3037 |
show_repos |
| 3038 |
display_packages_info |
| 3039 |
display_updated_globals |
| 3040 |
} |
| 3041 |
|
| 3042 |
# to be invoked at initialization and after a font scaling- or language change |
| 3043 |
proc rebuild_interface {} { |
| 3044 |
foreach c [winfo children .] {catch {destroy $c}} |
| 3045 |
|
| 3046 |
# for busy/idle indicators |
| 3047 |
set ::busy [__ "Idle"] |
| 3048 |
populate_main |
| 3049 |
display_all_data |
| 3050 |
if {$::tcl_platform(platform) eq "windows"} {wm deiconify .} |
| 3051 |
} |
| 3052 |
|
| 3053 |
##### initialize ###################################################### |
| 3054 |
|
| 3055 |
proc initialize {} { |
| 3056 |
# seed random numbers |
| 3057 |
expr {srand([clock seconds])} |
| 3058 |
|
| 3059 |
# directory for temp files |
| 3060 |
set attemptdirs {} |
| 3061 |
foreach tmp {TMPDIR TEMP TMP} { |
| 3062 |
if {$tmp in [array names ::env]} { |
| 3063 |
lappend attemptdirs $::env($tmp) |
| 3064 |
} |
| 3065 |
} |
| 3066 |
if {$::tcl_platform(platform) eq "unix"} { |
| 3067 |
lappend attemptdirs "/tmp" |
| 3068 |
} |
| 3069 |
lappend attemptdirs [pwd] |
| 3070 |
set ::tempsub "" |
| 3071 |
foreach tmp $attemptdirs { |
| 3072 |
if {$::tcl_platform(platform) eq "windows"} { |
| 3073 |
regsub -all {\\} $tmp {/} tmp |
| 3074 |
} |
| 3075 |
if {[file isdirectory $tmp]} { |
| 3076 |
# no real point in randomizing directory name itself |
| 3077 |
if {$::tcl_platform(platform) eq "unix"} { |
| 3078 |
set ::tempsub [file join $tmp $::env(USER)] |
| 3079 |
} else { |
| 3080 |
set ::tempsub [file join $tmp $::env(USERNAME)] |
| 3081 |
} |
| 3082 |
append ::tempsub "-tlshell" |
| 3083 |
if {! [catch {file mkdir $::tempsub}]} {break} ;# success |
| 3084 |
} |
| 3085 |
} |
| 3086 |
|
| 3087 |
if {$::tempsub eq "" || [file isdirectory $::tempsub] == 0} { |
| 3088 |
error "Cannot create directory for temporary files" |
| 3089 |
} |
| 3090 |
# temp file for stderr |
| 3091 |
set ::err_file [maketemp ".err_tlshl"] |
| 3092 |
|
| 3093 |
# logfile |
| 3094 |
if $::ddebug { |
| 3095 |
set fname [file join $::tempsub \ |
| 3096 |
[clock format [clock seconds] -format {%H:%M}]] |
| 3097 |
set ::flid [open $fname w] |
| 3098 |
} |
| 3099 |
|
| 3100 |
# store language in tlmgr configuration |
| 3101 |
save_config_var "gui-lang" $::lang |
| 3102 |
|
| 3103 |
# in case we are going to do something with json: |
| 3104 |
# add json subdirectory to auto_path, but at low priority |
| 3105 |
# since the tcl/tk installation may already have a better implementation. |
| 3106 |
# Trust kpsewhich to find out own directory and bypass symlinks. |
| 3107 |
#set tlsdir [file dirname [exec kpsewhich -format texmfscripts tlshell.tcl]] |
| 3108 |
#lappend ::auto_path [file join $tlsdir "json"] |
| 3109 |
|
| 3110 |
populate_main |
| 3111 |
|
| 3112 |
# testing writablilty earlier led to sizing problems |
| 3113 |
if {! [dir_writable $::instroot]} { |
| 3114 |
set ans [tk_messageBox -type yesno -icon warning -message \ |
| 3115 |
[__ "%s is not writable. You can probably not do much. |
| 3116 |
Are you sure you want to continue?" $::instroot]] |
| 3117 |
if {$ans ne "yes"} {exit} |
| 3118 |
} |
| 3119 |
# handle -h[elp] and -v[ersion parameters; |
| 3120 |
# do not pass these on to the upcoming tlmgr pipe |
| 3121 |
set i $::argc |
| 3122 |
while 1 { |
| 3123 |
incr i -1 |
| 3124 |
if {$i<0} break |
| 3125 |
set s [lindex $::argv $i] |
| 3126 |
if {$s eq "-h" || $s eq "-help"} { |
| 3127 |
tk_messageBox -message [__ "See internal help"] \ |
| 3128 |
-icon info -type ok |
| 3129 |
set ::argv [lreplace $::argv $i $i] |
| 3130 |
} elseif {$s eq "-v" || $s eq "-version"} { |
| 3131 |
set ::argv [lreplace $::argv $i $i] |
| 3132 |
} |
| 3133 |
} |
| 3134 |
set ::argc [llength $::argv] |
| 3135 |
|
| 3136 |
start_tlmgr {*}$::argv |
| 3137 |
if {$::tcl_platform(platform) eq "windows"} { |
| 3138 |
run_cmd_waiting "option multiuser" |
| 3139 |
set ::multiuser 0 |
| 3140 |
foreach l $::out_log { |
| 3141 |
if [regexp {^\s*multiuser\s+([01])\s*$} $l d ::multiuser] break |
| 3142 |
} |
| 3143 |
} |
| 3144 |
run_cmd_waiting "version" |
| 3145 |
foreach l $::out_log { |
| 3146 |
if {[string range $l 0 8] eq "tlversion"} { |
| 3147 |
set ::year [string range $l end-3 end] |
| 3148 |
break |
| 3149 |
} |
| 3150 |
} |
| 3151 |
get_packages_info_local |
| 3152 |
collect_filtered |
| 3153 |
get_repos_from_tlmgr |
| 3154 |
display_all_data |
| 3155 |
}; # initialize |
| 3156 |
|
| 3157 |
initialize |