From a7f1713cf7f5387d7d85f65fae2d5e1ca3510c59 Mon Sep 17 00:00:00 2001
From: witekfl
Date: Wed, 22 Oct 2008 09:22:15 +0000
Subject: [PATCH] - new versions of buildlogs scripts, not tested at all
---
buildlogs.inc | 26 +
index.php | 826 ++++++++++++++++++++++++++++
pld-buildlogs/scripts/addlog.php | 52 ++
pld-buildlogs/scripts/migration.php | 88 +++
4 files changed, 992 insertions(+)
create mode 100644 buildlogs.inc
create mode 100644 index.php
create mode 100644 pld-buildlogs/scripts/addlog.php
create mode 100644 pld-buildlogs/scripts/migration.php
diff --git a/buildlogs.inc b/buildlogs.inc
new file mode 100644
index 0000000..074c8d7
--- /dev/null
+++ b/buildlogs.inc
@@ -0,0 +1,26 @@
+ "", "arch" => ""),/* must be first */
+ array("dist" => "th, "arch" => "SRPMS"),
+ array("dist" => "th", "arch" => "i486"),
+ array("dist" => "th", "arch" => "i686"),
+ array("dist" => "th", "arch" => "athlon"),
+ array("dist" => "th", "arch" => "x86_64"),
+ array("dist" => "th", "arch" => "alpha"),
+ array("dist" => "th", "arch" => "ppc"),
+ array("dist" => "ac", "arch" => "SRPMS"),
+ array("dist" => "ac", "arch" => "i386"),
+ array("dist" => "ac", "arch" => "i586"),
+ array("dist" => "ac", "arch" => "i686"),
+ array("dist" => "ac", "arch" => "athlon"),
+ array("dist" => "ac", "arch" => "amd64"),
+ array("dist" => "ac", "arch" => "alpha"),
+ array("dist" => "ac", "arch" => "ppc"),
+ array("dist" => "ac", "arch" => "sparc"),
+ array("dist" => "ac", "arch" => "sparc64")
+);
+
+?>
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..5fb3bdc
--- /dev/null
+++ b/index.php
@@ -0,0 +1,826 @@
+\n";
+echo '<' . '?xml-stylesheet href="#internalStyle" type="text/css"?' . ">\n";
+?>
+
+
+
+ PLD Build Logs
+ ' ."\n";?>
+
+
+
+
+".
+ "";
+}
+
+function end_pre()
+{
+ echo " |
\n";
+}
+
+function trailer()
+{
+ echo "";
+}
+
+
+function mydie($msg)
+{
+ echo "Fatal error: $msg";
+}
+
+
+
+function list_logs()
+{
+ global $database;
+ global $arch, $dist, $ok;
+ global $big_url, $ns;
+ global $off, $cnt, $root_directory, $url;
+
+ $big_url = "$url?dist=$dist&arch=$arch&ok=$ok&ns=$ns&cnt=$cnt";
+
+ if ($ok == 1) {
+ echo ""._("Listing of")." $dist/$arch/OK "
+ ."("._("fail").")
\n";
+ } else {
+ echo ""._("Listing of")." $dist/$arch/FAIL "
+ ."("._("ok").")
\n";
+ }
+
+ echo "\n";
+ echo ""._("No.")." | ".
+ ""._("Log File").
+ "["._("sort")."] | ".
+ ""._("Size")." | ".
+ ""._("Age").
+ "["._("sort")."] | ".
+ "
";
+
+ if ($ns != 1) $ns = 0;
+ if (!isset($ok)) $ok = 0;
+// if (!isset($off)) $off = 0;
+// if (!isset($cnt)) $cnt = 50;
+ if ($ns == 0) $order = "mtime DESC";
+ else $order = "name";
+
+ $query = "SELECT log_id, dist, arch, ok, name, mtime, size, id FROM logs WHERE "
+ . "dist = '$dist' AND arch = '$arch' AND ok = $ok ORDER BY $order LIMIT $cnt OFFSET $off";
+
+ try {
+ $dbh = new PDO("$database");
+ } catch (PDOException $e) {
+ mydie("new PDO: " . $e->getMessage());
+ }
+ $now = time();
+ $i = $off;
+ foreach ($dbh->query("$query") as $row) {
+ $f = $row["name"];
+ $t = $now - $row["mtime"];
+ $s = $row["size"];
+ $h = $row["log_id"];
+
+ $t /= 60;
+ if ($t >= 60) {
+ $t /= 60;
+ if ($t >= 24) {
+ $t /= 24;
+ $t = round($t);
+ $t = $t . " " . ngettext("day","days",$t);
+ } else {
+ $t = round($t);
+ $t = $t . " " . ngettext("hour","hours",$t);
+ }
+ } else {
+ $t = round($t);
+ $t = $t . " " . ngettext("minute","minutes",$t);
+ }
+ $u = "$url?dist=$dist&arch=$arch&ok=$ok&name=$name&id=$id";
+ echo "".($i+1).". | ".
+ "$f ".
+ "["._("text")." | ".
+ ""._("tail")."]".
+ " | ".
+ "$s | $t |
\n";
+ $i++;
+ }
+ $count = $i - $off;
+ echo "
\n";
+
+ $backarr = "<<< ";
+ $back = _("Page back");
+ $forward = _("Page forward");
+ $forwardarr = " >>>";
+
+ echo "";
+
+ if ($off > 0) {
+ $noff = $off - $count;
+ if ($noff < 0)
+ $noff = 0;
+ $hrefurl = "";
+ echo "$hrefurl$backarr | $hrefurl$back";
+ } else {
+ echo "$backarr | $back";
+ }
+
+ echo " | \n";
+
+ if (isset($dist) && isset($arch)) {
+ echo "["._("View rpm -qa of builder")."]";
+ } else {
+ echo " ";
+ }
+
+ echo " | \n";
+ if ($cnt == $count) {
+ $noff = $off + $cnt;
+ if ($noff < 0)
+ $noff = 0;
+ $hrefurl = "";
+ echo "$hrefurl$forward | $hrefurl$forwardarr";
+ } else {
+ echo "$forward | $forwardarr";
+ }
+ echo " | \n
";
+}
+
+function file_name()
+{
+ global $ok, $dist, $arch, $name, $id;
+
+ if (isset($name) && isset($ok) && isset($arch) && isset($dist)) {
+ if (isset($id) && $id != '') {
+ $name = $name . ",$id";
+ }
+ $w = $ok ? "OK" : "FAIL";
+ return "$dist/$arch/$w/$name.bz2";
+ }
+}
+
+function dump_log($tail)
+{
+ global $ok, $url, $dist, $arch;
+ global $root_directory, $big_url, $ns, $id, $cnt, $off;
+ global $buildlogs_server;
+
+ $f = file_name();
+
+ if ($f == false)
+ return;
+
+ $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f);
+ $df = preg_replace("/\.(bz2|gz)$/", "", $df);
+
+ echo "$df
";
+
+ echo "";
+
+ function one_item($h, $t) {
+ echo "$h: | ".
+ "$t |
";
+ }
+
+ function href($h, $c) {
+ return "$c";
+ }
+
+ one_item(_("Status"), ($ok == 1 ?
+ ""._("OK")."" :
+ ""._("Failed").""));
+ one_item(_("Source URL"),
+ href("ftp://$buildlogs_server/$f",
+ "ftp://$buildlogs_server/$f"));
+
+ $big_url = "$url?dist=$dist&arch=$arch&ok=$ok&ns=$ns&cnt=$cnt";
+ $bu = "$big_url&off=$off";
+
+ one_item(_("text/plain URL"),
+ href("$bu&id=$id&action=text",
+ _("View!")));
+ if ($tail) {
+ one_item(_("full text"),
+ href("$bu&id=$id",
+ _("View!")));
+ }
+
+ if (isset($dist) && isset($arch)) {
+ one_item(_("rpm -qa of builder"), href("$bu&action=qa", _("View!")));
+ } else {
+ one_item(_("rpm -qa of builder"), _("Not available"));
+ }
+ one_item("Data", date("Y/m/d H:i:s", filemtime("$root_directory/$f")));
+ /*
+ echo "Here: | " .
+ "".
+ "http://" . getenv("SERVER_NAME") .
+ getenv("SCRIPT_NAME") . "?idx=$idx&ok=$ok&id=$id" .
+ " |
"; */
+
+ echo "
"._("Content:")."
";
+
+
+ # what can I say beside PHP suxx? how the fuck should I create
+ # bidirectional pipe? gotta use wget
+
+ if (preg_match("/\.bz2$/", $f)) {
+ $filter = "bzcat";
+ } elseif (preg_match("/\.gz$/", $f)) {
+ $filter = "zcat";
+ } else {
+ $filter = "cat";
+ }
+
+ $cmd = "$filter $root_directory/$f";
+ if ($tail)
+ $cmd = "$cmd | tail -n 100";
+ $fd = popen($cmd, "r");
+ start_pre();
+ while (($s = fgets($fd, 102400)) != false) {
+ if (strlen($s) > 800) {
+ $s = chunk_split($s, 800, "\n ");
+ $s = trim($s);
+ }
+ $s = htmlspecialchars($s);
+ echo $s;
+ }
+ end_pre();
+ pclose($fd);
+
+?>
+
+\n";
+ echo ""._("Failed")." | "._("Ok")." |
\n";
+ for ($i = 1; $i < count($addr); $i++) {
+ $dist = $addr[$i]['dist'];
+ $arch = $addr[$i]['arch'];
+ echo "".
+ "$addr[$i] | ".
+ "[OK] | ".
+ #"[qa] | ".
+ "
\n";
+ }
+ echo "
\n";
+
+ echo "\n";
+
+ # smile ;)
+ echo "";
+ $pow = array("vim", "php", "brain", "power", "electricity",
+ "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF",
+ "voodoo magic", "Linux", "x-files", "X", "foobar",
+ "/dev/null", "/dev/zero", "/dev/drzewo",
+ "Leppe'", "matrix", "Neo", "PDP-11",
+ "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
+ "foobarbaz", "ed", "Joe", "Unix conspiracy",
+ "overclock", "The Right Thing",
+ "The Bad Thing", "Star Treck", "NSA", "NASA",
+ "achelon", "VAX", "Real Programmer",
+ "Real Operating System", "Real Computer",
+ "computron", "bogon", "quantum bogodynamics",
+ "BOFH", "/dev/ill", "nasi tu byli",
+ "Paranoid Android", "Lunatic Corp", "Parallel thinking",
+ "sfistak", "Linus", "The Golden Path", "Dark Side of the Force",
+ "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003", "sqlite3",
+ "synergy"
+ # feel free to add sth if you change this file ;)
+ );
+ echo _("Powered by")." ";
+ $max = 1;
+ for ($i = 0; $i < $max; $i++) {
+ $x = rand(0, count($pow) - 1);
+ if ($pow[$x] == "") $i--;
+ else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
+ $pow[$x] = "";
+ }
+ echo "
";
+
+ if (isset($dist) && isset($arch)) {
+ echo "";
+ }
+}
+
+function get_qa()
+{
+ global $dist, $arch;
+
+ if (!isset($dist) || !isset($arch))
+ return false;
+
+$addr = "http://ftp.pld-linux.org/dists/$dist/.stat/builder/$dist/rpmqa-$arch.txt";
+ return fopen("$addr", "r");
+}
+
+function search_qa()
+{
+ global $url, $str, $dist, $arch;
+
+ $f = get_qa();
+ echo ""._("Search results for")." '$str' "._("in")." $dist/$arch
";
+
+ start_pre();
+
+ if ($f == 0) {
+ echo _("Sorry, cannot open.");
+ } else {
+ while (($s = fgets($f, 1000)) != false) {
+ if (stristr($s, $str))
+ echo $s;
+ }
+ echo "/* EOF */";
+ }
+ end_pre();
+}
+
+function dump_qa($plain)
+{
+ global $url, $dist, $arch;
+
+ $f = get_qa();
+
+ if ($plain) {
+ header("Content-type: text/plain");
+ echo _("# rpm -qa of")." $dist/$arch\n";
+ } else {
+ echo ""._("rpm -qa of")." $a
";
+ echo ""._("text/plain version")."";
+ start_pre();
+ }
+
+ if ($f == 0) {
+ echo _("Sorry, cannot open.");
+ } else {
+ while (($s = fgets($f, 1000)) != false) {
+ echo $s;
+ }
+ }
+
+ if (!$plain)
+ end_pre();
+}
+
+
+function adv_search()
+{
+ global $database, $addr, $fail_or_ok, $url, $_POST, $off, $cnt, $root_directory, $ok, $ns;
+
+ $big_url = "$url?ok=$ok&ns=$ns&cnt=$cnt";
+
+ echo "\n";
+
+/* Shut up warnings */
+ if (!isset($_POST["name"])) $_POST["name"] = "";
+ if (!isset($_POST["age1"])) $_POST["age1"] = "";
+ if (!isset($_POST["age2"])) $_POST["age2"] = "";
+ if (!isset($_POST["size1"])) $_POST["size1"] = "";
+ if (!isset($_POST["size2"])) $_POST["size2"] = "";
+
+ echo "\n";
+}
+
+function welcome()
+{
+?>
+ |
+=_("Welcome!")?>
+=_("Welcome to PLD Build Logs WWW interface.")?>
+=_("Feel free to email bug reports, complaints and feature requests ")?>
+
+=_("to us")?>. =_("Positive opinions are also")?>
+=_("welcome")?> ;)
+Version: $Id: index.php,v 1.7 2007/11/28 12:42:52 witekfl Exp $
+ | |
+
+";
+ list_archs();
+ echo " | ";
+ flush();
+ if ($action == "qa")
+ dump_qa(0);
+ else if ($action == "sqa")
+ search_qa();
+ else if (isset($id) || isset($name))
+ dump_log($action == "tail");
+ else if (isset($dist))
+ list_logs();
+ else
+ welcome();
+ echo " |
";
+ trailer();
+}
+?>
diff --git a/pld-buildlogs/scripts/addlog.php b/pld-buildlogs/scripts/addlog.php
new file mode 100644
index 0000000..319767c
--- /dev/null
+++ b/pld-buildlogs/scripts/addlog.php
@@ -0,0 +1,52 @@
+#!/usr/bin/php.cli
+ 0, "OK" => 1);
+include('buildlogs.inc');
+
+if (!isset($argv[1])) {
+ die("Usage: $argv[0] full_path_to_the_log\n");
+}
+if (!preg_match("|^$root_directory/(.*)/(.*)/(.*)/(.*),?(.*)?\.bz2$|", $argv[1], $matches))
+ exit(0);
+
+$dist = $matches[1];
+$arch = $matches[2];
+$ok = $result[$matches[3]];
+$name = $matches[4];
+if (isset($matches[5]) {
+ $id = $matches[5];
+} else {
+ $id = '';
+}
+$size = filesize($argv[1]);
+$mtime = filemtime($argv[1]);
+
+try {
+ $dbh = new PDO("$database");
+} catch (PDOException $e) {
+ die ($e->getMessage());
+}
+$result = $dbh->query("SELECT log_id FROM logs WHERE dist = '$dist' AND arch = '$arch' AND name = '$name'"
+." AND id = '$id' LIMIT 1")->fetchAll();
+if (count($result) == 1) {
+ foreach ($result as $row) {
+ $query = "UPDATE logs SET ok = $ok, size = $size, mtime = $mtime WHERE log_id = $row[log_id]";
+ break;
+ }
+} else {
+ $query = "INSERT INTO logs(dist, arch, ok, name, size, mtime, id) "
+ . "VALUES('$dist', '$arch', $ok, '$name', $size, $mtime, '$id')";
+}
+$ile = $dbh->exec("$query");
+if ($ile != 1) {
+ print_r($dbh->errorInfo());
+}
+?>
diff --git a/pld-buildlogs/scripts/migration.php b/pld-buildlogs/scripts/migration.php
new file mode 100644
index 0000000..2276ac8
--- /dev/null
+++ b/pld-buildlogs/scripts/migration.php
@@ -0,0 +1,88 @@
+#!/usr/bin/php.cli
+ 1,
+ "th/i486" => 2,
+ "th/i686" => 3,
+ "th/athlon" => 4,
+ "th/x86_64" => 5,
+ "th/ia64" => 6,
+ "th/alpha" => 7,
+ "th/ppc" => 8,
+ "th/sparc" => 9,
+ "ac/SRPMS" => 10,
+ "ac/i386" => 11,
+ "ac/i586" => 12,
+ "ac/i686" => 13,
+ "ac/athlon" => 14,
+ "ac/amd64" => 15,
+ "ac/alpha" => 16,
+ "ac/ppc" => 17,
+ "ac/sparc" => 18,
+ "ac/sparc64" => 19
+);
+*/
+include('buildlogs.inc');
+
+if (file_exists($database_file)) {
+ unlink($database_file);
+}
+
+$query = " CREATE TABLE LOGS(log_id INTEGER PRIMARY KEY, dist TEXT, arch TEXT, ok INTEGER, name TEXT, "
+. "size INTEGER, mtime INTEGER, id TEXT DEFAULT '');";
+try {
+ $dbhandle = new PDO("$database");
+} catch (PDOException $e) {
+ die("new PDO: ". $e->getMessage());
+}
+
+$result = array("FAIL", "OK");
+
+$dh = opendir($root_directory);
+if ($dh) {
+ die("opendir $root_directory");
+}
+while ($dist = readdir($dh)) {
+ if ($dist[0] == '.') continue;
+ if (!is_dir("$root_directory/$dist")) continue;
+ $ah = opendir("$root_directory/$dist");
+ if (!ah) die("opendir $dist");
+ while ($arch = readdir($ah)) {
+ if ($arch[0] == '.') continue;
+ if (!is_dir("$root_directory/$dist/$arch")) continue;
+ for ($ok = 0; $ok < 2; $ok++) {
+ $directory = "$root_directory/$dist/$arch/" . $result[$ok]
+ $sh = opendir($directory);
+ if (!$sh) continue;
+ while ($file = readdir($sh)) {
+ if (preg_match("/^(.*),?(.*)?\.bz2$/", $file, $match)) {
+ $f = "$directory/" . $match[0];
+ $size = filesize($f);
+ $mtime = filemtime($f);
+ $name = $match[1];
+ if (isset($match[2])) {
+ $id = $match[2];
+ } else {
+ $id = "";
+ }
+$query .= " INSERT INTO logs(dist, arch, ok, name, size, mtime, id) "
+. "VALUES('$dist', '$arch', $ok, '$name', $size, $mtime, '$id');";
+ }
+
+ }
+ closedir($sh);
+ }
+ }
+ closedir($ah);
+}
+closedir($dh);
+
+$dbhandle->beginTransaction();
+$dbhandle->exec("$query");
+$dbhandle->commit();
+?>
--
2.44.0