Skip to content

Commit

Permalink
Updating sloshdsp.kit and setup.tcl to work with PUBLIC assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurTaylorNWS committed Apr 30, 2024
1 parent 32ab861 commit 5abf520
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
2 changes: 1 addition & 1 deletion distrib/windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ E:sloshdsp/sloshdsp.bat
# Bin
#E:sloshdsp/bin/gswin32c.exe
E:sloshdsp/bin/tclkit854.exe
E:sloshdsp/bin/curl.exe
# E:sloshdsp/bin/curl.exe
# E:sloshdsp/bin/tclkit854-linux32
E:sloshdsp/bin/sloshdsp.ico
#E:sloshdsp/bin/track.ico
Expand Down
41 changes: 10 additions & 31 deletions setup.tcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!./bin/tclkitsh854.exe
#-------------------------------------------------------------------------------
# setup.tcl Last Change: 2024-04-25
# setup.tcl Last Change: 2024-04-29
# [email protected]
# NWS/OSTI/MDL/DSD
#-------------------------------------------------------------------------------
Expand All @@ -9,38 +9,20 @@ proc Usage {} {
set base [file tail $argv0]
puts "Download and install assets (dd3.kit, shpfiles.tar.gz) from GitHub"
puts ""
puts "Usage: $base <cmd> <method>, where:"
puts "Usage: $base <cmd>, where:"
puts " <cmd> is:"
puts " help = Display this message and exit"
puts " all = Download basin, storm, and GUI data"
puts " <method> is:"
puts " manual = Use tarballs in ./tar"
puts " PAT(=<file>) = Use GitHub Personal Access Token (PAT) in <file>"
puts " if (=<file>) is omitted use ~/.gitHub_pat"
puts ""
puts "Example:"
puts " 1) ./$base all PAT"
puts " Use PAT (~/.gitHub_pat) to install all assests"
puts " 1) ./$base all"
puts " Install all assests"
}
if {($argc != 2) || ([lindex $argv 0] == "help")} { Usage ; exit 0 }
if {($argc != 1) || ([lindex $argv 0] == "help")} { Usage ; exit 0 }

set Cmd [lindex $argv 0]
if {$Cmd != "all"} { Usage ; exit 0 }

set Method [lindex $argv 1]
if {$Method == "manual"} { set TOKEN "manual"
} elseif {[string range $Method 0 2] == "PAT"} {
set PAT_FILE [string range $Method 4 end]
if {[string length $PAT_FILE] == 0} {
set PAT_FILE $env(HOME)/.gitHub_pat
}
set fp [open $PAT_FILE r]
gets $fp TOKEN
close $fp
} else {
Usage ; exit 0
}

#-------------------------------------------------------------------------------
# @brief One line JSON parser
#
Expand All @@ -64,7 +46,7 @@ proc json2dict JSONtext {
#-------------------------------------------------------------------------------
# @brief Download a file (asset) from GitHub
#
# @param Token: Private Access Token for private repositories
# @param curl: Program to use for 'Curl'
# @param url: URL for the GitHub repo releases
# @param Ver: Name of release that this is an asset of
# @param Name: Name of asset.
Expand All @@ -73,13 +55,12 @@ proc json2dict JSONtext {
# @author [email protected] (NWS/OSTI/MDL/DSD)
# @date Mar 2023: AAT - Created
#-------------------------------------------------------------------------------
proc getGitHubAsset {curl Token url Ver Name dstName} {
proc getGitHubAsset {curl url Ver Name dstName} {
# This call to curl could be done in Tcl via:
# geturl https://$url -binary true \
# -progress ::http::Progress -blocksize $chunk \
# -headers [list "Authorization" "token $Token" "Accept" "application/vnd.github.v3.raw"]
catch {exec $curl -s -L \
-H "Authorization: Bearer $Token" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://$url} ans
Expand All @@ -101,10 +82,9 @@ proc getGitHubAsset {curl Token url Ver Name dstName} {
file delete $Name
}
catch {exec $curl -s -L \
-H "Authorization: Bearer $Token" \
-H "Accept: application/octet-stream" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://$Token:@$url/assets/$ID > $dstName} ans
https://$url/assets/$ID > $dstName} ans
return 0
}

Expand All @@ -115,11 +95,10 @@ set UNZIP $srcDir/bin/unzip.exe
set BASE "api.github.com/repos"

puts "Getting dd3.kit"
getGitHubAsset $CURL $TOKEN $BASE/ArthurTaylorNWS/sdp/releases Assets \
dd3.kit dd3.kit
getGitHubAsset $CURL $BASE/NOAA-MDL/sdp/releases Assets dd3.kit dd3.kit

puts "Getting shpfiles.zip"
getGitHubAsset $CURL $TOKEN $BASE/ArthurTaylorNWS/sdp/releases Assets \
getGitHubAsset $CURL $BASE/NOAA-MDL/sdp/releases Assets \
shpfiles.zip shpfiles.zip

# Unpack the shpfiles.zip file
Expand Down
Binary file modified sloshdsp.kit
Binary file not shown.

0 comments on commit 5abf520

Please sign in to comment.