teaget

What?

Teaget is a tcl only script that can be used as a command line utility to retrieve packages, applications and profiles from the ActiveTcl web repository. Teaget mimics some of commands implemented by teacup, but is not part of ActiveTcl.

Why?

The idea comes to me after read this discussion between jcw and Jeff Hobbs on "Teacup/-pot questions" [L1 ], particularly this statement:

  > Which brings up multiple-choice question 3a: is there a way to access
  > a teapot repository directly over the net? Yes / no / please don't /
  > not ever / not yet / no interest?

  http://teapot.activestate.com/

  While not intended for human consumption, the server itself does serve
  something you can browse.

  Jeff

My intention was to make a tcl only script to download and install packages from the repository. I think teaget solve some of the troubles and cons of teacup:

  • teacup is a closed source application, and not can be adapted to suit the developer needs. Teaget instead can be "hacked" or converted to a tcl extension easily, and can be used in several ways.
  • teacup is really slow, even to search a package that match a pattern. Just make this test:
  % time {exec teacup search Expect >@ stdout}
  entity  name         version                   platform
  ------- ------------ ------------------------- ---------------------
  package Expect       5.43                      win32-ix86
  package Expect       5.43.0                    aix-powerpc
  package Expect       5.43.0                    hpux-parisc
  package Expect       5.43.0                    linux-glibc2.2-ix86
  ...
  ------- ------------ ------------------------- ---------------------
  115 entities found

  Problems which occurred during the operation:
  * http://teapot.activestate.com : Retrieval of INDEX failed (timeout).
          The system used slow(er) remote queries to keep working.
          Please use the 'teacup timeout' command to adjust or
          disable the transfer timeout. It is currently set to 30 seconds.

  34059168 microseconds per iteration

My internet connection is not fast really, but 34 seconds are too much for me.

Just make the same with teaget. First we have to 'refresh' the packages list, wich takes around 16 seconds:

  % time {exec teaget refresh >@ stdout}
  Retrieving 'list'
  15834230 microseconds per iteration

But then I can make search without require retrieve the package list every time.

  % time {exec teaget search Expect >@ stdout}
  package Expect 5.44.1.3 linux-glibc2.3-ix86 0
  package Expect 5.44.1.3 linux-glibc2.3-x86_64 0
  package Expect 5.44.1.4 linux-glibc2.3-x86_64 0
  ...
  25 entities found.
  74308 microseconds per iteration

Really fast! Note also that teaget only show packages for architectures selected.

There is no secrets for the difference in the execution time of the same command: teaget make a cache with the big package list and the details page for every package when is used. These pages not change all the time, so can be very efficient to store it. If you want to clear the cache, just run teaget purge.

  • teaget makes easy to work with tclkits. The teaget 'link' command can be used to link a tclkit to the local respository. In facts, teaget can link a tclkit to a teacup repository too.
  • teacup make a database with the repository state. If some goes wrong the entire repository may not work. Teaget only relies on the local filesystem and the info pages in the web repository. This has some cons, of course, for instance teaget do not implement the uninstall command. But for normal purposes this is enough.

Where?

I made a google code site to store some of my tcl projects. Teaget is a single tcl file that can be downloaded from here: [L2 ]

Be sure to select the latest version, and you must rename it to "teaget.tcl" after download.

Usage

Settings

In order to use teaget you need to edit some settings:

  • settings(repo): web address to the ActiveTcl repository. Don't touch.
  • settings(teapot): path to the local repository directory. Can be absolute or relative to the teaget.tcl file, using [info script].
  • settings(platforms): list of platforms used. 'tcl' must allways be present.
  • settings(cache): directory used as cache.
  • settings(tclVersion): maximum tcl version. For example if set to 8.4, only packages requiring tcl 8.4 can be installed.
  • settings(teapot,*,*): these settings are used to customize the directories layout within the local repository. Leave as default.

Link tclkit

To use teaget with a tclkit you need another tclkit or tclsh and then run:

  > tclsh teaget.tcl link path-to-tclkit
  (choose the tclkit architecture)
  Tclkit 'path-to-tclkit' patched successfully

Test

Then using the patched tclkit:

  > tclkit
  % package require tdom
  can't find package tdom
  % exit
  > tclkit teaget.tcl install tdom
  Checking dependencies of entity 'tdom'
  Retrieving 'package/name/tdom/ver/0.8.3/arch/win32-ix86/details'
  The following entities need to be installed in your system.
  package tdom 0.8.3 win32-ix86 0
  1 entities required.
  1 entities to install.
  Do you want to continue? (y/n):
  Downloading '/package/name/tdom/ver/0.8.3/arch/win32-ix86/file.zip'
  Progress: 177.967 Kb / 177.967 Kb (100%)

  > tclkit
  % package require tdom
  0.8.3

Add teaget to the path

Windows:

  • Create a directory, for instance "D:/Tcl/bin" and add to the PATH environment variable
  • Put a copy of tclkitsh.exe in "D:/Tcl/bin"
  • Create a file like "D:/Tcl/bin/teaget.bat" with this:
  @tclkitsh path-to-teaget.tcl %*

Linux:

  • Create a directory, for instance "/usr/local/bin" and add to the PATH environment variable
  • Put a copy of tclkit in "/usr/local/bin"
  • Create a file like "/usr/local/bin/teaget" with this:
  #!/bin/sh
  exec tclkit path-to-teaget.tcl ${1+"$@"}

I use this to keep teaget.tcl in a user directory, so I can edit without use sudo.

Subcommands auto-completion

To enable the auto-completion of subcommands from the console (bash), these steps are required:

  • Create a file 'completion.bash' with this content:
  _teaget()
  {
      local cur prev opts
      COMPREPLY=()
      cur="${COMP_WORDS[COMP_CWORD]}"
      prev="${COMP_WORDS[COMP_CWORD-1]}"
      opts="help search refresh link unlink purge install settings"

      if [[ ${cur} == * ]] ; then
          COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
          return 0
      fi
  }
  complete -F _teaget teaget
  • Add to the file '.bashrc' in your home directory this line:
  source path-to-completion.bash
  • Open a new console.
  • Then you can type:
  > teag<TAB> i<TAB>

and the line will be completed to:

  > teaget install

Also you can type:

  > teaget <TAB>

and all the possibilities should be displayed:

  > teaget 
  help      link      refresh   settings  
  install   purge     search    unlink  

If you are lazy to type like me, you will love this feature!

Discussion

gasty Please let me know your opinions/critics/whatever.

RLH So this snags them over HTTP like a Tcl wget? If that is so, good! I know I can set a "proxy" for teacup but my firewall guys never give that out and this might let me work around that.

If there are teacup commands that would help to give you an idea for the defaults above maybe those would be good to list. For example, teacup default, tells you the location of the teapot directory. Just a thought...

gasty Try "teaget settings":

  >teaget settings
  * TEAget settings *
    Directory used as cache: 'C:/Documents and Settings/gaston/.teaget/cache'
    Tcl version: '8.6'
    Platforms supported:
      win32-ix86
      tcl
    Library paths:
      D:/Tcl/teapot/win32-ix86
      D:/Tcl/teapot/tcl

LV You should be cautious about mixing teaget and teacup directories. There are checksums, etc. that teacup maintains and if you start adding new files or overwriting files you could end up with your local repository in an unusable state. gasty That is very true!

jblz Rock on! Great work gasty!