| 304 | # sorts fetch_urls in order of ping time |
| 305 | proc sortsites {args} { |
| 306 | global fetch_urls |
| 307 | set svnserver "svn.macports.org" |
| 308 | |
| 309 | foreach {url_var distfile} $fetch_urls { |
| 310 | global portfetch::$url_var |
| 311 | if {![info exists $url_var]} { |
| 312 | ui_error [format [msgcat::mc "No defined site for tag: %s, using master_sites"] $url_var] |
| 313 | set url_var master_sites |
| 314 | global portfetch::$url_var |
| 315 | } |
| 316 | set urllist [set $url_var] |
| 317 | set pinglist {} |
| 318 | |
| 319 | foreach site $urllist { |
| 320 | regexp {[a-zA-Z]+://([a-zA-Z0-9\.-]+)[(/?$)|(/.*)]} $site -> host |
| 321 | if { [string compare $host $svnserver] } { |
| 322 | if {[catch {exec ping -noq -c1 -t1 $host | grep round-trip | cut -d / -f 5} msecs]} { |
| 323 | set msecs 10000; # ping failed, so put it last in the list |
| 324 | } |
| 325 | } else { |
| 326 | set msecs 20000; # always try macports svn last |
| 327 | } |
| 328 | lappend pinglist [ list $site $msecs ] |
| 329 | } |
| 330 | |
| 331 | set pinglist [ lsort -real -index 1 $pinglist ] |
| 332 | |
| 333 | set $url_var {} |
| 334 | foreach pair $pinglist { |
| 335 | lappend $url_var [lindex $pair 0] |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |