This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_allpages.tcl
83 lines (75 loc) · 2.38 KB
/
test_allpages.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
#!/usr/bin/tclsh
package require uri
package require http
package require tdom
package require sqlite3
set ::http::defaultCharset utf-8
set fastcheck [expr {[lindex $argv 0] eq "--fast"}]
if {$fastcheck} {
puts "fast check enabled"
}
set hostname {[::1]}
set port 18082
set servhost "$hostname:18082"
set masterfifo "/tmp/uwsgiservtest.fifo"
set pserver [exec > /dev/null 2> /dev/null uwsgi_python37 --http-socket $servhost --master-fifo $masterfifo --wsgi-file main.py &]
puts "started server $pserver"
set urlhost http://$servhost
set urlmatch [regsub -all {([\[\]])} $urlhost {\\\1}]
append urlmatch /*
sqlite3 db {:memory:}
db eval {CREATE TABLE links(url TEXT PRIMARY KEY, ref TEXT, status INTEGER)}
db eval {INSERT INTO links VALUES ('/', null, null)}
after 1000
set testpath /
while {$testpath ne ""} {
set row [db eval {
SELECT url, ref FROM links
WHERE status IS null ORDER BY random() LIMIT 1
}]
set testpath [lindex $row 0]
if {$fastcheck && [regexp "^/(packages|changelog|revdep|qa)/" $testpath]} {
db eval {UPDATE links SET status=-1 WHERE url=$testpath}
continue
}
set testref [lindex $row 1]
set token [::http::geturl $urlhost$testpath -timeout 5000]
set ncode [::http::ncode $token]
db eval {UPDATE links SET status=$ncode WHERE url=$testpath}
upvar #0 $token state
if {$ncode >= 400} {
puts "$ncode $testpath ref $testref"
::http::cleanup $token
continue
}
if {! [string match text/html* $state(type)]} {
::http::cleanup $token
continue
}
set data [::http::data $token]
set doc [dom parse -html $data]
foreach tag [domDoc $doc getElementsByTagName a] {
set href [domNode $tag getAttribute href {}]
set href [::uri::resolve $urlhost$testpath $href]
if {[string match $urlmatch $href]} {
set href [string range $href [string length $urlhost] end]
db eval {INSERT OR IGNORE INTO links VALUES ($href, $testpath, null)}
}
}
$doc delete
::http::cleanup $token
}
puts "=== Summary ==="
db eval {
SELECT status, count(url) cnt FROM links GROUP BY status ORDER BY status
} values {
if {$values(status) == -1} {
puts "ignored: $values(cnt) pages"
} else {
puts "$values(status): $values(cnt) pages"
}
}
set mf [open $masterfifo w]
puts $mf Q
after 1000
file delete $masterfifo