From b3b88ea646af31ee94d1589fd12ab086bc0fc7b6 Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Tue, 4 Sep 2012 09:02:09 +0000 Subject: Code reorg. - CSS move in style.css - configuration values move in conf.php - function definitions move in lib.php - a few code style fixes - test_index.php to test these changes before pushing to prod file --- conf.php | 34 +++++ lib.php | 136 +++++++++++++++++++ style.css | 36 +++++ test_index.php | 423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 629 insertions(+) create mode 100644 conf.php create mode 100644 lib.php create mode 100644 style.css create mode 100644 test_index.php diff --git a/conf.php b/conf.php new file mode 100644 index 0000000..71482fd --- /dev/null +++ b/conf.php @@ -0,0 +1,34 @@ + body > h1 title */ +$title = 'Mageia build system status'; + +/** Should crawlers index this page or not? meta[robots] tag.*/ +$robots = 'index,nofollow,nosnippet,noarchive'; + +/** */ +$g_root_url = 'http://pkgsubmit.mageia.org/'; \ No newline at end of file diff --git a/lib.php b/lib.php new file mode 100644 index 0000000..5feb424 --- /dev/null +++ b/lib.php @@ -0,0 +1,136 @@ + 'rejected', + 'upload' => 'uploaded', + 'failure' => 'failure', + 'done' => 'partial', + 'build' => 'building', + 'todo' => 'todo' + ); + + foreach ($labels as $k => $v) { + if (array_key_exists($k, $pkg['status'])) { + return $v; + } + } + + return 'unknown'; +} + +/** + * @param integer $num + * + * @return string +*/ +function plural($num) +{ + if ($num > 1) + return "s"; +} + +/** + * Return timestamp from package key + * + * @param string $key package submission key + * + * @return integer +*/ + +function key2timestamp($key) { + global $tz; + + $date = DateTime::createFromFormat("YmdHis", $key+0, $tz); + if ($date <= 0) + return null; + + return $date->getTimestamp(); +} + +/** + * Return human-readable time difference + * + * @param integer $start timestamp + * @param integer $end timestamp, defaults to now + * + * @return string +*/ +function timediff($start, $end) +{ + if (is_null($end)) { + $end = time(); + } + $diff = $end - $start; + if ($diff < 60) { + return $diff . " second" . plural($diff); + } + $diff = round($diff/60); + if ($diff < 60) { + return $diff . " minute" . plural($diff); + } + $diff = round($diff/60); + if ($diff < 24) { + return $diff . " hour" . plural($diff); + } + $diff = round($diff/24); + + return $diff . " day" . plural($diff); +} + + +/** + * Compare two duration strings + * + * @param string $a "1 hour" or "23 mins" + * @param string $b + * + * @return integer +*/ +function timesort($a, $b) +{ + $a = explode(' ', trim($a)); + $b = explode(' ', trim($b)); + + if ($a[1] == 'hour' || $a[1] == 'hours') { + $a[0] *= 3600; + } + + if ($b[1] == 'hour' || $a[1] == 'hours') { + $b[0] *= 3600; + } + + if ($a[0] > $b[0]) { + return 1; + } elseif ($a[0] < $b[0]) { + return -1; + } else { + return 0; + } +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..5074786 --- /dev/null +++ b/style.css @@ -0,0 +1,36 @@ +body, table { + font-family: Verdana, "Trebuchet MS", "Lucida Grande", "Lucida Sans", Tahoma, Arial, sans-serif; +} +body { font-size: 80%; } +.clear { clear: both; } +table { + border-spacing: 0; + border: 1px solid #ccc; + float: left; +} +table tr { padding: 0; margin: 0; } +table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; text-align: left; font-size: 85%; color: #999; } +table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; } + +tr { background: transparent; } +tr.uploaded { background: #bbffbb; } +tr.failure, tr.rejected { background: #ffbbbb; } +tr.todo { background: white; } +tr.building { background: #ffff99; } +tr.partial { background: #bbbbff; } +tr.built { background: #cceeff; } + +td.status-box { width: 1em; height: 1em; } +td.timeinfo { font-size: 85%; } +td.percent { text-align: right; } +tr.uploaded td.status-box { background: green; } +tr.failure td.status-box, tr.rejected td.status-box { background: red; } +tr.todo td.status-box { background: white; } +tr.building td.status-box { background: yellow; } +tr.partial td.status-box { background: blue; } +tr.built td.status-box { background: #00ccff; } + +#stats { float: right; } +#score { margin-bottom: 2em; font-family: Helvetica, Verdana, Arial, sans-serif; } +#score-box { width: 100px; height: 100px; background: #faa; } +#score-meter { width: 100px; background: #afa; } \ No newline at end of file diff --git a/test_index.php b/test_index.php new file mode 100644 index 0000000..38daf75 --- /dev/null +++ b/test_index.php @@ -0,0 +1,423 @@ + array(), + 'path' => $val[2], + 'version' => $val[3], + 'media' => $val[4], + 'section' => $val[5], + 'user' => $val[7], + 'host' => $val[8], + 'job' => $val[9] + ); + } + $status = $val[1]; + $data = $val[10]; + if (preg_match("/@(\d+):/", $data, $revision)) { + $pkgs[$key]['revision'] = $revision[1]; + } + + $pkgs[$key]['status'][$status] = 1; + $ext = $val[11]; + + if ($ext == '.src.rpm.info') { + preg_match("!^(?:@\d+:)?(.*)!", $data, $name); + $pkgs[$key]['package'] = $name[1]; + } else if ($ext == '.src.rpm') { + $pkgs[$key]['status']['src'] = 1; + } else if ($ext == '.upload') { + $pkgs[$key]['status']['upload'] = 1; + } else if ($ext == '.lock') { + preg_match("!(.*)\.iurt\.(.*)\.\d+\.\d+!", $data, $buildhost); + if (!$hosts[$buildhost[2]]) { + $hosts[$buildhost[2]]= array(); + } + $hosts[$buildhost[2]][$buildhost[1]] = $key; + if ($pkgs[$key]['status']['build']) { + array_push($pkgs[$key]['status']['build'], $buildhost[2]); + } else { + $pkgs[$key]['status']['build'] = array($buildhost[2]); + } + } else if ($ext == '.done') { + // beware! this block is called twice for a given $key + + $pkgs[$key]['buildtime']['start'] = key2timestamp($val[6]); + $pkgs[$key]['buildtime']['end'] = round($val[12]); + $pkgs[$key]['buildtime']['diff'] = $pkgs[$key]['buildtime']['end'] - $pkgs[$key]['buildtime']['start']; + + @$build_dates[date('H', $pkgs[$key]['buildtime']['start'])] += 1; + + // keep obviously dubious values out of there + // 12 hours is be an acceptable threshold given current BS global perfs + // as of April 2011 + if ($pkgs[$key]['buildtime']['diff'] < 43200) { + $buildtime_total[$key] = $pkgs[$key]['buildtime']['diff']; + } + } +} + +// filter packages if a package name was provided +if ($_GET['package']) { + foreach ($pkgs as $key => $pkg) { + preg_match("/^(.*)-[^-]*-[^-]*$/", $pkg['package'], $name); + if ($_GET['package'] != $name[1]) { + unset($pkgs[$key]); + } + } +} + +// sort by key in reverse order to have more recent pkgs first +krsort($pkgs); +ksort($build_dates); + +$build_count = count($buildtime_total); +$buildtime_total = array_sum($buildtime_total); + +// count all packages statuses +$stats = array( + 'uploaded' => 0, + 'failure' => 0, + 'todo' => 0, + 'building' => 0, + 'partial' => 0 +); +$total = count($pkgs); + +// count users' packages +$users = array(); + +if ($total > 0) { + foreach ($pkgs as $key => $p) { + $pkgs[$key]['type'] = pkg_gettype($p); + + $stats[$pkgs[$key]['type']] += 1; + + if (!array_key_exists($p['user'], $users)) { + $users[$p['user']] = 1; + } else { + $users[$p['user']] += 1; + } + } +} + +// check if emi is running +$stat = stat("/var/lib/schedbot/tmp/upload"); +if ($stat) { + $upload_time = $stat['mtime']; +} + +// publish stats as headers + +foreach ($stats as $k => $v) { + Header("X-BS-Queue-$k: $v"); +} + +$w = $stats['todo'] - 10; +if($w < 0) { + $w = 0; +} +$w = $w * 60; +Header("X-BS-Throttle: $w"); + +if ($_GET['last'] && $total > 0) { + reset($pkgs); + $last = current($pkgs); + Header("X-BS-Package-Status: ".$last['type']); +} + +$buildtime_total = $buildtime_total / 60; +header(sprintf('X-BS-Buildtime: %d', round($buildtime_total))); +$buildtime_avg = round($buildtime_total / $build_count, 2); +header(sprintf('X-BS-Buildtime-Average: %5.2f', $buildtime_avg)); +?> + + + + + <?php echo strip_tags($title); ?> + + + + + + +

+ +« Back to full list'; +} + +if (!$_GET['package']) { + $missing_deps_count = preg_match_all("//m", file_get_contents("http://check.mageia.org/cauldron/dependencies.rss"), $matches); + $unmaintained_count = count(file(__DIR__ . '/data/unmaintained.txt')); + if ($missing_deps_count > 0 || $unmaintained_count > 0) { + echo "

"; + if ($missing_deps_count > 0) { + echo "$missing_deps_count broken dependencies. "; + } + + if ($unmaintained_count > 0) { + echo "$unmaintained_count unmaintained packages. "; + } + echo 'You can help!

'; +} + +preg_match_all('/(\d+)/', file_get_contents("https://bugs.mageia.org/buglist.cgi?quicksearch=%40qa-bugs+-kw%3Avali"), $matches); +$qa_bugs = $matches[1][0]; +if ($qa_bugs > 0) { + echo "

"; + echo "$qa_bugs package updates to validate. "; + echo 'You can help!

'; +} + +if ($upload_time) { + echo sprintf('

Upload in progress for %s.

', timediff($upload_time)); +} + +$buildtime_stats = array(); + +// Builds in progress +$s = ''; +$tmpl = << + %s + %s + %s + %s + %s + %s/%s + +TB; +foreach ($hosts as $machine => $b) { + foreach ($b as $arch => $key) { + $s .= sprintf($tmpl, + $machine, + $arch, + $pkgs[$key]['user'], $pkgs[$key]['user'], + $pkgs[$key]['package'], + $pkgs[$key]['version'], + $pkgs[$key]['media'], $pkgs[$key]['section']); + } +} +echo '
', + sprintf('', count($hosts), plural(count($hosts))), + '', + $s, + '
%d build%c in progress.
MachineArchUserPackageTargetMedia
'; +echo '
'; + +} + +// Build queue +$s = ''; +$tmpl = << + %s + %s + %s + %s + %s/%s + +T; + +if ($total > 0) { + foreach ($pkgs as $key => $p) { + $s .= sprintf($tmpl, + $p['type'], + timediff(key2timestamp($key)) . ' ago', + $p['user'], $p['user'], + $p['revision'], + addslashes($p['summary']), + $p['package'], + $p['version'], + $p['media'], $p['section'] + ); + + $typelink = ''; + if ($p['type'] == 'failure') { + $typelink = '/uploads/' . $p['type'] . '/' . $p['path']; + } elseif ($p['type'] == 'rejected') { + $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri'; + } else { + $typelink = '/uploads/done/' . $p['path']; + if (!is_dir("..$typelink")) { + $typelink = ''; + } + } + $typestr = $p['type']; + if ($p['status']['build']) { + $typealt = 'Building on'; + foreach ($p['status']['build'] as $h) { + $typealt .= " $h"; + } + $typestr = "$typestr"; + } + + $s .= ''; + $s .= ($typelink != '') ? + sprintf('%s', $typelink, $typestr) : + $typestr; + + $s .= ''; + if ($p['type'] == 'uploaded') { + $tdiff = timediff($p['buildtime']['start'], $p['buildtime']['end']); // use $p['buildtime']['diff']; instead? + $s .= $tdiff; + $tdiff = floor(($p['buildtime']['end'] - $p['buildtime']['start']) / 60)*60; + + @$buildtime_stats[timediff(0, $tdiff)] += 1; + } + $s .= ''; + $s .= ''; + } + // Table + echo '', + '', + ' + + ', + $s, + '
', $total, ' packages submitted in the past ', $max_modified * 24, ' hours.
SubmittedUserPackageTargetMediaStatusBuild time
'; + + // Stats + $s = '
'; + $score = round($stats['uploaded']/$total * 100); + $s .= sprintf('

Score: %d/100

+
', + $score, $score); + + $s .= ''; + foreach ($stats as $k => $v) { + $s .= sprintf('', + $k, $k, $v, round($v/$total*100)); + } + + $s .= '
Stats.
StatusCount%
%s%d%d%%


'; + + $s .= ''; + arsort($users); + foreach ($users as $k => $v) { + $s .= sprintf('', + $k, $k, $v); + } + + $s .= '
Packagers
UserPackages
%s%d


'; + + uksort($buildtime_stats, "timesort"); + + $bts = ''; + $max = max($buildtime_stats); + foreach ($buildtime_stats as $time => $count) { + $bts .= sprintf('%s', + $time == "0 second" ? "< 1 minute" : $time, + round($count/$max*100), + $count); + + $tmp = explode(' ', $time); + } + + $s .= ''; + + $s .= sprintf(' + + ', + round($buildtime_total / 60, 2), + $buildtime_avg, + $buildtime_cnt); + + $s .= ''; + $s .= $bts; + $s .= '
Build time
Total time%s hours
Average%s minutes
Builds count%s
DurationPack. nb.
Does not take
build failures
into account.
'; + + $s .= ''; + $max = max($build_dates); + foreach ($build_dates as $time => $count) + $s .= sprintf('', + $time, + round($count / $max * 100), + $count); + $s .= '
Build times
%d
'; + $s .= '
'; + + echo $s; +} +else +{ + echo sprintf('

No package has been submitted in the past %d hours.

', + $max_modified * 24); +} + +?> +
+
+

Generated at . + Code for this page is in http://svnweb.mageia.org/soft/build_system/web/.

+ + -- cgit v1.2.1