-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.php
131 lines (115 loc) · 3.95 KB
/
new.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
<?php
// Copyright (C) 2015 xaizek <xaizek@posteo.net>
//
// fragile is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free
// Software Foundation, version 3.
//
// fragile 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 Affero General Public License for more
// details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
require_once __DIR__ . '/classes/Build.php';
require_once __DIR__ . '/classes/Buildset.php';
require_once __DIR__ . '/classes/Utils.php';
require_once __DIR__ . '/config.php';
if (sizeof($argv) < 3) {
print "Usage: ${argv[0]} name revision [builder-name..]\n";
die("Wrong invocation\n");
}
$name = $argv[1];
$revision = $argv[2];
$builders = array_slice($argv, 3);
if (substr($name, 0, strlen('fragile-do/')) === 'fragile-do/') {
$command = substr($name, strlen('fragile-do/'));
$pieces = explode('%', $command);
switch ($pieces[0]) {
case 'clean':
// XXX: ideally, this would only schedule the operation for the
// daemon; currently, we can change FS in parallel with it
Utils::delTree(BUILDS_PATH);
exit("Cleaned ".BUILDS_PATH);
case 'repeat':
if (sizeof($pieces) != 2) {
die('repeat command expects an argument');
}
$buildset = Buildset::get($pieces[1]);
if ($buildset === null) {
die("repeat command expects a valid buildset id as an ".
"argument\ngot: ${pieces[1]}");
}
$name = $buildset->name;
$revision = $buildset->revision;
$builders = [];
print "Repeating $name@$revision from #{$pieces[1]}\n";
break;
default:
exit("Unknown command: $command");
}
}
$buildset = Buildset::create($name, $revision);
if (!empty($builders)) {
$builders = pickBuilders(BUILDERS_PATH, $builders);
} else {
$builders = pickBuildersIn(BUILDERS_PATH, '');
$builders = array_merge($builders, pickBuildersIn(BUILDERS_PATH, "$name/"));
}
foreach ($builders as $builderName) {
Build::create($buildset, $builderName);
}
print "Buildset ID: $buildset->buildsetid\n";
if (sizeof($builders) == 0) {
print "No builders were scheduled\n";
} else {
print "Scheduled " . sizeof($builders) . " builder"
. (sizeof($builders) == 1 ? '' : 's')
. ": " . join(', ', $builders) . "\n";
}
/**
* @brief Schedules builders in @p dir directory specified by their name.
*
* @param dir Directory to look for builders.
* @param names List of builder names (appended to @p dir by one).
*
* @returns Array of names of builders to schedule.
*/
function pickBuilders($dir, $names)
{
$builders = [];
foreach ($names as $name) {
$path = "$dir/$name";
if (!is_dir($path) && is_executable($path)) {
array_push($builders, $name);
}
}
return $builders;
}
/**
* @brief Schedules builders discovered in @p dir directory.
*
* @param dir Directory to look for builders.
* @param suffix Additional suffix for builders path (appended to @p dir).
*
* @returns Array of names of builders to schedule.
*/
function pickBuildersIn($dir, $suffix)
{
$builders = [];
$basePath = "$dir/$suffix";
if (is_dir($basePath) && $handle = opendir($basePath)) {
while (($entry = readdir($handle)) !== false) {
$path = "$basePath/$entry";
if (!is_dir($path) && $entry != '.' && $entry != '..' &&
is_executable($path)) {
$builderName = "$suffix$entry";
array_push($builders, $builderName);
}
}
closedir($handle);
}
return $builders;
}
?>