diff options
Diffstat (limited to 'modules/mga-mirrors/files')
-rwxr-xr-x | modules/mga-mirrors/files/check_mirrors_status | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/modules/mga-mirrors/files/check_mirrors_status b/modules/mga-mirrors/files/check_mirrors_status index 867ff3ec..0e23eeca 100755 --- a/modules/mga-mirrors/files/check_mirrors_status +++ b/modules/mga-mirrors/files/check_mirrors_status @@ -8,6 +8,11 @@ require 'uri' def get_dates(base, archs_per_distro, optional=true) r = {} + begin + r['base'] = get_timestamp(base) + rescue Net::OpenTimeout, Timeout::Error, ArgumentError, NoMethodError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError => e + end + archs_per_distro.each{|d, archs| r[d] = {} archs.each{|a| @@ -29,7 +34,9 @@ def get_mirrors mirrors = [] fetch_url("http://mirrors.mageia.org/").each_line{|l| next unless l =~ /http:.*>http/ - mirrors << l.sub(/<a href="(http[^"]*)".*\n/, '\1') + url = l.sub(/<a href="(http[^"]*)".*\n/, '\1') + url += "/" unless url =~ /\/$/ + mirrors << url } mirrors end @@ -64,19 +71,46 @@ def fetch_url(url, redirect_limit = 3) end end +def timestamp_url(url) + "#{url}mageia_timestamp" +end + +def get_timestamp(url) + DateTime.strptime(fetch_url(timestamp_url(url)).to_i.to_s, '%s') +end + def parse_version(version) date = version.sub(/.* (........ ..:..)$/, '\1').rstrip DateTime.strptime(date, '%Y%m%d %H:%M') end def version_url(url, distrib, arch) - "#{url}/distrib/#{distrib}/#{arch}/VERSION" + "#{url}distrib/#{distrib}/#{arch}/VERSION" end def get_date(url, distrib, arch) return parse_version(fetch_url(version_url(url, distrib, arch))) end +def format_age(ref_time, time) + return " <td class='broken'>X</td>" unless time + + diff = time - ref_time + cls = nil + if diff == 0 then + cls = 'ok' + elsif diff < 0.5 then + cls = 'almost' + elsif diff < 2 then + cls = 'bad' + end + if cls == 'ok' then + return " <td class='#{cls}'> </td>" + else + return " <td class='#{cls}'>#{time.strftime("%F %R")}</td>" + end +end + def print_output(archs_per_distro, mirrors, ref_times, times) puts "<html> <style> @@ -97,12 +131,13 @@ th {background-color:#EEEEEE;} puts "<table cellpadding='4px'><tr><td class='ok'>Up to date</td><td class='almost'>Less than 12h old</td><td class='bad'>Less than 2 days old</td><td class='broken'>Old or broken</td></tr></table>" puts "<table><thead>" puts "<tr><td/>" + puts "<td/><th>Base directory</th>" archs_per_distro.each{|d, archs| nb_arches = archs.size puts " <td/><th colspan='#{nb_arches}'>#{d}</th>" } puts "</tr>" - puts "<tr><td/>" + puts "<tr><td/><td/><td/>" archs_per_distro.each{|d, archs| puts " <td class='sep' />" archs.each{|a| @@ -112,6 +147,8 @@ th {background-color:#EEEEEE;} puts "</tr></thead>" puts "<tbody>" puts "<tr><td class='name'>Reference</td>" + puts " <td class='sep' />" + puts " <td>#{ref_times['base'].strftime("%F %R")}</td>" archs_per_distro.each{|d, archs| puts " <td class='sep' />" archs.each{|a| @@ -122,27 +159,12 @@ th {background-color:#EEEEEE;} mirrors.each{|u| puts "<tr><td class='name'><a href='#{u}'>#{u}</a></td>" + puts " <td class='sep' />" + puts format_age(ref_times['base'], times[u]['base']) archs_per_distro.each{|d, archs| puts " <td class='sep' />" archs.each{|a| - if times[u][d][a] != nil then - cls = 'broken' - diff = ref_times[d][a] - times[u][d][a] - if diff == 0 then - cls = 'ok' - elsif diff < 0.5 then - cls = 'almost' - elsif diff < 2 then - cls = 'bad' - end - if cls == 'ok' then - puts " <td class='#{cls}'> </td>" - else - puts " <td class='#{cls}'>#{times[u][d][a].strftime("%F %R")}</td>" - end - else - puts " <td class='broken'>X</td>" - end + puts format_age(ref_times[d][a], times[u][d][a]) } } puts "</tr>" |