[Midnightbsd-cvs] mports: www/tmpls: Add magus webapp.
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Wed Oct 31 16:05:33 EDT 2007
Log Message:
-----------
Add magus webapp.
Added Files:
-----------
mports/Tools/magus/www/data/magus:
index.cgi (r1.1)
mports/Tools/magus/www/data/magus/elements:
magus.css (r1.1)
mports/Tools/magus/www/tmpls:
error.tmpl (r1.1)
footer.tmpl (r1.1)
header.tmpl (r1.1)
index.tmpl (r1.1)
list.tmpl (r1.1)
log.tmpl (r1.1)
port.tmpl (r1.1)
result-list.tmpl (r1.1)
subresults.tmpl (r1.1)
-------------- next part --------------
--- /dev/null
+++ Tools/magus/www/data/magus/index.cgi
@@ -0,0 +1,241 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use lib qw(/usr/mports/Tools/lib);
+
+use Magus;
+use CGI;
+use HTML::Template;
+
+eval {
+ main();
+};
+
+error($@) if $@;
+
+sub main {
+ my $p = CGI->new;
+ my $path = $p->path_info;
+
+ if ($path eq '' || $path eq '/') {
+ summary_page($p);
+ } elsif ($path =~ m:/list/(.*):) {
+ list_page($p, $1);
+ } elsif ($path =~ m:/ports/(.*):) {
+ port_page($p, $1);
+ } elsif ($path =~ m:/results/(\d+)/log:) {
+ log_page($p, $1);
+ } elsif ($path =~ m:/results/(\d+)/details:) {
+ subresults_page($p, $1);
+ } else {
+ die "Unknown path: $path\n";
+ }
+}
+
+sub summary_page {
+ my ($p) = @_;
+
+ Magus::Result->set_sql(last_twenty => qq{
+ SELECT __ESSENTIAL__
+ FROM __TABLE__
+ ORDER BY id DESC LIMIT 20
+ });
+
+ my @results = map {{
+ summary => $_->summary,
+ port => $_->port,
+ version => $_->version,
+ machine => $_->machine->name,
+ arch => $_->arch
+ }} Magus::Result->search_last_twenty;
+
+ print $p->header;
+
+ my $tmpl = template($p, 'index.tmpl');
+
+ $tmpl->param(
+ title => 'Magus Summary',
+ results => \@results
+ );
+
+ my $dbh = Magus::Result->db_Main();
+ my $sth = $dbh->prepare("SELECT summary,COUNT(*) as count FROM results JOIN ports ON results.port=ports.name AND results.version=ports.version GROUP BY summary ORDER BY count DESC");
+ $sth->execute;
+ my $stats = $sth->fetchall_arrayref({});
+ $sth->finish;
+
+ $sth = $dbh->prepare("SELECT COUNT(DISTINCT port) FROM results");
+ $sth->execute;
+ my ($count) = $sth->fetchrow_array;
+ $sth->finish;
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM ports WHERE name NOT IN (SELECT port FROM results)");
+ $sth->execute;
+ my ($untested) = $sth->fetchrow_array;
+ $sth->finish;
+
+ my @locks = map {{
+ port => $_->port->name,
+ machine => $_->machine->name,
+ arch => $_->arch
+ }} Magus::Lock->retrieve_all;
+
+ $tmpl->param(
+ ports_tested => $count,
+ ports_untested => $untested,
+ stats => $stats,
+ locks => \@locks
+ );
+ print $tmpl->output;
+}
+
+sub port_page {
+ my ($p, $port) = @_;
+
+ my $tmpl = template($p, "port.tmpl");
+
+ $port = Magus::Port->retrieve($port) || die "No such port: $port";
+
+ $tmpl->param(
+ port => $port->name,
+ title => "Magus // $port",
+ desc => $port->description,
+ );
+
+ my @results = map { {
+ id => $_->id,
+ version => $_->version,
+ machine => $_->machine->name,
+ arch => $_->arch,
+ summary => $_->summary,
+ has_log => defined $_->logs->next,
+ has_subresults => defined $_->subresults->next,
+ }} $port->results;
+
+ if (@results) {
+ $tmpl->param(
+ results => \@results,
+ );
+ }
+
+ my @depends = map { {
+ port => $_->name
+ } } $port->depends;
+
+ if (@depends) {
+ $tmpl->param(depends => \@depends);
+ }
+
+ my @depends_of = map { {
+ port => $_->port
+ } } Magus::Depend->search(dependency => $port);
+
+ if (@depends_of) {
+ $tmpl->param(depends_of => \@depends_of);
+ }
+
+ print $p->header, $tmpl->output;
+}
+
+sub subresults_page {
+ my ($p, $id) = @_;
+
+ my $tmpl = template($p, "subresults.tmpl");
+
+ my $result = Magus::Result->retrieve($id) || die "No such results: $id";
+
+ my @subresults = map { {
+ phase => $_->phase,
+ type => $_->type,
+ name => $_->name,
+ msg => $_->msg
+ }} $result->subresults;
+
+ if (@subresults) {
+ $tmpl->param(
+ subresults => \@subresults,
+ );
+ }
+
+ print $p->header, $tmpl->output;
+}
+
+
+
+sub log_page {
+ my ($p, $id) = @_;
+
+ my $result = Magus::Result->retrieve($id) || die "No such result.";
+
+ my $log = $result->logs->next;
+
+ my $tmpl = template($p, 'log.tmpl');
+
+ $tmpl->param(port => $result->port, log => $log->data);
+
+ print $p->header, $tmpl->output;
+}
+
+sub list_page {
+ my ($p, $summary) = @_;
+
+ my @results = map {{
+ summary => $_->summary,
+ port => $_->port,
+ version => $_->version,
+ machine => $_->machine->name,
+ arch => $_->arch
+ }} sort { $b->id <=> $a->id } Magus::Result->search(summary => $summary);
+
+ my $tmpl = template($p, 'list.tmpl');
+
+ my %titles = (
+ fail => 'Failed Ports',
+ skip => 'Skipped Ports',
+ pass => 'Passed Ports',
+ internal => 'Internal failures',
+ warn => 'Warned Ports',
+ );
+
+ $tmpl->param(results => \@results, title => $titles{$summary}, count => scalar @results);
+
+ print $p->header, $tmpl->output;
+}
+
+
+sub error {
+ my ($msg) = @_;
+
+ my $tmpl = template(CGI->new, 'error.tmpl');
+
+ $tmpl->param(error => $msg, title => 'Error');
+
+ print "Content-Type: text/html\n\n", $tmpl->output;
+}
+
+
+
+sub template {
+ my ($p, $file) = @_;
+
+ my $tmpl = HTML::Template->new(
+ cache => 1,
+ global_vars => 1,
+ filename => "/usr/local/www/apache22/tmpls/$file",
+ loop_context_vars => 1,
+ die_on_bad_params => 0
+ );
+
+ $tmpl->param(
+ title => 'Magus',
+# breadcrumbs => breadcrumbs(path => $p->path_info or '/'),
+ root => $p->script_name(),
+ list_root => $p->script_name() . '/list',
+ port_root => $p->script_name() . '/ports',
+ result_root => $p->script_name() . '/results',
+ );
+
+ return $tmpl;
+}
+
\ No newline at end of file
--- /dev/null
+++ Tools/magus/www/data/magus/elements/magus.css
@@ -0,0 +1,50 @@
+
+table {
+ border: solid 1px #555;
+ border-spacing: 0px;
+}
+
+table td {
+ border: solid 1px #eee;
+ padding: 4px 10px;
+}
+
+table th {
+ border-bottom: solid 1px #888;
+}
+
+*.fail {
+ color: #C0000B;
+}
+
+*.warn {
+ color: orange;
+}
+
+*.internal {
+ color: blue;
+}
+
+*.pass {
+ color: green;
+}
+
+*.skip {
+ color: #666;
+}
+
+
+div.right {
+ float: right;
+ position: relative;
+ bottom: 60px;
+ right: 20px
+}
+
+ul.depends li {
+ list-style: none;
+}
+
+ul.depends {
+ padding: 0px;
+}
\ No newline at end of file
--- /dev/null
+++ Tools/magus/www/tmpls/subresults.tmpl
@@ -0,0 +1,20 @@
+<TMPL_INCLUDE NAME="header.tmpl">
+
+<TMPL_IF NAME="subresults">
+
+<table class="port-results">
+<TMPL_LOOP name="subresults">
+<tr class="<TMPL_VAR NAME=type>">
+ <td><TMPL_VAR NAME="type"></td>
+ <td><TMPL_VAR NAME="phase"></td>
+ <td><TMPL_VAR NAME="name"></td>
+</tr>
+<tr class="<TMPL_VAR NAME=type>">
+ <td colspan="3"><TMPL_VAR NAME="msg"></td>
+</tr>
+</TMPL_LOOP>
+</table>
+
+</TMPL_IF>
+
+<TMPL_INCLUDE NAME="footer.tmpl">
--- /dev/null
+++ Tools/magus/www/tmpls/footer.tmpl
@@ -0,0 +1 @@
+</body></html>
\ No newline at end of file
--- /dev/null
+++ Tools/magus/www/tmpls/list.tmpl
@@ -0,0 +1,8 @@
+<TMPL_INCLUDE NAME="header.tmpl">
+
+<h1><a href="/magus/">Magus</a> :: <TMPL_VAR name="TITLE"></h1>
+
+<p><TMPL_VAR NAME="count"> ports:</p>
+
+<TMPL_INCLUDE NAME="result-list.tmpl">
+<TMPL_INCLUDE NAME="footer.tmpl">
--- /dev/null
+++ Tools/magus/www/tmpls/error.tmpl
@@ -0,0 +1,8 @@
+<TMPL_INCLUDE NAME="header.tmpl">
+
+<h1>Error</h1>
+
+<p><TMPL_VAR NAME="error">
+
+
+<TMPL_INCLUDE NAME="footer.tmpl">
--- /dev/null
+++ Tools/magus/www/tmpls/port.tmpl
@@ -0,0 +1,66 @@
+<TMPL_INCLUDE NAME="header.tmpl">
+
+<h1><a href="/magus/">Magus</a> :: <TMPL_VAR name="port"></h1>
+
+<div class="right">
+<a href="http://cvsweb.midnightbsd.org/mports/<TMPL_VAR NAME=port>">CVSWeb</a>
+
+<h3>Depends On</h3>
+
+<TMPL_IF NAME="depends">
+<ul class="depends">
+ <TMPL_LOOP NAME="depends">
+ <li><a href="<TMPL_VAR NAME=port_root>/<TMPL_VAR NAME=port>"><TMPL_VAR NAME="port"></a></li>
+ </TMPL_LOOP>
+</ul>
+<TMPL_ELSE>
+<i>Nothing</i>
+</TMPL_IF>
+
+<h3>Depend Of</h3>
+
+<TMPL_IF NAME="depends_of">
+<ul class="depends">
+ <TMPL_LOOP NAME="depends_of">
+ <li><a href="<TMPL_VAR NAME=port_root>/<TMPL_VAR NAME=port>"><TMPL_VAR NAME="port"></a></li>
+ </TMPL_LOOP>
+</ul>
+<TMPL_ELSE>
+<i>Nothing</i>
+</TMPL_IF>
+
+</div>
+
+<p><TMPL_VAR NAME="desc"></p>
+
+<TMPL_IF name="results">
+
+<table class="port-results">
+<tr>
+ <th>Version</th>
+ <th>Machine</th>
+ <th>Arch</th>
+ <th>Summary</th>
+ <td></td>
+</tr>
+<TMPL_LOOP name="results">
+<tr class="<TMPL_VAR NAME=summary>">
+ <td><TMPL_VAR NAME="version"></td>
+ <td><TMPL_VAR NAME="machine"></td>
+ <td><TMPL_VAR NAME="arch"></td>
+ <td><TMPL_VAR NAME="summary"></td>
+ <td>
+ <a href="<TMPL_VAR NAME=result_root>/<TMPL_VAR NAME=id>/details">Details</a>
+ --
+ <a href="<TMPL_VAR NAME=result_root>/<TMPL_VAR NAME=id>/log">Log</a>
+ </td>
+</tr>
+</TMPL_LOOP>
+</table>
+<TMPL_ELSE>
+<p><TMPL_VAR name=port> has not been tested.</p>
+</TMPL_IF>
+
+
+
+<TMPL_INCLUDE NAME="footer.tmpl">
--- /dev/null
+++ Tools/magus/www/tmpls/index.tmpl
@@ -0,0 +1,58 @@
+<TMPL_INCLUDE NAME="header.tmpl">
+
+<h1>Magus Summary</h1>
+
+<div class="right">
+<h2>Stats</h2>
+<table class="stats">
+<tr>
+ <td>Tested</td><td><TMPL_VAR NAME="ports_tested"></td>
+</tr>
+<tr>
+ <td>Untested</td><td><TMPL_VAR NAME="ports_untested"></td>
+</tr>
+<TMPL_LOOP NAME="stats">
+<tr class="<TMPL_VAR name=summary>">
+ <td><TMPL_VAR NAME="summary"></td>
+ <td><a href="<TMPL_VAR NAME=list_root>/<TMPL_VAR NAME=summary>"><TMPL_VAR NAME=count></td>
+</tr>
+</TMPL_LOOP>
+</table>
+
+<TMPL_IF NAME="locks">
+<h2>Currently Building</h2>
+<table class="locks">
+<tr>
+ <th>Port</th>
+ <th>Machine</th>
+ <th>Arch</th>
+</tr>
+<TMPL_LOOP NAME="locks">
+<tr>
+ <td><a href="<TMPL_VAR name=port_root>/<TMPL_VAR NAME=port>"><TMPL_VAR NAME="port"></a></td>
+ <td><TMPL_VAR name="machine"></td>
+ <td><TMPL_VAR name="arch"></td>
+</tr>
+</TMPL_LOOP>
+</table>
+</TMPL_IF>
+
+</div>
+
+
+
+<h2>Latest Results</h2>
+<table class="result-list">
+ <tr><th>Port</th><th>Version</th><th>Summary</th><th>Machine</th><th>Arch</th></tr>
+ <TMPL_LOOP NAME=results>
+ <tr class="<TMPL_VAR NAME=summary>">
+ <td><a href="<TMPL_VAR name=port_root>/<TMPL_VAR NAME=port>"><TMPL_VAR NAME="port"></a></td>
+ <td><TMPL_VAR NAME=version></td>
+ <td><TMPL_VAR NAME=summary></td>
+ <td><TMPL_VAR NAME=machine></td>
+ <td><TMPL_VAR NAME=arch></td>
+ </tr>
+ </TMPL_LOOP>
+</table>
+
+<TMPL_INCLUDE NAME="footer.tmpl">
\ No newline at end of file
--- /dev/null
+++ Tools/magus/www/tmpls/header.tmpl
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title><TMPL_VAR NAME="title"></title>
+
+ <link rel="stylesheet" href="/magus/elements/magus.css" media="screen" />
+</head>
+<body>
--- /dev/null
+++ Tools/magus/www/tmpls/log.tmpl
@@ -0,0 +1,7 @@
+<TMPL_INCLUDE NAME="header.tmpl">
+
+<h1><TMPL_VAR name="port"></h1>
+
+<pre><TMPL_VAR name="log"></pre>
+
+<TMPL_INCLUDE NAME="footer.tmpl">
--- /dev/null
+++ Tools/magus/www/tmpls/result-list.tmpl
@@ -0,0 +1,13 @@
+<table class="result-list">
+ <tr><th>Port</th><th>Version</th><th>Summary</th><th>Machine</th><th>Arch</th></tr>
+ <TMPL_LOOP NAME=results>
+ <tr class="<TMPL_VAR NAME=summary>">
+ <td><a href="<TMPL_VAR name=port_root>/<TMPL_VAR NAME=port>"><TMPL_VAR NAME="port"></a></td>
+ <td><TMPL_VAR NAME=version></td>
+ <td><TMPL_VAR NAME=summary></td>
+ <td><TMPL_VAR NAME=machine></td>
+ <td><TMPL_VAR NAME=arch></td>
+ </tr>
+ </TMPL_LOOP>
+</table>
+
More information about the Midnightbsd-cvs
mailing list