-
Notifications
You must be signed in to change notification settings - Fork 0
/
builds.php
250 lines (217 loc) · 5.79 KB
/
builds.php
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* Nightly builds page is built dynamically by reading the contents
* of the /builds directory
*/
/**
* Parsing directories in sorted order using provided callback function
*/
class SortingIterator extends ArrayIterator {
public function __construct( Traversable $iterator, $callback ) {
parent::__construct( iterator_to_array( $iterator ) );
$this->uasort( $callback );
}
}
/**
* Retrieves the list of builds from the specified path
* @param string $p_path
* @param array $p_builds
* @param SplFileInfo $p_logfile
* @return bool false in case of errors
*/
function get_builds_list( $p_path, &$p_builds, &$p_logfile ) {
# Error handling in case the path does not exist
if( !is_dir( $p_path ) ) {
echo "ERROR: path '$p_path' not found\n";
return false;
}
# Loop over parent directories (channels)
$t_iter_builds = new SortingIterator(
new FileSystemIterator( $p_path ),
'strcmp'
);
$p_path = '/' . basename( $p_path ) . '/';
$p_builds = array();
foreach( $t_iter_builds as $t_file ) {
if( $t_file->isDir() ) {
continue;
}
$t_file_url = $p_path . $t_file->getFilename();
# mantisbt.org is on PHP 5.3.2 and SplFileInfo:: getExtension
# was only introduced in 5.3.6, so, until we upgrade the server...
# if( $t_file->getExtension() == 'log' ) {
if( substr( $t_file, -3, 3 ) == 'log' ) {
$p_logfile = array(
'file' => $t_file_url,
'time' => $t_file->getMTime()
);
} else {
# Break down filename into components
$t_result = preg_match(
'/^mantisbt-((?U).*)-(.*)-((?U).*)\.((?U).*)(?:\.)?(digests)?$/',
$t_file->getFileName(),
$t_match
);
if( $t_result != 1 ) {
continue;
}
$t_sha = $t_match[3];
$t_ext = $t_match[4];
# Build details
$p_builds[$t_sha]['branch'] = $t_match[2];
$p_builds[$t_sha]['version'] = $t_match[1];
# Digest and zip/tarball file names
if( isset( $t_match[5] ) ) {
$p_builds[$t_sha][$t_ext]['digests'] = $t_file_url;
} else {
$p_builds[$t_sha][$t_ext]['file'] = $t_file_url;
$p_builds[$t_sha][$t_ext]['time'] = $t_file->getMTime();
}
}
}
return true;
}
/**
* Prints timestamp in YYYY-MM-DD HH:mm:ss format
*/
function print_timestamp( $p_time ) {
return date( 'Y-m-d H:i:s', $p_time );
}
/**
* Prints download links and timestamp for the file
*/
function print_file_details( $p_type, $p_file ) {
if( is_null( $p_file ) || !isset( $p_file['file'] ) ) {
return '
<td class="table-cell center">Unavailable</td>';
} else {
return sprintf( '
<td class="table-cell center">
<a href="%s"><img src="images/zip.gif" alt="%s"> Download</a>
(%s)
<br />
%s
</td>',
$p_file['file'], $p_type,
isset( $p_file['digests'] )
? sprintf( '<a href="%s">digests</a>', $p_file['digests'] )
: 'no digest',
print_timestamp( $p_file['time'] )
);
}
}
/**
* Prints the Travis-CI status icon for the given branch
* @param string $p_branch Branch name
*/
function print_travis_status( $p_branch ) {
return sprintf( '
<a href="https://travis-ci.org/mantisbt/mantisbt/builds">
<img src="https://travis-ci.org/mantisbt/mantisbt.png?branch=%s" />
</a>',
$p_branch
);
}
/**
* Prints the table with the builds
* @param array $p_builds
*/
function print_builds_list( $p_builds ) {
# printf formats
$t_fmt_sha_link = '
<a href="http://www.mantisbt.org/bugs/plugin.php?page=Source%%2Fsearch&revision=%1$s">%1$s</a>';
$t_fmt_branch = '
<td rowspan="%d" class="table-cell">
%s
<br />%s
</td>';
$t_fmt_build_row = '
<tr class="table-row">%s
<td class="table-cell center">%s
</td>
%s
%s
</tr>' . "\n";
# Count number of builds available for each branch
foreach( $p_builds as $t_build ) {
$t_branch = $t_build['branch'];
if( isset( $t_build_count[$t_branch] ) ) {
$t_build_count[$t_branch]++;
} else {
$t_build_count[$t_branch] = 1;
}
}
# Table header
echo ' <!-- Downloads table -->
<table class="table" style="padding: 2px;">
<thead class="table-header">
<tr class="table-row">
<th class="table-cell" style="text-align: left;">Branch (Release)</th>
<th class="table-cell">Commit</th>
<th class="table-cell">Tarballs</th>
<th class="table-cell">Zipballs</th>
</tr>
</thead>
<tbody>';
# Table body
$t_branch = null;
foreach( $p_builds as $t_sha => $t_build ) {
if( $t_branch != $t_build['branch'] ) {
$t_branch = $t_build['branch'];
$t_current = sprintf(
$t_fmt_branch,
$t_build_count[$t_branch],
sprintf(
'%1$s<br />(%2$s)',
$t_build['branch'],
$t_build['version']
),
print_travis_status( $t_branch )
);
} else {
$t_current = '';
}
printf(
$t_fmt_build_row,
$t_current,
sprintf( $t_fmt_sha_link, $t_sha),
print_file_details( 'tarball', isset( $t_build['tar.gz'] ) ? $t_build['tar.gz'] : null),
print_file_details( 'zipball', isset( $t_build['zip'] ) ? $t_build['zip'] : null)
);
}
echo '
</tbody>
</table>
<br />';
}
/**
* Main body
*/
# Page header
$t_sub_title = "Nightly Builds";
include( "top.php" );
# Root of builds - try in current dir and one level above if not found
$t_dir = 'builds';
$t_path_root = rtrim( $_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
$t_path = realpath( $t_path_root . $t_dir );
if( false === $t_path ) {
$t_path = realpath( $t_path_root . '..' . DIRECTORY_SEPARATOR . $t_dir );
}
if( false === $t_path ) {
$t_path = $t_dir;
}
if( get_builds_list( $t_path, $t_builds, $t_logfile ) ) {
?>
<h4>Nightly Builds Downloads</h4>
<?php
print_builds_list( $t_builds );
?>
<div>
View the Nightly Builds script's
<a href="<?php echo $t_logfile['file']; ?>">Log File</a>
(<?php echo print_timestamp( $t_logfile['time'] ); ?>).
<p>All times on this page are <?php echo date('T (\U\TCP)') ?>.</p>
</div>
<?php
}
include( "bot.php" );