Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add Tcl-based tool capable of automatically updating the file sizes and hashes on the downloads page. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
3f0042b2f5714d6b1fe80d7c51dc8fb5 |
User & Date: | mistachkin 2011-10-03 09:53:28.438 |
Context
2011-10-03
| ||
10:01 | Minor tweaks to file info updating tool. check-in: 836eef1fd5 user: mistachkin tags: trunk | |
09:53 | Add Tcl-based tool capable of automatically updating the file sizes and hashes on the downloads page. check-in: 3f0042b2f5 user: mistachkin tags: trunk | |
05:49 | Clean up after NuGet packages left in the source directory. check-in: 1a80776bac user: mistachkin tags: trunk | |
Changes
Added Setup/updateFileInfo.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | ############################################################################### # # updateFileInfo.tcl -- File Metadata Updating Tool # # WARNING: This tool requires that the Fossil binary somewhere along the PATH. # # Written by Joe Mistachkin. # Released to the public domain, use at your own risk! # ############################################################################### proc readFile { fileName } { set file_id [open $fileName RDONLY] fconfigure $file_id -encoding binary -translation binary set result [read $file_id] close $file_id return $result } proc writeFile { fileName data } { set file_id [open $fileName {WRONLY CREAT TRUNC}] fconfigure $file_id -encoding binary -translation binary puts -nonewline $file_id $data close $file_id return "" } proc getFileSize { fileName } { # # NOTE: Return the number of mebibytes in the file with two digits after the # decimal. # return [format %.2f [expr {[file size $fileName] / 1048576.0}]] } proc getFileHash { fileName } { # # NOTE: Return the SHA1 hash of the file, making use of Fossil via [exec] to # actually calculate it. # return [string trim [lindex [regexp -inline -nocase -- {[0-9A-F]{40} } \ [exec fossil sha1sum $fileName]] 0]] } # # NOTE: Grab the fully qualified directory name of the directory containing # this script file. # set path [file normalize [file dirname [info script]]] # # NOTE: Grab the name of the file to be updated from the command line, if # available; otherwise, use the default (i.e. "../www/downloads.wiki"). # if {[info exists argv] && [llength $argv] > 0} then { set updateFileName [lindex $argv 0] } else { set updateFileName [file join [file dirname $path] www downloads.wiki] } # # NOTE: Grab the directory containing the files referenced in the data of the # file to be updated from the command line, if available; otherwise, use # the default (i.e. "./Output"). # if {[info exists argv] && [llength $argv] > 1} then { set directory [lindex $argv 1] } else { set directory [file join $path Output] } # # NOTE: Setup the regular expression pattern with the necessary captures. This # pattern is mostly non-greedy; however, at the end we need to match # exactly 40 hexadecimal characters. In theory, in Tcl, this could have # an undefined result due to the mixing of greedy and non-greedy # quantifiers; however, in practice, this seems to work properly. Also, # this pattern assumes a particular structure for the [HTML] file to be # updated. # set pattern {<a\ href=".*?/(.*?\.(?:exe|zip))">.*?\((\d+?\.\d+?) MiB\).*?sha1:\ ([0-9A-F]{40})} # # NOTE: Grab all the data from the file to be updated. # set data [readFile $updateFileName] # # NOTE: Process each match in the data and capture the file name, size, and # hash. # set count 0 foreach {dummy fileName fileSize fileHash} \ [regexp -all -inline -nocase -- $pattern $data] { # # NOTE: Get the fully qualified file name based on the configured directory. # set fullFileName [file join $directory $fileName] # # NOTE: If the file does not exist, issue a warning and skip it. # if {![file exists $fullFileName]} then { puts stdout "WARNING: File \"$fullFileName\" does not exist, skipped." continue } # # NOTE: Replace the captured size and hash with ones calculated from the # actual file name. This will only replace the first instance of # each (literal) match. Since we are processing the matches in the # exact order they appear in the data AND we are only replacing one # literal instance per match AND the size sub-pattern is nothing like # the hash sub-pattern, this should be 100% reliable. # incr count [regsub -nocase -- "***=$fileSize" $data [getFileSize \ $fullFileName] data] incr count [regsub -nocase -- "***=$fileHash" $data [getFileHash \ $fullFileName] data] } # # NOTE: Write the [modified] data to the file to be updated. # if {$count > 0} then { writeFile $updateFileName $data } else { puts stdout "WARNING: No changes, update of \"$updateFileName\" skipped." } |