Skip to content

Commit

Permalink
Web|Builder: Generating the build index and build report header
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 28, 2017
1 parent c0f6504 commit e11d84c
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 24 deletions.
49 changes: 26 additions & 23 deletions webapi/1/admin/bdb.php
Expand Up @@ -24,19 +24,20 @@ function add_build($json_args)
$args = json_decode($json_args);
if ($args == NULL) return; // JSON parse error.

$build = (int) $args->build;
$type = ($args->type == 'stable'? BT_STABLE :
$args->type == 'candidate'? BT_CANDIDATE : BT_UNSTABLE);
$build = (int) $args->build;
$type = ($args->type == 'stable'? BT_STABLE :
$args->type == 'candidate'? BT_CANDIDATE : BT_UNSTABLE);
$version = $db->real_escape_string($args->version);
$major = (int) $args->major;
$minor = (int) $args->minor;
$patch = (int) $args->patch;
$label = $db->real_escape_string($args->label);
$major = (int) $args->major;
$minor = (int) $args->minor;
$patch = (int) $args->patch;
$label = $db->real_escape_string($args->label);
$changes = $db->real_escape_string($args->changes);

$db = db_open();
db_query($db, "INSERT INTO ".DB_TABLE_BUILDS
. " (build, type, version, major, minor, patch, label) VALUES ("
. "$build, $type, '$version', $major, $minor, $patch, '$label')");
. " (build, type, version, major, minor, patch, label, changes) VALUES ("
. "$build, $type, '$version', $major, $minor, $patch, '$label', '$changes')");
$db->close();
}

Expand All @@ -59,20 +60,20 @@ function add_file($json_args)

$build = (int) $args->build;
$plat_id = get_platform_id($db, $args->platform);
$type = ($args->type == 'binary'? FT_BINARY :
$args->type == 'log'? FT_LOG :
$args->type == 'changes'? FT_CHANGES : FT_NONE);
$type = ($args->type == 'binary'? FT_BINARY :
$args->type == 'log'? FT_LOG :
FT_NONE);
$name = $db->real_escape_string($args->name);

$header = 'build, plat_id, type, name';
$values = "$build, $plat_id, $type, '$name'";

if (in_array('md5', $args)) {
if (property_exists('md5', $args)) {
$md5 = $db->real_escape_string($args->md5);
$header .= ', md5';
$values .= ", '$md5'";
}
if (in_array('signature', $args)) {
if (property_exists('signature', $args)) {
$sigature = $db->real_escape_string($args->signature);
$header .= ', signature';
$values .= ", '$signature'";
Expand Down Expand Up @@ -145,6 +146,7 @@ function purge_old_builds()
$table = DB_TABLE_PLATFORMS;
$sql = "CREATE TABLE $table ("
. "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, "
. "ord INT NOT NULL, "
. "platform VARCHAR(50) NOT NULL, "
. "name VARCHAR(100) NOT NULL, "
. "os VARCHAR(20) NOT NULL, "
Expand All @@ -154,13 +156,13 @@ function purge_old_builds()
db_query($db, $sql);

// Set up the known platforms.
db_query($db, "INSERT INTO $table (platform, name, os, cpu_arch, cpu_bits) VALUES "
. "('win-x86', 'Windows 7 (32-bit)', 'windows', 'x86', 32), "
. "('win-x64', 'Windows 7 (64-bit)', 'windows', 'x64', 64), "
. "('mac10_8-x86_64', 'macOS 10.8', 'macx', 'x86_64', 64), "
. "('ubuntu-x86_64', 'Ubuntu 16.04 LTS', 'linux', 'amd64', 64), "
. "('fedora-x86_64', 'Fedora 23', 'linux', 'x86_64', 64), "
. "('source', 'Source', 'any', 'any', 0);");
db_query($db, "INSERT INTO $table (ord, platform, name, os, cpu_arch, cpu_bits) VALUES "
. "(100, 'win-x64', 'Windows 7 (64-bit)', 'windows', 'x64', 64), "
. "(200, 'win-x86', 'Windows 7 (32-bit)', 'windows', 'x86', 32), "
. "(300, 'mac10_8-x86_64', 'macOS 10.8', 'macx', 'x86_64', 64), "
. "(400, 'ubuntu-x86_64', 'Ubuntu 16.04 LTS', 'linux', 'amd64', 64), "
. "(500, 'fedora-x86_64', 'Fedora 23', 'linux', 'x86_64', 64), "
. "(600, 'source', 'Source', 'any', 'any', 0);");

// File archive.
$table = DB_TABLE_FILES;
Expand All @@ -172,7 +174,7 @@ function purge_old_builds()
. "name VARCHAR(200) NOT NULL, "
. "md5 CHAR(32), "
. "signature TEXT, "
. "timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
. "timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
. ") CHARACTER SET utf8";
db_query($db, $sql);

Expand All @@ -185,8 +187,9 @@ function purge_old_builds()
. "major INT NOT NULL, "
. "minor INT NOT NULL, "
. "patch INT NOT NULL, "
. "label INT NOT NULL, "
. "label VARCHAR(30) NOT NULL, "
. "blurb TEXT, "
. "changes TEXT, "
. "timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
. ") CHARACTER SET utf8";
db_query($db, $sql);
Expand Down
119 changes: 119 additions & 0 deletions webapi/1/build_page.css
@@ -0,0 +1,119 @@
body {
font-family: "Open Sans";
max-width: 80ex;
margin-left: auto;
margin-right: auto;
}

h1, h2 {
font-weight: 300;
text-align: center;
}

h1 {
font-size: 275%;
margin-top: 1em;
}

h2 {
font-size: 200%;
margin-top: 1.5em;
}

h3 {
font-size: 150%;
margin-top: 1.5em;
}

p {
color: #666;
text-align: justify;
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
}
ul {
color: #666;
}
/*blockquote {
font-size: 95%;
color: #aaa !important;
margin-left: 0em;
margin-top: 1ex;
padding-left: 1em;
border-left: 2px solid #ddd;
}
blockquote:hover {
border-left: 2px solid #2c2;
color: #666 !important;
}*/

a {
color: #191;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

table {
margin: auto;
}
th {
border-bottom: 1px solid #ccc;
}
td, th {
padding: 0.5ex;
}

/* Build List */

.links {
text-align: center;
}

div.buildlist {
text-align: center;
}

div.build {
min-width: 5em;
display: inline-block;
border: 1px solid #bdb;
border-radius: 1ex;
margin: 0.5ex;
padding: 1ex;
text-align: center;
}

div.build.candidate {
border-color: #da8;
background: #fd8;
}

div.build.stable {
border-color: #371;
background: #6a3;
}

div.build.candidate a {
color: #850;
}

div.build.stable a {
color: white;
}

.buildnumber {
font-size: 150%;
}

.builddate, .buildversion {
font-size: 80%;
}

.buildversion {
font-weight: 300;
}
144 changes: 144 additions & 0 deletions webapi/1/builds.php
@@ -0,0 +1,144 @@
<?php
/*
* Doomsday Web API: Build Information
* Copyright (c) 2016-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* License: GPL v2+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses/gpl.html
*/

require_once('database.inc.php');

ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);

function generate_header($page_title)
{
echo("<html><head>\n");
echo(" <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>\n");
echo(" <link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,700' rel='stylesheet' type='text/css'>\n");
echo(" <link href='http://api.dengine.net/1/build_page.css' rel='stylesheet' type='text/css'>\n");
echo(" <title>$page_title</title>\n");
echo("</head><body>\n");
echo("<h1>$page_title</h1>\n");
}

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

function generate_build_page($number)
{
$db = db_open();
$result = db_query($db, "SELECT * FROM ".DB_TABLE_BUILDS." WHERE build=$number");
if ($row = $result->fetch_assoc()) {
$type = $row['type'];
$version = $row['version'];
$blurb = $row['blurb'];
$ts = $row['timestamp'];

$files = db_list_build_files($db, $number);

// Output page header.
generate_header("Build $number");

echo("<p class='links'><a href='http://dengine.net/'>dengine.net</a> | <a href='".DENG_API_URL."/builds?format=html'>Autobuilder Index</a>| <a href='".DENG_API_URL."/builds?format=feed'>RSS Feed</a></p>\n");

echo(db_build_summary($db, $number));

// Output page footer.
generate_footer();
}
$db->close();
}

function generate_build_index_page()
{
generate_header("Doomsday Autobuilder");

echo("<p class='links'><a href='http://dengine.net/'>dengine.net</a> | <a href='".DENG_API_URL."/builds?format=feed'>RSS Feed</a></p>"
.'<h2>Latest Builds</h2>'
.'<div class="buildlist">');

$all_versions = array();
$db = db_open();
$result = db_query($db, "SELECT build, type, UNIX_TIMESTAMP(timestamp), version"
." FROM ".DB_TABLE_BUILDS." ORDER BY timestamp DESC");
while ($row = $result->fetch_assoc()) {
$build = $row['build'];
$type = build_type_text($row['type']);
$timestamp = $row['UNIX_TIMESTAMP(timestamp)'];
$version = $row['version'];

// Collect all known versions.
$info = array(
"build" => $build,
"type" => $type,
"date" => strftime('%b %d', $timestamp),
"version" => $version
);
if (in_array($version, $all_versions)) {
$all_versions[$version][] = $info;
}
else {
$all_versions[$version] = array($info);
}

$build_date = $info['date'];
echo("<div class='build $type'>"
."<a href=\"".DENG_API_URL."/builds?number=${build}&format=html\">"
."<div class='buildnumber'>$build</div>"
."<div class='builddate'>$build_date</div>"
."<div class='buildversion'>$version</div></a></div>\n");
}
echo("</div>\n");
$db->close();

echo("<h2>Versions</h2>\n");
foreach ($all_versions as $version => $builds) {
echo("<h3>$version</h3>"
."<div class='buildlist'>\n");
foreach ($builds as $info) {
$type = $info['type'];
$build_date = $info['date'];
$build = $info['build'];
echo("<div class='build $type'>"
."<a href=\"".DENG_API_URL."/builds?number=${build}&format=html\">"
."<div class='buildnumber'>$build</div>"
."<div class='builddate'>$build_date</div>"
."<div class='buildversion'>$version</div></a></div>\n");
}
echo("</div>\n");
}

// Output page footer.
generate_footer();
}

//---------------------------------------------------------------------------------------

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$number = (int) $_GET['number'];
$format = $_GET['format'];
if ($format == 'html') {
if ($number > 0) {
generate_build_page($number);
}
else {
generate_build_index_page();
}
}
else if ($format == 'feed') {
//generate_build_feed();
}
}

0 comments on commit e11d84c

Please sign in to comment.