r1704 - in tools: . webtools webtools/timeline
Author: sip Date: 2006-08-10 17:00:23 +0200 (Thu, 10 Aug 2006) New Revision: 1704 Added: tools/webtools/ tools/webtools/timeline/ tools/webtools/timeline/timeline.php tools/webtools/timeline/timeline.sql tools/webtools/timeline/tlcacher.php Log: Imported webtools section with timeline scripts Added: tools/webtools/timeline/timeline.php =================================================================== --- tools/webtools/timeline/timeline.php (rev 0) +++ tools/webtools/timeline/timeline.php 2006-08-10 15:00:23 UTC (rev 1704) @@ -0,0 +1,44 @@ +<?php +require_once('DB.php'); +Markup("timeline", "directives", "/\\(:timeline(\\s+.*)?\\s*:\\)/e", + "'<:block>'.GetEvents()"); + + +function GetEvents() { + +$days = 30; +if (isset($_POST['days'])) { + $days = intval($_POST['days']); +} + +$dsn = 'sqlite:////home/crux/public_html/local/timeline.db'; +$db =& DB::connect($dsn); +if (DB::isError($db)) die("Cannot connect to database"); +$db->setFetchMode(DB_FETCHMODE_ASSOC); +$from = time() - ($days * 24 * 60 * 60); +$sql = "select * from events where event_tstamp >= $from order by event_tstamp desc"; +$res =& $db->Query($sql); +if (DB::isError($res)) die("Query error"); + + +$timeline .= '<table cellspacing="0" border="0" cellpadding="0">'."\n"; +$currdate = "noway"; +while ($evt =& $res->fetchRow()) { + if ($evt['event_date'] != $currdate) { + $timeline .= '<tr><td class="timeline-head" colspan="3"><span class="timeline-date">'.$evt['event_date']."</span></td></tr>\n"; + } + $event_description = $evt['event_description']; + if ($evt['event_notes'] != "") { + $event_description .= ": ".$evt['event_notes']; + } + $img = '<img src="/images/'.$evt['event_type'].'.png">'; + $timeline .= '<tr><td align="right" valign="top" width="60">'.$evt['event_time'].'</td><td align="center" valign="top" width="30">'.$img.'</td><td valign="top">'.$event_description.'</td></tr>'; + $timeline .= "\n"; + $currdate = $evt['event_date']; +} +$timeline .= "</table>\n"; +$timeline .= '<br><form method="post" action="pmwiki.php?n=Main.Test">Show the latest <input size="4" type="text" name="days" value="'.$days.'"> days <input type="submit" value="Show"></form>'."\n"; +return $timeline; + +} +?> Added: tools/webtools/timeline/timeline.sql =================================================================== --- tools/webtools/timeline/timeline.sql (rev 0) +++ tools/webtools/timeline/timeline.sql 2006-08-10 15:00:23 UTC (rev 1704) @@ -0,0 +1,11 @@ +create table events ( + event_id integer primary key, + cache_id integer, + event_tstamp integer, + event_type varchar(20), + event_date varchar(10), + event_time varchar(5), + event_user varchar(50), + event_description text, + event_notes text +); Added: tools/webtools/timeline/tlcacher.php =================================================================== --- tools/webtools/timeline/tlcacher.php (rev 0) +++ tools/webtools/timeline/tlcacher.php 2006-08-10 15:00:23 UTC (rev 1704) @@ -0,0 +1,215 @@ +#!/usr/bin/php +<?php + +/* Caches the timeline events into a sqlite db */ + +require_once('DB.php'); + +/**************** Configuration ***********************/ + +// PEAR dns for the flyspray db and sqlite cache db, +// ie +// $dsn = 'mysql://username:password@host/dbname'; +// $dsnc = 'sqlite:////path/to/database.db'; +require_once("tlcacher_config.php"); + +// Url of the detailed task +$task_url="https://crux.nu/bugs/?do=details&id=%s"; +// Path of the subversion repository +$repo_path = "/home/crux/repo"; + +// Subversion commands +$svn_cmd = "/usr/bin/svn --non-interactive --config-dir /"; +$svnlook_cmd = "/usr/bin/svnlook"; + +// Url of the online repo viewer +$svn_url = "http://crux.nu/svnweb/CRUX/revision/?rev=%s"; + +// Path of the recent changes pmwiki file +$wiki_file = "/home/crux/public_html/wiki.d/Site.AllRecentChanges"; + +// Map svn users to wiki profiles +$username_map = array( + "jaeger" => "jaeger", + "jue" => "JuergenDaubert", + "jw" => "JohannesWinkelmann", + "sip" => "SimoneRota" , + "jdolan" => "JasonThomasDolan", + "jheino" => "JukkaHeino", + "tilman" => "TilmanSauerbeck", + "viper" => "SimonGlo�ner", + "sten" => "NickSteeves" +); + +// Event: cache_id, tstamp, type(icon), date, time, user, description, notes +$events = array(); + +/**************** Last cached events *******************/ + +$dbc =& DB::connect($dsnc); +if (DB::isError($dbc)) die("Cannot connect to S database"); +$dbc->setFetchMode(DB_FETCHMODE_ASSOC); +$last_cached_sql = "select cache_id from events where event_type='svn_commit' order by cache_id desc"; +$res =& $dbc->limitQuery($last_cached_sql,0,1); +if (DB::isError($res)) die("Query error"); +if ($res->numRows() === 0) { + $last_svn = 0; +} else { + $row =& $res->fetchRow(); + $last_svn = $row['cache_id']; +} +$last_cached_sql = "select cache_id from events where event_type like 'task%' order by cache_id desc"; +$res =& $dbc->limitQuery($last_cached_sql,0,1); +if (DB::isError($res)) die("Query error"); +if ($res->numRows() === 0) { + $last_task = 0; +} else { + $row =& $res->fetchRow(); + $last_task = $row['cache_id']; +} +$last_cached_sql = "select cache_id from events where event_type = 'wiki_changed' order by cache_id desc"; +$res =& $dbc->limitQuery($last_cached_sql,0,1); +if (DB::isError($res)) die("Query error"); +if ($res->numRows() === 0) { + $last_wiki = 0; +} else { + $row =& $res->fetchRow(); + $last_wiki = $row['cache_id']; +} +/**************** Flyspray events ***********************/ + +$db =& DB::connect($dsn); +if (DB::isError($db)) die("Cannot connect to M database"); +$db->setFetchMode(DB_FETCHMODE_ASSOC); + +$sql = "select history_id, event_date, event_type, user_name, flyspray_history.task_id, item_summary, closure_comment + from flyspray_history + join flyspray_users on flyspray_users.user_id = flyspray_history.user_id + join flyspray_tasks on flyspray_tasks.task_id = flyspray_history.task_id + where history_id > $last_task"; + +$res =& $db->Query($sql); +if (DB::isError($res)) die("Query error"); + +while ($row =& $res->fetchRow()) { + // $etype = $fs_events[$row['event_type']]; + $etype = $row['event_type']; + $euser = $row['user_name']; + $etid = $row['task_id']; + $edate = $row['event_date']; + $cache_id = $row['history_id']; + $description = ""; + $date = date("Y-m-d", $edate); + $time = date("H:i", $edate); + switch ($etype) { + case "1": // new task + $icon = "task_opened"; + $description = "New task [[ ".sprintf($task_url,$etid)." | $etid ]] opened by $euser"; + $notes = $row['item_summary']; + break; + case "2": // task closed + $icon = "task_closed"; + $description = "Task [[ ".sprintf($task_url,$etid)." | $etid ]] closed by $euser"; + if ($row['closure_comment'] != "" && $row['closure_comment'] != 0) { // weird flyspray! + $notes = $row['closure_comment']; + } else { + $notes = ""; + } + break; + case "3": // task edited : fields, comments, attachments, ownership, related tasks, etc. + case "4": + case "5": + case "6": + case "7": + case "8": + case "14": + case "15": + case "16": + case "22": + case "23": + case "24": + case "25": + $icon = "task_changed"; + $description = "Task [[ ".sprintf($task_url,$etid)." | $etid ]] modified by $euser"; + $notes = ""; + break; + } + if ($description !== "") { + $events[] = array( 'cache_id' => $cache_id, 'tstamp' => $edate, 'icon' => $icon, 'date' => $date, + 'time' => $time, 'user' => $euser, 'description' => $description, 'notes' => $notes,); + } +} + + +/**************** Subversion events ********************/ +$out = array(); +$res = 0; +exec("$svnlook_cmd youngest $repo_path", $out, $res); +$svn_latest = trim($out[0]); +if ($svn_latest != $last_svn) { + exec("$svn_cmd log file://$repo_path -r$last_svn:HEAD", $out, $res); + foreach ($out as $line) { + if ($line != "" && substr($line, 0, 5) != "-----") { + $revline = split("\|", $line); + if (count($revline) == 4) { + $rev = substr(trim($revline[0]),1); + $user = trim($revline[1]); + $wikiname = $username_map[$user]; + if ($wikiname != "") + $user = "[[~" . $wikiname . "|" . $user . "]]"; + $date = substr($revline[2],1,10); + $time = substr($revline[2],12,5); + $revurl = "[[ ".sprintf($svn_url, $rev)." | $rev ]]"; + $description = "Revision $revurl committed by $user"; + $tstamp = strtotime("$date $time:00"); + } else { + $icon = "svn_commit"; + $notes = trim($line); + $events[] = array( 'cache_id' => $rev, 'tstamp' => $tstamp, 'icon' => $icon, 'date' => $date, + 'time' => $time, 'user' => $user, 'description' => $description, 'notes' => $notes); + } + } + } +} + +/****************** PmWiki events *********************/ +$lines = file($wiki_file); +$chline = ""; +foreach ($lines as $line) { + if (substr($line,0,5) == "text=") { + $chline = substr($line,7); + } +} +if ($chline != "") { + $wikiedits = split('\*', $chline); + $icon = "wiki_changed"; + foreach ($wikiedits as $ed) { + preg_match('/\[\[.*\]\] ./', $ed, $matches); + $page = $matches[0]; + preg_match('/by \[\[.*\]\]/', $ed, $matches); + $user = $matches[0]; + preg_match("/\=(.*)\=/s",$ed,$matches); + $notes = $matches[1]; + preg_match("/\. \. \. (.*?) by/s",$ed,$matches); + $date = $matches[1]; + $date = str_replace(", at", "", $date); // old entry format + $tstamp = strtotime($date); + preg_match('/(..\:..)/',$date,$matches); + $time = $matches[0]; + $date = date("Y-m-d", $tstamp); + $description = "Wiki page $page edited $user"; + if ($tstamp > $last_wiki) { + $events[] = array( 'cache_id' => $tstamp, 'tstamp' => $tstamp, 'icon' => $icon, 'date' => $date, + 'time' => $time, 'user' => $user, 'description' => $description, 'notes' => $notes); + } + } +} + +/*************** Finally, all events *********************/ +$sth = $dbc->prepare("insert into events values (NULL, ?, ?, ?, ?, ?, ?, ?, ?)"); +foreach ($events as $evt) { + $res = $dbc->execute($sth, $evt); + if (DB::isError($res)) die("Query error"); +} + +?> Property changes on: tools/webtools/timeline/tlcacher.php ___________________________________________________________________ Name: svn:executable + *
participants (1)
-
crux@crux.nu