Basic Stats Page Outside Of Koji

So since we’re building Fedora ARM packages outside of Koji first (on F13 builders and then again on F15 builders), I decided to create a simple stats page so our team could track its status.

<?php
	function fileread($filename)
	{
		$outpstri = "";
		$fileobjc = fopen($filename, "r");
		$outpstri .= fread($fileobjc, filesize($filename));
		fclose($fileobjc);
		$outpstri .= "\n";
		return $outpstri;
	}
	$foldname = "./done";
	if (isset($_GET["pkgn"]))
	{
		$outpstri = "";
		$outpstri .= fileread($foldname."/mock.".$_GET["pkgn"]."/build.log");
		$outpstri .= fileread($foldname."/mock.".$_GET["pkgn"]."/root.log");
		$outpstri .= fileread($foldname."/mock.".$_GET["pkgn"]."/state.log");
		$outpstri = preg_replace("/&/", "&amp;", $outpstri);
		$outpstri = preg_replace("/</", "&lt;", $outpstri);
		$outpstri = preg_replace("/>/", "&gt;", $outpstri);
		$outpstri = str_replace("\n", " <br /> \n ", $outpstri);
		print($outpstri."\n");
		die;
	}
	exec("find ".$foldname." -type f", $outplist);
	$donestri = ""; $donelist = array();
	$errostri = ""; $errolist = array();
	$totllist = array();
	foreach ($outplist as $outpitem)
	{
		$safefold = preg_replace("/([\/.])/", "\\\\$1", $foldname);
		if (!preg_match("/^".$safefold."\/mock\.([^\/]+)\/.*$/", $outpitem))
		{
			continue;
		}
		$pkgsname = preg_replace("/^".$safefold."\/mock\.([^\/]+)\/.*$/", "$1", $outpitem);
		if (preg_match("/^.*\.src\.rpm$/", $outpitem))
		{
			if (!in_array($pkgsname, $donelist))
			{
				array_push($donelist, $pkgsname);
			}
		}
		if (!in_array($pkgsname, $totllist))
		{
			array_push($totllist, $pkgsname);
		}
	}
	foreach ($totllist as $totlitem)
	{
		if (!in_array($totlitem, $donelist))
		{
			array_push($errolist, $totlitem);
		}
	}
	sort($donelist);
	sort($errolist);
	$donenumb = count($donelist);
	$erronumb = count($errolist);
	$donestri .= ("<script>parent.document.title += ' [ ".$donenumb.".d ] ';</script>");
	$donestri .= ("<b>Built: [ ".$donenumb." ]</b> <br /> <br /> \n");
	foreach ($donelist as $doneitem)
	{
		$donestri .= ($doneitem." <br /> \n ");
	}
	$errostri .= ("<script>parent.document.title += ' [ ".$erronumb.".e ] ';</script>");
	$errostri .= ("<b>Error: [ ".$erronumb." ]</b> <br /> <br /> \n");
	foreach ($errolist as $erroitem)
	{
		$errostri .= ("<a href=\"javascript:function a() { parent.document.getElementById('logswind').src = ('".$_SERVER["PHP_SELF"]."?pkgn=".$erroitem."'); } a();\">".$erroitem."</a> <br /> \n ");
	}
	if (isset($_GET["done"]))
	{
		print($donestri);
		die;
	}
	if (isset($_GET["erro"]))
	{
		print($errostri);
		die;
	}
?>
<html>
	<head>
		<title>loading...</title>
		<style>
			table
			{
				width: 95%;
			}
			iframe
			{
				border: 1px dotted black;
				width: 100%;
			}
			#errowind
			{
				height: 160px;
			}
			#logswind
			{
				height: 240px;
			}
			#donewind
			{
				height: 160px;
			}
		</style>
		<script>
			function pkgslist()
			{
				document.title = "";
				document.getElementById("errowind").src = ('<?php echo $_SERVER["PHP_SELF"]; ?>?erro=true');
				document.getElementById("donewind").src = ('<?php echo $_SERVER["PHP_SELF"]; ?>?done=true');
			}
			function pageinit()
			{
				setInterval("pkgslist();", 30 * 1000);
			}
		</script>
	</head>
	<body onload="pkgslist(); pageinit();">
		<b>Date: [ <?php echo date("y-m-d H:i:s"); ?> ]</b>
		<br /> <br />
		<center>
		<table>
			<tr>
				<td><iframe id="errowind"></iframe></td>
			</tr>
			<tr>
				<td> &nbsp; </td>
			</tr>
			<tr>
				<td><b>Logs:</b></td>
			</tr>
			<tr>
				<td><iframe id="logswind"></iframe></td>
			</tr>
			<tr>
				<td> &nbsp; </td>
			</tr>
			<tr>
				<td><iframe id="donewind"></iframe></td>
			</tr>
		</table>
		</center>
	</body>
</html>

Advertisements
Basic Stats Page Outside Of Koji

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