summaryrefslogtreecommitdiffstats
path: root/index.php
blob: 4e5d7dff00f551adaaab98a0d19bd4d03cc7a2f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php

/* Copyright (C) 2011 Oliver Blin                                         *\
/**************************************************************************\
* This program is free software; you can redistribute it and/or modify it  *
* under the terms of the GNU General Public License aspublished by the     *
* Free Software Foundation; either version 2 of the License, or (at your   *
* option) any later version.                                               *
\**************************************************************************/

error_reporting(E_ALL);

$upload_dir = "/home/schedbot/uploads";
$max_modified = 2;
$title = "Mageia build system status";
$tz = new DateTimeZone("UTC");

# Temporary until initial mirror is ready
chdir("data");
$nb_rpm = shell_exec('rpm -qp --qf "%{SOURCERPM}\n" /distrib/bootstrap/distrib/cauldron/i586/media/core/release/*.rpm | sort -u | tee src.txt | wc -l');
$nb_rpm_mga = shell_exec('grep mga src.txt | tee src.mga.txt | wc -l');
shell_exec('grep -v mga src.txt > src.mdv.txt');
#########################################

chdir($upload_dir);

$all_files = shell_exec("find \( -name '*.rpm' -o -name '*.src.rpm.info' -o -name '*.youri' -o -name '*.lock' -o -name '*.done' \) ! -ctime $max_modified");

preg_match_all("!^\./(\w+)/((\w+)/(\w+)/(\w+)/(\d+)\.(\w+)\.(\w+)\.(\d+))_?(.+)(\.src\.rpm(?:\.info)?|\.youri|\.lock|\.done)$!m", $all_files, $matches, PREG_SET_ORDER);

$pkgs = array();
foreach ($matches as $val) {
    if ($_GET["user"] && ($_GET["user"] != $val[7])) {
		continue;
    }
    $key = $val[6] . $val[7];
    if (!is_array($pkgs[$key])) {
        $pkgs[$key] = array();
        $pkgs[$key]["status"]  = array();
	$pkgs[$key]["path"]    = $val[2];
	$pkgs[$key]["version"] = $val[3];
        $pkgs[$key]["media"]   = $val[4];
        $pkgs[$key]["section"] = $val[5];
        $pkgs[$key]["user"]    = $val[7];
        $pkgs[$key]["host"]    = $val[8];
        $pkgs[$key]["job"]     = $val[9];
    }

    $status = $val[1];
    $data = $val[10];
    $pkgs[$key]["status"][$status] = 1;
    $ext = $val[11];
    if ($ext == ".src.rpm.info") {
        preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
        $pkgs[$key]["package"] = $name[1];
    } else if ($ext == ".src") {
        $pkgs[$key]["status"]["src"] = 1;
    } else if ($ext == ".youri") {
        $pkgs[$key]["status"]["youri"] = 1;
    } else if ($ext == ".lock") {
        // parse build bot from $data
        $pkgs[$key]["status"]["build"] = 1;
    }
}
// sort by key in reverse order to have more recent pkgs first
krsort($pkgs);
?>
<html>

<head>
<title><? echo $title ?></title>
<style type="text/css">
table { 
    border-spacing: 0;
    font-family: Helvetica; font-size: 80%;
    border: 1px solid #ccc;
}
table tr { padding: 0; margin: 0; }
table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
 
tr { background: transparent; }
tr.uploaded { background: #ddffdd; }
tr.failure, tr.rejected { background: #ffdddd; }
tr.todo { background: white; }
tr.building { background: #ffffdd; }
tr.partial { background: #aaaaff; }
tr.built { background: #00CCFF; }
tr.youri { background: olive; }
 
td.status-box { width: 1em; height: 1em; }
tr.uploaded td.status-box { background: green; }
tr.failure td.status-box, tr.rejected td.status-box { background: red; }
tr.todo td.status-box { background: white; }
tr.building td.status-box { background: yellow; }
tr.partial td.status-box { background: blue; }
tr.built td.status-box { background: #00CCFF; }
tr.youri td.status-box { background: olive; }
 
</style>
</head>

<body>
<h1><? echo $title ?></h1>

<table>
<?
function pkg_gettype($pkg) {
    if (array_key_exists("rejected", $pkg["status"]))
        return "rejected";
    if (array_key_exists("youri",    $pkg["status"])) {
        if (array_key_exists("src",    $pkg["status"]))
	    return "youri";
	else
	    return "uploaded";
    }
    if (array_key_exists("failure",  $pkg["status"]))
        return "failure";
    if (array_key_exists("done",     $pkg["status"]))
        return "partial";
    if (array_key_exists("build",    $pkg["status"]))
        return "building";
    if (array_key_exists("todo",     $pkg["status"]))
        return "todo";
    return "unknown";
}

function plural($num) {
    if ($num > 1)
        return "s";
}

function key2date($key) {
    global $tz;    
    $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
    $diff = time() - $date->getTimestamp();
    if ($diff<60)
       return $diff . " second" . plural($diff) . " ago";
    $diff = round($diff/60);
    if ($diff<60)
       return $diff . " minute" . plural($diff) . " ago";
    $diff = round($diff/60);
    if ($diff<24)
       return $diff . " hour" . plural($diff) . " ago";
    $diff = round($diff/24);
    return $diff . " day" . plural($diff) . " ago";
}

# Temporary until initial mirror is ready
echo "<a href=\"data/src.mga.txt\">$nb_rpm_mga src.rpm</a> rebuilt for Mageia out of <a href=\"data/src.txt\">$nb_rpm</a>. <a href=\"data/src.mdv.txt\">List of Mandriva packages still present</a>.<br/>\n";
#########################################

echo "<tr><th>Submitted</th><th>User</th><th>Package</th><th>Target</th><th>Media</th><th colspan=\"2\">Status</th></tr>\n";
foreach ($pkgs as $key => $p) {
    $p["type"] = pkg_gettype(&$p);
    echo "<tr class=" . $p["type"] . ">\n";
    echo "<td>" . key2date($key) . "</td>\n";
    echo "<td><a href='?user=" . $p["user"] . "'>" . $p["user"] . "</a></td>\n";
    echo "<td>" . $p["package"] . "</td>\n";
    echo "<td>" . $p["version"] . "</td>\n";
    echo "<td>" . $p["media"] . "/" . $p["section"] . "</td>\n";
    echo "<td class='status-box' />\n";
    $typelink = "";
    if ($p["type"] == "failure") {
       $typelink = "/uploads/" . $p["type"] . "/" . $p["path"];
    } else if ($p["type"] == "rejected") {
       $typelink = "/uploads/" . $p["type"] . "/" . $p["path"] . ".youri";
    }
    echo "<td>";
    if ($typelink)
        echo "<a href='$typelink'>";
    echo $p["type"];
    if ($typelink)
        echo "</a>";
    echo "</td>\n";
    echo "</tr>\n";
}
?>
</table>

</body>

</html>