Skip to content

Commit

Permalink
adding web page source code
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-t committed Oct 21, 2011
1 parent 05a95d4 commit 5f8600e
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cruise-control/README
Expand Up @@ -8,6 +8,7 @@ Features:
- Run regression tests
- Run a sample EMS pipeline
- Report results into logfiles
- A simple web interface in PHP

How to run cruise control:

Expand All @@ -21,4 +22,11 @@ How to run cruise control:
4) Execute ./test_all_new_commits.sh yourfile.config


How to set up the web interface:

1) Install Apache and PHP

2) Point StaticData::logs_path to correct directory, e.g. /home/cruise/logs/example/
Default value is 'data', you might want to just create a symlink.

Written by Ondrej Bojar, Ales Tamchyna, Barry Haddow, Rimas Blazaitis
112 changes: 112 additions & 0 deletions cruise-control/web/html_templates.php
@@ -0,0 +1,112 @@
<?php

function show_header($title)
{
echo "
<html>
<head>
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=utf-8\">
<title>$title</title>
</head><body>";
}

function show_heading($text, $size = 1)
{
echo "
<h$size>$text</h$size>";
}

function show_footer()
{
echo "
</body>
<html>";
}

function end_table()
{
echo "
</table>";
}

function array_to_table_row($odd = true, $data)
{
$bgcolor = $odd ? " bgcolor=\"#ccccdd\"" : "";
echo "
<tr$bgcolor>";
foreach ($data as &$item) {
echo "
<td style=\"padding-left:8px; padding-right:8px\">$item</td>";
}
echo "
</tr>";
}

function start_table()
{
echo '
<table rules="cols" frame="vsides">';
}

function start_form($action, $method = "get")
{
echo "
<form action=\"$action\" method=\"$method\">";
}

function end_form()
{
echo "
</form>";
}

function show_select_box($items, $name, $selected = "", $onchange_hdl = "")
{
$onchange = $onchange_hdl ? " onchange=\"$onchange_hdl\"" : "";
echo "
<select name=\"$name\"$onchange>";
foreach ($items as &$item) {
$item_selected = $selected == $item ? " selected=\"yes\"" : "";
echo "
<option value=\"$item\"$item_selected>$item</option>";
}
echo "
</select>";
}

function get_href($label, $url, $new_window = false)
{
$target = $new_window ? " target=\"_blank\"" : "";
return "<a href=\"$url\"$target>$label</a>";
}

function warn($msg)
{
echo "<p><font color=\"red\"><b>$msg</b></font>";
}

function get_current_url()
{
return $_SERVER["REQUEST_URI"];
}

function set_var($url, $var, $value)
{
$url = cut_var($url, $var);
if ($url[strlen($url) - 1] == "?") {
$url .= "$var=$value";
} elseif (strpos($url, "?") !== false) {
$url .= "&$var=$value";
} else {
$url .= "?$var=$value";
}
return $url;
}

function cut_var($url, $var)
{
// XXX there is probably a cleaner solution for this
return preg_replace('/&?' . $var . '=[^&]+/', '', $url);
}

?>
101 changes: 101 additions & 0 deletions cruise-control/web/index.php
@@ -0,0 +1,101 @@
<?php

include("html_templates.php");
include("log_wrapper.php");

const SHOW_ITEMS = 50;
const GITHUB_LINK = "https://github.com/moses-smt/mosesdecoder/commit/";

show_header("Moses Cruise Control");
echo "\n<center>\n";

show_heading("Moses Cruise Control");
echo "\n</center>\n";

// show current status of 'master' branch
$master_branch = new Branch("master");
$last_commit = $master_branch->get_next_commit();
$last_commit->read_log();
show_heading("Current status of master: " . colorize_status($last_commit->get_status()), 3);
$branch_name = ! empty($_GET["branch"]) ? $_GET["branch"] : "master";

// check that user wants to see a valid branch
$all_branches = get_all_branch_names();
if (! in_array($branch_name, $all_branches)) {
warn("Branch '$branch_name' not found (only branches with some tests done can be viewed)");
$branch_name = "master";
}

// branch select box
start_form("", "get");
echo "<p>Showing log of branch: ";
show_select_box($all_branches, "branch", $branch_name, "submit()");
end_form();

$branch = new Branch("$branch_name");
$start_with = ! empty($_GET["start"]) ? $_GET["start"] : 0;
$branch->set_line($start_with);

show_navigation($start_with);

// table of commits
start_table();
array_to_table_row(true, array("<b>Commit Link</b>", "<b>Status</b>", "<b>Full Log</b>",
"<b>Timestamp</b>", "<b>Author</b>", "<b>Commit Message</b>" ));
for ($i = 0; $i < SHOW_ITEMS; $i++) {
$last_commit = $branch->get_next_commit();

if ( $last_commit->get_name() == "" ) {
array_to_table_row(array("=== End of log ==="));
break;
}
$last_commit->read_log();
$last_commit->read_info();

array_to_table_row(($i % 2 == 1),
array( get_href(substr($last_commit->get_name(), 0, 10) . "...", GITHUB_LINK . $last_commit->get_name(), true),
colorize_status($last_commit->get_status()),
$last_commit->was_tested() ? get_href("Log", $last_commit->get_log_file(), true) : "N/A",
$last_commit->get_timestamp(),
$last_commit->get_author(),
substr($last_commit->get_message(), 0, 30) . (strlen($last_commit->get_message()) > 30 ? "..." : "")));
}

end_table();

show_navigation($start_with);
show_footer();

// HTML ends here

function colorize_status($status)
{
switch ( substr(strtolower($status), 0, 1) ) {
case "o":
$color = "green";
break;
case "f":
$color = "red";
break;
default:
$color = "#FFDD00";
}
return "<font color=\"$color\"><b>$status</b></font>";
}

function show_navigation($start_with)
{
start_form("", "get");
if ($start_with > 0) {
echo get_href("<p>Previous",
set_var(get_current_url(), "start", max(0, $start_with - SHOW_ITEMS)));
} else {
echo "Previous";
}
echo " ";

echo get_href("Next", set_var(get_current_url(), "start", $start_with + SHOW_ITEMS));
end_form();
}

?>

0 comments on commit 5f8600e

Please sign in to comment.