PHP Koji Stats Page

Note: put this in a cron job as it may take a while to run. Use the output to generate a basic html page instead.

stats.php

<?php
	date_default_timezone_set("EST");
	$dta = date(DATE_RFC822);
	$dis = "dist-f15";
	$hua = "http://arm.koji.fedoraproject.org/kojihub";
	$hub = "http://koji.fedoraproject.org/kojihub";
	
	function p($n)
	{
		preg_match("/^(.*)-([^-]+)-([^-]+)$/", $n, $m);
		return $m;
	}
	
	$a = array();
	exec("/usr/bin/koji -s '".$hua."' list-tagged '".$dis."' --latest --quiet | /bin/awk '{ print $1 }'", $a);
	$b = array();
	exec("/usr/bin/koji -s '".$hub."' list-tagged '".$dis."' --latest --quiet | /bin/awk '{ print $1 }'", $b);
	
	$err = array(); $unb = array(); $dif = array(); $wor = array(); $fin = array();
	
	$t = array();
	foreach ($a as $i)
	{
		$n = p($i);
		array_push($t, $n[1]);
	}
	
	$u = array();
	foreach ($b as $i)
	{
		$n = p($i);
		$c = array_search($n[1], $t);
		if ($c === FALSE)
		{
			array_push($u, $i);
		}
		else if ($a[$c] != $i)
		{
			array_push($dif, array($a[$c], $i));
		}
		else if ($a[$c] == $i)
		{
			array_push($fin, $i);
		}
	}
	
	$c = 0; $s = ""; $l = count($u); $v = array();
	for ($x = 0; $x < $l; $x += 1)
	{
		$s = ($s."'".$u[$x]."' ");
		$c = ($c + 1);
		if (($c >= 256) or ($x == ($l - 1)))
		{
			exec("/usr/bin/koji -s '".$hua."' buildinfo ".$s." | /bin/grep -Ei '^(genericerror|no such build|build|state): .*$'", $v);
			$c = 0; $s = "";
		}
	}
	array_push($v, "");
	
	$b = ""; $s = "";
	foreach ($v as $i)
	{
		$m = array(); $n = array();
		if (preg_match("/^state: (.*)$/i", $i, $m))
		{
			$s = trim($m[1]);
		}
		else if (preg_match("/^.*: ([^ ]*).*$/i", $i, $n) or ($b != ""))
		{
			if ($b != "")
			{
				if ($s == "COMPLETE")
				{
					array_push($fin, $b);
				}
				else if ($s == "BUILDING")
				{
					array_push($wor, $b);
				}
				else if ($s == "")
				{
					array_push($unb, $b);
				}
				else
				{
					array_push($err, $b);
				}
			}
			$b = trim($n[1]); $s = "";
		}
	}
	
	$dtb = date(DATE_RFC822);
?>

<html>
	<head>
		<title>Koji Stats Page</title>
		<style>
			a
			{
				color: black;
				text-decoration: none;
			}
			table
			{
				width: 95%;
			}
			.errb
			{
				background-color: #FF6A6A;
			}
			.unbb
			{
				background-color: #FFA812;
			}
			.difb
			{
				background-color: #FFD700;
			}
			.work
			{
				background-color: #33FF33;
			}
			.buib
			{
				background-color: #499DF5;
			}
			.head
			{
				text-align: left;
				width: 95%;
				display: none;
			}
			.butt
			{
				border: 1px solid black;
				padding-left: 10px;
				padding-right: 10px;
			}
			.list
			{
				border: 1px dotted black;
				text-align: left;
				padding-top: 10px;
				padding-left: 10px;
				width: 95%;
				height: 512px;
				overflow: auto;
			}
		</style>
		<script>
			function show(name)
			{
				var x, objc;
				var elem = ["erro", "unbu", "diff", "work", "buil"];
				for (x = 0; x < elem.length; ++x)
				{
					objc = document.getElementById(elem[x]);
					objc.style.display = "none";
				}
				for (x = 0; x < elem.length; ++x)
				{
					if (name == elem[x])
					{
						objc = document.getElementById(elem[x]);
						objc.style.display = "block";
					}
				}
			}
			function init()
			{
				var objc = document.getElementById("head");
				objc.style.display = "block";
			}
		</script>
	</head>
	<body onload="init();">
		<b><?php print($dis." / ".$dta." / ".$dtb); ?></b>
		<br /><br />
		<center>
			<div id="head" class="head">
				<span class="butt errb"><a href="javascript:show('erro');">Errors [<?php echo count($err); ?>]</a></span>
				<span class="butt unbb"><a href="javascript:show('unbu');">Unbuilt [<?php echo count($unb); ?>]</a></span>
				<span class="butt difb"><a href="javascript:show('diff');">Different [<?php echo count($dif); ?>]</a></span>
				<span class="butt work"><a href="javascript:show('work');">Working [<?php echo count($wor); ?>]</a></span>
				<span class="butt buib"><a href="javascript:show('buil');">Built [<?php echo count($fin); ?>]</a></span>
			</div>
			<br />
			<div id="erro" class="list"><center><table>
				<?php foreach ($err as $i) { print("<tr><td class='butt errb'><a href=\"javascript:logs('".$i."');\">".$i."</a></td></tr>\n"); } ?>
			</table></center></div>
			<div id="unbu" class="list" style="display: none"><center><table>
				<?php foreach ($unb as $i) { print("<tr><td class='butt unbb'><a href=\"javascript:logs('".$i."');\">".$i."</a></td></tr>\n"); } ?>
			</table></center></div>
			<div id="diff" class="list" style="display: none"><center><table>
				<?php foreach ($dif as $i) { print("<tr><td class='butt difb'><a href=\"javascript:logs('".$i[0]."');\">".$i[0]." [".$i[1]."]</a></span></td></tr>\n"); } ?>
			</table></center></div>
			<div id="work" class="list" style="display: none"><center><table>
				<?php foreach ($wor as $i) { print("<tr><td class='butt work'><a href=\"javascript:logs('".$i."');\">".$i."</a></td></tr>\n"); } ?>
			</table></center></div>
			<div id="buil" class="list" style="display: none"><center><table>
				<?php foreach ($fin as $i) { print("<tr><td class='butt buib'><a href=\"javascript:logs('".$i."');\">".$i."</a></td></tr>\n"); } ?>
			</table></center></div>
		</center>
	</body>
</html>

Advertisements
PHP Koji Stats Page

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s