Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAles Tamchyna <a.tamchyna@gmail.com>2011-10-22 01:36:20 +0400
committerAles Tamchyna <a.tamchyna@gmail.com>2011-10-22 01:36:20 +0400
commit5f8600e1bd585d693d2300fac6b44936e7527974 (patch)
treed7b91ea4a41807944c3c8c2a6f5a9b925d1e8cb9 /cruise-control
parent05a95d464da5018cb392d46d49a2f0ace929e891 (diff)
adding web page source code
Diffstat (limited to 'cruise-control')
-rw-r--r--cruise-control/README8
-rw-r--r--cruise-control/web/html_templates.php112
-rw-r--r--cruise-control/web/index.php101
-rw-r--r--cruise-control/web/log_wrapper.php188
-rw-r--r--cruise-control/web/show_commit.php17
5 files changed, 426 insertions, 0 deletions
diff --git a/cruise-control/README b/cruise-control/README
index ede761c08..6a45d7241 100644
--- a/cruise-control/README
+++ b/cruise-control/README
@@ -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:
@@ -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
diff --git a/cruise-control/web/html_templates.php b/cruise-control/web/html_templates.php
new file mode 100644
index 000000000..83f6cc879
--- /dev/null
+++ b/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);
+}
+
+?>
diff --git a/cruise-control/web/index.php b/cruise-control/web/index.php
new file mode 100644
index 000000000..3d6aee6ae
--- /dev/null
+++ b/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();
+}
+
+?>
diff --git a/cruise-control/web/log_wrapper.php b/cruise-control/web/log_wrapper.php
new file mode 100644
index 000000000..af03db016
--- /dev/null
+++ b/cruise-control/web/log_wrapper.php
@@ -0,0 +1,188 @@
+<?php
+
+class StaticData
+{
+ const logs_path = "./data/";
+}
+
+function get_all_branch_names()
+{
+ $branches = array();
+ $dir_hdl = opendir(StaticData::logs_path);
+ while (($file = readdir($dir_hdl)) !== false) {
+ if (($pos = strpos($file, ".revlist")) > 0) {
+ array_push($branches, substr($file, 0, $pos));
+ }
+ }
+ return $branches;
+}
+
+class Branch
+{
+ public function __construct($name)
+ {
+ $this->name = $name;
+ $this->create_revlist_hdl();
+ }
+
+ public function get_next_commit()
+ {
+ return new Commit( chop( fgets($this->revlist_hdl) ) );
+ }
+
+ public function set_line($line)
+ {
+ $this->reset();
+ $index = 0;
+ while ($this->revlist_hdl && $index < $line) {
+ fgets($this->revlist_hdl);
+ $index++;
+ }
+ }
+
+ public function reset()
+ {
+ fclose($this->revlist_hdl);
+ $this->create_revlist_hdl();
+ }
+
+ private function create_revlist_hdl()
+ {
+ $this->revlist_hdl = fopen(StaticData::logs_path . "/" . $this->name . ".revlist", "r");
+ }
+
+ private $name;
+ private $revlist_hdl;
+}
+
+class Commit
+{
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+ public function read_log()
+ {
+ if (! $this->was_tested()) {
+ return;
+ }
+
+ $log_hdl = fopen(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".log", "r");
+ while (($line = fgets($log_hdl)) !== false) {
+ if (preg_match('/tests passed/', $line)) {
+ $this->passed_percent = substr($line, 0, strpos('%', $line));
+ }
+ else if (preg_match('/INVESTIGATE THESE FAILED TESTS/', $line)) {
+ $this->failed_tests = substr($line, 39);
+ }
+ else if (! $this->is_ok() && preg_match('/## Status:/', $line)) {
+ $this->failed_at = substr($line, 16);
+ }
+ }
+ }
+
+ public function read_info()
+ {
+ $info_hdl = fopen(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".info", "r");
+ while (($line = fgets($info_hdl)) !== false) {
+ if (preg_match('/Author:/', $line)) {
+ $this->author = substr("$line", 7);
+ }
+ else if (preg_match('/Date:/', $line)) {
+ $this->timestamp = substr("$line", 12);
+ break;
+ }
+ }
+ while (($line = fgets($info_hdl)) !== false) {
+ $this->message .= chop($line);
+ }
+ $this->message = preg_replace('/\s+/', ' ', $this->message);
+ }
+
+ public function was_tested()
+ {
+ return file_exists(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".log");
+ }
+
+ public function is_ok()
+ {
+ if (! $this->was_tested()) {
+ return false;
+ } else {
+ return file_exists(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".OK");
+ }
+ }
+
+ public function get_status()
+ {
+ return $this->was_tested()
+ ? ($this->is_ok() ? "OK" : "Failed: " . $this->get_failed_at()) : "Not tested";
+ }
+
+ public function get_passed_percent()
+ {
+ return $this->passed_percent;
+ }
+
+ public function get_failed_tests()
+ {
+ return $this->failed_tests;
+ }
+
+ public function get_failed_at()
+ {
+ return $this->failed_at;
+ }
+
+ public function get_message()
+ {
+ return $this->message;
+ }
+
+ public function get_author()
+ {
+ return $this->author;
+ }
+
+ public function get_timestamp()
+ {
+ return $this->timestamp;
+ }
+
+ public function get_name()
+ {
+ return $this->name;
+ }
+
+ public function get_log_file()
+ {
+ return "show_commit.php?commit_id=$this->name&type=log";
+ }
+
+ public function get_info_file()
+ {
+ return "show_commit.php?commit_id=$this->name&type=info";
+ }
+
+ private function open_log()
+ {
+ return fopen($this->get_log_file());
+ }
+
+ private function open_info()
+ {
+ return fopen($this->get_info_file());
+ }
+
+ private $name;
+ private $passed_percent;
+ private $failed_tests;
+ private $failed_at;
+ private $message;
+ private $author;
+ private $timestamp;
+
+}
+
+?>
diff --git a/cruise-control/web/show_commit.php b/cruise-control/web/show_commit.php
new file mode 100644
index 000000000..bcb5e5732
--- /dev/null
+++ b/cruise-control/web/show_commit.php
@@ -0,0 +1,17 @@
+<?php
+
+include("html_templates.php");
+include("log_wrapper.php");
+
+$type = $_GET["type"];
+$commit_id = $_GET["commit_id"];
+
+if (($type != "log" && $type != "info") || empty($commit_id)) {
+ warn("Wrong arguments, dying") && die();
+}
+
+header("Content-Type: text/plain; charset=UTF-8");
+
+include(StaticData::logs_path . "/" . substr($commit_id, 0, 1) . "/" . $commit_id . "." . $type);
+
+?>