Check-in [8e422c69d7]
Overview
Comment:Improved buildinfo URL guessing. Fixed Tclkits with no packages having a dash an the end of the filename. Do not use [file attributes] to restore Jim Tcl compatibility.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8e422c69d7cb1a11c2fe96ab41ddadadc9898138
User & Date: dbohdan on 2016-03-08 19:12:14
Other Links: manifest | tags
Context
2016-03-08
19:53
Merged private commit check-in: c51d83c360 user: dbohdan tags: trunk
19:22
Renamed the file build/utils/kitcreator-downloader.tcl "download-tclkit.tcl" Leaf check-in: be047fad60 user: dbohdan tags: private
19:12
Improved buildinfo URL guessing. Fixed Tclkits with no packages having a dash an the end of the filename. Do not use [file attributes] to restore Jim Tcl compatibility. check-in: 8e422c69d7 user: dbohdan tags: trunk
18:28
KitCreator downloader: Make the downloaded Tclkit executable check-in: ffc6b46c9f user: dbohdan tags: trunk
Changes

Modified build/utils/kitcreator-downloader.tcl from [a023a886a6] to [d8b2ec6c7d].

     1      1   #!/usr/bin/env tclsh
     2         -# KitCreator downloader v0.2.1 -- download Tclkits created with the KitCreator
     3         -# Web Interface. Works with Tcl 8.5+ and Jim Tcl v0.75+.
            2  +# KitCreator downloader v0.2.2 -- download Tclkits created with the KitCreator
            3  +# Web Interface. Works with Tcl 8.5+ and Jim Tcl v0.75+. This script requires
            4  +# that cURL be available through [exec curl].
     4      5   # Copyright (C) 2016, dbohdan.
     5      6   # License: MIT.
     6      7   proc download url {
     7         -    # Guess at what the buildinfo URL might be if we are given, e.g., a building
     8         -    # page URL.
     9         -    set url [string map {/building {}} $url]
    10      8       if {![string match */buildinfo $url]} {
    11         -        append url /buildinfo
            9  +        # Guess at what the buildinfo URL might be if we are given, e.g., a
           10  +        # building page URL.
           11  +        set url [string map {/building {}} $url]
           12  +        set checksum {}
           13  +        foreach piece [split $url /] {
           14  +            if {[regexp {^[a-z0-9]{40}$} $piece checksum]} {
           15  +                break
           16  +            }
           17  +        }
           18  +        if {$checksum eq {}} {
           19  +            error "can't determine how to get the from the URL \"$url\" to the\
           20  +                    buildinfo"
           21  +        }
           22  +        set url [regexp -inline "^.*$checksum" $url]/buildinfo
    12     23       }
    13     24   
    14     25       set buildInfo [exec curl -s $url]
    15     26   
    16     27       set filename [dict get $buildInfo filename]
    17     28       append filename -[dict get $buildInfo tcl_version]
    18     29       append filename -[dict get $buildInfo platform]
    19     30   
    20         -    foreach option {staticpkgs threaded debug} {
    21         -        if {[dict exists $buildInfo options $option] &&
    22         -                [dict get $buildInfo options $option]} {
    23         -            append filename -$option
           31  +    if {[llength [dict get $buildInfo packages]] > 0} {
           32  +        foreach option {staticpkgs threaded debug} {
           33  +            if {[dict exists $buildInfo options $option] &&
           34  +                    [dict get $buildInfo options $option]} {
           35  +                append filename -$option
           36  +            }
    24     37           }
           38  +        append filename -[join [dict get $buildInfo packages] -]
    25     39       }
    26     40   
    27         -    append filename -[join [dict get $buildInfo packages] -]
    28         -
    29     41       set tail [file tail $url]
    30     42       # We can't use [file dirname] here because it will transform
    31         -    # "http://example.com" into "http:/example.com".
           43  +    # "http://example.com/" into "http:/example.com/".
    32     44       set baseUrl [string range $url 0 end-[string length $tail]]
    33     45       if {[string index $baseUrl end] ne {/}} {
    34     46           append baseUrl /
    35     47       }
    36     48       set tclkit $baseUrl[dict get $buildInfo filename]
    37     49   
    38     50       puts "Downloading $tclkit to $filename..."
    39     51       exec curl -o $filename $tclkit >@ stdout 2>@ stderr
    40         -    file attributes $filename -permissions +x
           52  +
           53  +    catch {exec chmod +x $filename}
    41     54   }
    42     55   
    43     56   set url [lindex $argv 0]
    44     57   if {$url eq {}} {
    45     58       puts "usage: $argv0 url"
    46         -    puts {The URL must be a KitCreator Web Interface buildinfo page.}
           59  +    puts {The URL should be a KitCreator Web Interface buildinfo page.\
           60  +            If it is instead, e.g., a building page or a direct Tclkit download\
           61  +            URL, the script will try to guess where the buildinfo is.}
    47     62   } else {
    48     63       download $url
    49     64   }