SVN: toys/stbr: index.php queue.php

vip vip at pld-linux.org
Tue May 15 20:05:57 CEST 2007


Author: vip
Date: Tue May 15 20:05:54 2007
New Revision: 8548

Added:
   toys/stbr/queue.php
Modified:
   toys/stbr/index.php
Log:
- show status from builder queue


Modified: toys/stbr/index.php
==============================================================================
--- toys/stbr/index.php	(original)
+++ toys/stbr/index.php	Tue May 15 20:05:54 2007
@@ -1,6 +1,11 @@
 <?
 ob_start("ob_gzhandler");
-$db = sqlite_open("../ApHeX/scripts/stbrlog.db")
+$db = sqlite_open("../ApHeX/scripts/stbrlog.db");
+
+include("queue.php");
+
+$queue = new Queue();
+
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
@@ -62,6 +67,7 @@
 <td width="150px">spec</td>
 <td width="200px">recipient</td>
 <td width="150px">builder</td>
+<td width="150px">queue status</td>
 </tr>
 </thead>
 </table>
@@ -82,17 +88,46 @@
 <!-- inner evil -->
 <table>
 <?
-$inner = "SELECT * FROM application WHERE date='{$p['date']}' ORDER BY date DESC";
+$inner  = "SELECT application.recipient as arecipient, application.spec as aspec,  ";
+$inner .= " builder, queue_requester, queue_date ";
+$inner .= "FROM application ";
+$inner .= "LEFT JOIN status ";
+$inner .= "WHERE application.date='{$p['date']}' ";
+$inner .= "ORDER BY application.date DESC";
+
 $inner = sqlite_query($db, $inner);
 
 while($q = sqlite_fetch_array($inner))
 {
-$q['recipient'] = strrev($q['recipient']);
+	if(empty($q['queue_requester']) && empty($q['queue_date']))
+	{
+		$filled = $queue->is_filled(array('spec' => $q['aspec'], 'date' => $p['date']));
+		if(count($filled))
+		{
+			$filled['date'] = date("d.m.Y H:i:s", $filled['date']);
+			$insert = "INSERT INTO status VALUES (";
+			$insert .= "'{$p['date']}','{$q['aspec']}', '{$filled['requester']}','{$filled['date']}'";
+			$insert .= ");";
+			sqlite_exec($db, $insert);
+			$filled = $filled['requester'] . '/' . $filled['date'];
+		}
+		else
+		{
+		        $filled = "not in";
+		}
+	}
+	else
+	{
+		$filled = $q['queue_requester'] . '/' .$q['queue_date'];
+	}
+
+	$q['arecipient'] = strrev($q['arecipient']);
 ?>
 <tr>
-<td width="150px"><a href="http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/<?=$q['spec']?>"><?=$q['spec']?></a></td>
-<td width="200px"><script>vm("<?=$q['recipient']?>");</script></td>
+<td width="150px"><a href="http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/<?=$q['aspec']?>"><?=$q['aspec']?></a></td>
+<td width="200px"><script>vm("<?=$q['arecipient']?>");</script></td>
 <td width="150px"><?=$q['builder']?></td>
+<td><?=$filled?></td>
 </tr>
 <?
 }

Added: toys/stbr/queue.php
==============================================================================
--- (empty file)
+++ toys/stbr/queue.php	Tue May 15 20:05:54 2007
@@ -0,0 +1,89 @@
+<?
+class Queue
+{
+	var $xmlqueuepath = "queue.gz";
+	//$xmlqueuepath = "http://ep09.pld-linux.org/~builderth/queue.gz";
+	var $queue = '';
+
+	function array_preg_search($data, $search)
+	{
+		foreach($data as $key => $value)
+		{
+			if(trim($value) == $search)
+			{
+				return $key;
+			}
+		}
+		return false;
+	}
+
+	function gzfile_get_contents($file)
+	{	
+		$data = '';
+		$data = gzfile($file);
+	
+		$pgp_start = $this->array_preg_search($data, "<queue>");
+		$pgp_length = $this->array_preg_search($data, "</queue>") - $pgp_start + 1;
+	
+		$data = array_slice($data, $pgp_start, $pgp_length);
+		$data = implode($data);
+		
+		return $data; 
+	} 
+	
+	function convert_to_timestamp(&$element, $key)
+	{
+		$element['date'] = strtotime($element['date']);
+	}
+	
+	function queue_search_recursive($spec)
+	{
+		$result = array();
+	
+		foreach($this->queue as $group)
+		{
+			$this->queue_requster = (string)$group->requester;
+			$this->queue_date = (int)$group->time;
+			$this->queue_spec = (string)$group->batch->spec;
+		
+			if($spec['spec'] != $this->queue_spec)
+				continue;
+	
+			//echo date("Y-m-d H:i:s", $this->queue_date) . "\n";
+			
+			if($spec['date'] < $this->queue_date)
+				$result = array('date' => $this->queue_date, 'requester' => $this->queue_requster);
+		}
+	
+		return $result;
+	}
+	
+	function prepare_queue_data()
+	{
+		if(empty($this->queue))
+		{
+			$this->queue = $this->gzfile_get_contents($this->xmlqueuepath);
+			$this->queue = simplexml_load_string($this->queue);
+		}
+	}
+	
+	
+	//array_walk($specs, 'convert_to_timestamp');
+	
+	function is_filled($spec)
+	{
+		$status = array();
+
+		$this->prepare_queue_data();
+
+		$spec['date'] = strtotime($spec['date']);
+		
+//		echo "Searching " . $spec['spec'] . " (>" . $spec['date'] . ") in queue...\n";
+	
+		$status = $this->queue_search_recursive($spec);
+		
+		//echo "Found filled req: " . $spec['spec'] . " (". $spec['date'] .") with queue entry: " . $status['requester'] . " (" . $status['date'] . ")\n";
+		return $status;
+	}
+}	
+?>


More information about the pld-cvs-commit mailing list