Skip to content

Commit 0b5eea0

Browse files
authored
Add files via upload
0 parents  commit 0b5eea0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+54329
-0
lines changed

BlackTools.tcl

Lines changed: 1848 additions & 0 deletions
Large diffs are not rendered by default.

BlackTools/Addons/github.tcl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env tclsh
2+
# file github/github.tcl
3+
#https://wiki.tcl-lang.org/page/github%3A%3Agithub
4+
#
5+
#Version 1.1 - added a timer in seconds between files & folders
6+
7+
# chicken and egg problem we need non-standard packages tls and json ...
8+
package require tls
9+
package require http
10+
::http::register https 443 ::tls::socket
11+
12+
namespace eval ::github {
13+
variable libdir [file normalize [file join [file dirname [info script]] ..]]
14+
if {[lsearch $::auto_path $libdir] == -1} {
15+
lappend auto_path $libdir
16+
}
17+
}
18+
19+
# I already placed the json folder below of the github folder
20+
package require json
21+
package provide github::github 0.2
22+
package provide github 0.2
23+
24+
# Tcl package download
25+
proc ::github::github {cmd owner repo folder} {
26+
variable libdir
27+
set url https://api.github.com/repos/$owner/$repo/contents/
28+
download $url $folder
29+
}
30+
31+
# Folder download
32+
proc ::github::download {url folder {debug true}} {
33+
if {![file exists $folder]} {
34+
file mkdir $folder
35+
}
36+
set sfiles ""
37+
set dfiles ""
38+
set data [http::data [http::geturl $url]]
39+
set d [json::json2dict $data]
40+
set l [llength $d]
41+
set files [list]
42+
for {set i 0} {$i < $l} {incr i 1} {
43+
set dic [dict create {*}[lindex $d $i]]
44+
set file [dict get $dic download_url]
45+
set type [dict get $dic type]
46+
if {$file eq "null" && $type eq "dir"} {
47+
set file [dict get $dic url]
48+
set file [regsub {.ref=master} $file ""]
49+
}
50+
if {$type eq "file"} {
51+
lappend sfiles $file
52+
} else {
53+
lappend dfiles $file
54+
}
55+
}
56+
if {$sfiles != ""} {
57+
files $sfiles $folder 0 $dfiles
58+
return
59+
}
60+
if {$dfiles != ""} {
61+
dirs $dfiles $folder 0
62+
}
63+
}
64+
65+
# Folders make
66+
proc ::github::dirs {dirs dir num} {
67+
set file [lindex $dirs $num]
68+
set nfolder [file join $dir [file tail $file]]
69+
download $file $nfolder
70+
set counter [expr $num + 1]
71+
if {[lindex $dirs $counter] != ""} {
72+
utimer 2 [list ::github::dirs $dirs $dir $counter]
73+
}
74+
}
75+
76+
# Files make
77+
proc ::github::files {files dir num dirs} {
78+
set item [lindex $files $num]
79+
set file [lindex $item 0]
80+
set fname [file tail $file]
81+
set fname [file join $dir $fname]
82+
set f [open $fname w]
83+
fconfigure $f -translation binary
84+
set tok [http::geturl $file -channel $f]
85+
set Stat [::http::status $tok]
86+
flush $f
87+
close $f
88+
http::cleanup $tok
89+
set counter [expr $num + 1]
90+
if {[lindex $files $counter] != ""} {
91+
utimer 2 [list ::github::files $files $dir $counter $dirs]
92+
} else {
93+
if {$dirs != ""} {
94+
dirs $dirs $dir 0
95+
}
96+
}
97+
}
98+

0 commit comments

Comments
 (0)