Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a9c1b47b8594a762f19383c3b93416a1a0682d6e
Ticket: 218337ffffffffffffffffffffffffffffffffff
Package present produces an error and breaks out of loop
User & Date: nobody on 2000-10-26 00:56:24
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
    
    
  4. foundin changed to: "obsolete: 8.3b2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "56. LibTomMath"
  10. title changed to:
    Package present produces an error and breaks out of loop
    
  11. type changed to: "RFE"