Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Package present produces an error and breaks out of loop

Closed / Fixed218337ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:56:24
OriginalBugID: 3974 Bug
Version: 8.3b2
SubmitDate: '2000-01-04'
LastModified: '2000-02-07'
Severity: LOW
Status: Closed
Submitter: shawn
ChangedBy: hobbs
OS: Windows NT
FixedDate: '2000-10-25'
ClosedDate: '2000-02-07'


Package present produces an error and breaks out of loop -  return from script is an error - package is not present - it would be nice if it told something about the state of the interpretor - so it could be used as a test - I'd like it to return zero if it's not in an interactive interpretor  - and it would be nicer still - if it were called without any arguments - if it could tell you all the packages currently loaded.  much in the same way info loaded - works.  

What would really be nice is if it were an info packages comnmand - returning a list if no options are used and a version number if a package is specified.  

script ------------------

# This probably doesn't need to produce an error either 

catch { package require {} }

foreach a " [package names] " {
     puts $a 
     set c "100.0"
     set d '''
   if ![ package present  $a ] { 
# to match the extra if a bove 

#     catch { package present $a } msg 
#     if [regsub -- not $msg  nothing msg ] { 
           foreach b " [package versions $a] " {  
                 lappend l  " $a $b "      
                 puts $l 
                 puts " I could load $a here" 
                 if  { [package vcompare $b $c] == -1 } { 
                      if [string equal $a $d ] { 
                           package forget $a 
                      } 
                }
                set c $b 
                set d $a

                package require -exact $a $b 

          }  
     }
    }
}



Below is an example of how getting all the packages is done,
and whether they have been loaded or not.

proc tkConPkgMenu {m app type} {
    global TKCON

    # just in case stuff has been added to the auto_path
    # we have to make sure that the errorInfo doesn't get screwed up
    tkConEvalAttached {
set __tkcon_error $errorInfo
catch {package require bogus-package-name}
set errorInfo ${__tkcon_error}
unset __tkcon_error
    }
    $m delete 0 end
    foreach pkg [tkConEvalAttached [list info loaded {}]] {
set loaded([lindex $pkg 1]) [package provide $pkg]
    }
    foreach pkg [lremove [tkConEvalAttached {package names}] Tcl] {
set version [tkConEvalAttached [list package provide $pkg]]
if {[string compare {} $version]} {
    set loaded($pkg) $version
} elseif {![info exists loaded($pkg)]} {
    set loadable($pkg) [list package require $pkg]
}
    }
    foreach pkg [tkConEvalAttached {info loaded}] {
set pkg [lindex $pkg 1]
if {![info exists loaded($pkg)] && ![info exists loadable($pkg)]} {
    set loadable($pkg) [list load {} $pkg]
}
    }
    set npkg 0
    foreach pkg [lsort -dictionary [array names loadable]] {
foreach v [tkConEvalAttached [list package version $pkg]] {
    set brkcol [expr {([incr npkg]%16)==0}]
    $m add command -label "Load $pkg ($v)" -command  "tkConEvalOther [list $app] $type $loadable($pkg) $v"  -columnbreak $brkcol
}
    }
    if {[info exists loaded] && [info exists loadable]} {
$m add separator
    }
    foreach pkg [lsort -dictionary [array names loaded]] {
$m add command -label "${pkg}$loaded($pkg) Loaded" -state disabled
    }
} 
-- 02/07/2000 hobbs
welch Closed ticket [218337ffff]. [History diff]2000-10-26 08:20:07
dgp Open ticket [218337ffff]. [History diff]2001-04-06 02:13:43
dgp Closed ticket [218337ffff]. [History diff]2001-04-06 02:14:08
Log in (anonymous is fine) to add a comment.