tkpkg revision 950
1950Sjkh#!/usr/local/bin/wish -f 2950Sjkh#$Id: pkg,v 1.1 1993/09/04 17:06:09 jkh Exp $ 3950Sjkh# 4950Sjkh#$Log: pkg,v $ 5950Sjkh# Revision 1.1 1993/09/04 17:06:09 jkh 6950Sjkh# Added Rich's wish front-end. 7950Sjkh# 8950Sjkh# Revision 1.6 1993/09/03 23:37:22 rich 9950Sjkh# warn user if no tar archives are found in the current directory. 10950Sjkh# removed the revision string from the lower text frame. 11950Sjkh# 12950Sjkh# Revision 1.5 1993/09/03 15:48:04 rich 13950Sjkh# glob for .tar.gz, .tar.z and .tar.Z looking for archives 14950Sjkh# 15950Sjkh# Revision 1.4 1993/08/28 15:53:59 rich 16950Sjkh# added version and date info to lower text window. 17950Sjkh# 18950Sjkh# Revision 1.3 1993/08/28 15:47:12 rich 19950Sjkh# filtered out ^Ls in pkg_* output. 20950Sjkh# 21950Sjkh# 22950Sjkhset pkgname "" 23950Sjkhwm title . "Package Installation" 24950Sjkh#-------------------------------------------------------------- 25950Sjkh# The top level main window, consisting of a bar of buttons and a list 26950Sjkh# of packages and a description of the current package. 27950Sjkh#-------------------------------------------------------------- 28950Sjkhframe .menu -relief raised -borderwidth 1 29950Sjkhframe .frame -borderwidth 4 30950Sjkh 31950Sjkhscrollbar .frame.scroll -relief sunken -command ".frame.list yview" 32950Sjkhlistbox .frame.list -yscroll ".frame.scroll set" -relief sunken -setgrid 1 33950Sjkhpack append .frame .frame.scroll {right filly} \ 34950Sjkh .frame.list {left expand fill} 35950Sjkh 36950Sjkh# build the lower window shoing the complete description of a pacage 37950Sjkhframe .f -borderwidth 4 38950Sjkhtext .f.t -width 80 -height 20 -yscrollcommand ".f.s set" -relief sunken 39950Sjkh 40950Sjkh# Initially display instructions in this window. Erase the 41950Sjkh# instructions and show the package description when the user clicks 42950Sjkh# on a package. 43950Sjkh# 44950Sjkh.f.t insert end "Double click on a package above to see it's 45950Sjkhcomplete description here." 46950Sjkhscrollbar .f.s -relief sunken -command ".f.t yview" 47950Sjkhpack append .f .f.s {right filly} .f.t {left expand fill} 48950Sjkh 49950Sjkhbind .frame.list <Double-Button-1> \ 50950Sjkh {foreach i [selection get] {do_description $i}} 51950Sjkhpack append . .menu {top fill} \ 52950Sjkh .f {bottom expand fill} \ 53950Sjkh .frame {bottom expand fill} 54950Sjkh 55950Sjkh#---------------------------------------------------------------- 56950Sjkh# Make menu bar: 57950Sjkh#---------------------------------------------------------------- 58950Sjkhbutton .menu.inst -text "Install" \ 59950Sjkh -command "apply_to_pkg \"pkg_add -v\"" 60950Sjkhbutton .menu.dein -text "Deinstall" \ 61950Sjkh -command "apply_to_pkg \"pkg_delete -v\"" 62950Sjkhbutton .menu.installed -text "What is Installed?" \ 63950Sjkh -command "list_pkgs \"pkg_info -I -a |tr ' ' ' '\"" 64950Sjkhbutton .menu.available -text "What can I install?" \ 65950Sjkh -command "list_pkgs \"pkg_info -I -c [glob -nocomplain *.{tgz,tar.z,tar.gz,tar.Z}] |tr ' ' ' '\"" 66950Sjkhbutton .menu.cont -text "Contents?" \ 67950Sjkh -command "global pkgname; apply_to_pkg \"pkg_info -d -v |tr -d ''\"" 68950Sjkhbutton .menu.quit -text "Quit" -command "destroy ." 69950Sjkhbutton .menu.help -text "Help" -command "do_help" 70950Sjkh 71950Sjkhpack append .menu \ 72950Sjkh .menu.inst left \ 73950Sjkh .menu.dein left \ 74950Sjkh .menu.installed left \ 75950Sjkh .menu.available left \ 76950Sjkh .menu.cont left \ 77950Sjkh .menu.quit left \ 78950Sjkh .menu.help right 79950Sjkh#------------------------------------------------------- 80950Sjkh# Display the package description. 81950Sjkh#------------------------------------------------------- 82950Sjkhproc list_pkgs {s} { 83950Sjkh set line "" 84950Sjkh set f [eval "open {| csh -c \"$s\" } r"] 85950Sjkh .frame.list delete 0 end 86950Sjkh while {[gets $f line] > 0} { 87950Sjkh .frame.list insert end $line 88950Sjkh } 89950Sjkh close $f 90950Sjkh} 91950Sjkh 92950Sjkh# display the list of available packages 93950Sjkhset archives [glob -nocomplain *.{tgz,tar.z,tar.gz,tar.Z}] 94950Sjkhif {$pkgname == ""} { 95950Sjkh .frame.list delete 0 end 96950Sjkh .frame.list insert end "Warning: no compressed tar archives files found." 97950Sjkh} else { 98950Sjkh list_pkgs "pkg_info -I -c $archives |tr ' ' ' '" 99950Sjkh} 100950Sjkh 101950Sjkh#------------------------------------------------------- 102950Sjkh# Display the package description. 103950Sjkh#------------------------------------------------------- 104950Sjkhproc do_description {s} { 105950Sjkh global pkgname 106950Sjkh regexp {[^ ]*} $s filename 107950Sjkh set pkgname $filename 108950Sjkh .f.t delete 0.0 end 109950Sjkh set cmd "pkg_info -d $filename |tr -d ''" 110950Sjkh set f [eval "open {| csh -c \"$cmd\" } r"] 111950Sjkh while {![eof $f]} { 112950Sjkh .f.t insert end [read $f] 113950Sjkh } 114950Sjkh} 115950Sjkh#------------------------------------------------------- 116950Sjkh# package install window. 117950Sjkh#------------------------------------------------------- 118950Sjkhproc do_help {{w .help}} { 119950Sjkh catch {destroy $w} 120950Sjkh toplevel $w 121950Sjkh wm title $w "Help" 122950Sjkh wm iconname $w "Help" 123950Sjkh button $w.ok -text OK -command "destroy $w" 124950Sjkh message $w.t -relief raised -bd 2 \ 125950Sjkh -text "You can install, deinstall and list info on the available packages. To select a package and see it's complete description, press mouse button 1 over the package name. To install a selected package, press the Install button. To exit, press the \"Quit\" button." 126950Sjkh pack append $w $w.ok {bottom fillx} $w.t {expand fill} 127950Sjkh} 128950Sjkh#------------------------------------------------------- 129950Sjkh# Apply a command to a package. 130950Sjkh#------------------------------------------------------- 131950Sjkhproc apply_to_pkg {s} { 132950Sjkh global pkgname 133950Sjkh .f.t delete 0.0 end 134950Sjkh if {$pkgname == ""} { 135950Sjkh .f.t insert end "You must double click on a package name first!" 136950Sjkh } else { 137950Sjkh .f.t delete 0.0 end 138950Sjkh .f.t insert end "Running: $s $pkgname\n" 139950Sjkh set f [eval "open {| $s $pkgname} r"] 140950Sjkh while {![eof $f]} { 141950Sjkh .f.t insert end [read $f 64] 142950Sjkh } 143950Sjkh } 144950Sjkh} 145950Sjkh#------------------------------------------------------- 146950Sjkh# Invoke an arbitrary command. 147950Sjkh#------------------------------------------------------- 148950Sjkhproc do_command {s} { 149950Sjkh .f.t delete 0.0 end 150950Sjkh .f.t insert end "Running: $s\n" 151950Sjkh set f [eval "open {| $s} r"] 152950Sjkh while {![eof $f]} { 153950Sjkh .f.t insert end [read $f 64] 154950Sjkh } 155950Sjkh} 156950Sjkh# local variables: 157950Sjkh# mode: csh 158950Sjkh# compile-command: "" 159950Sjkh# comment-start: "# " 160950Sjkh# comment-start-skip: "# " 161950Sjkh# end: 162