|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// This file is part of BOINC. |
|
4
|
|
|
// https://boinc.berkeley.edu |
|
5
|
|
|
// Copyright (C) 2024 University of California |
|
6
|
|
|
// |
|
7
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
|
8
|
|
|
// under the terms of the GNU Lesser General Public License |
|
9
|
|
|
// as published by the Free Software Foundation, |
|
10
|
|
|
// either version 3 of the License, or (at your option) any later version. |
|
11
|
|
|
// |
|
12
|
|
|
// BOINC is distributed in the hope that it will be useful, |
|
13
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
15
|
|
|
// See the GNU Lesser General Public License for more details. |
|
16
|
|
|
// |
|
17
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
|
18
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
|
|
20
|
|
|
// get output files, individually or zipped groups |
|
21
|
|
|
// |
|
22
|
|
|
// args: |
|
23
|
|
|
// action: get_file or get_batch |
|
24
|
|
|
// get_file: |
|
25
|
|
|
// path: relative to project root dir |
|
26
|
|
|
// download: if set, download file; else show it in browser |
|
27
|
|
|
// get_batch: |
|
28
|
|
|
// batch_id |
|
29
|
|
|
// downloads zip of batch's output files |
|
30
|
|
|
// Assumes the layout used by sample_assimilator.cpp |
|
31
|
|
|
// and sample_assimilate.py: |
|
32
|
|
|
// <project>/results/ |
|
33
|
|
|
// <batchid>/ (0 if not in a batch) |
|
34
|
|
|
// |
|
35
|
|
|
|
|
36
|
|
|
require_once("../inc/util.inc"); |
|
37
|
|
|
require_once("../inc/submit_util.inc"); |
|
38
|
|
|
|
|
39
|
|
|
// the path of an output file in the 'assim move' scheme. |
|
40
|
|
|
// This must agree with the corresponding assimilators: |
|
41
|
|
|
// tools/sample_assimilate.py |
|
42
|
|
|
// sched/sample_assimilator.cpp |
|
43
|
|
|
// and with tools/query_job |
|
44
|
|
|
// |
|
45
|
|
|
function outfile_path($wu, $index, $log_names) { |
|
46
|
|
|
return sprintf('results/%d/%s__file_%s', |
|
47
|
|
|
$wu->batch, $wu->name, $log_names[$index] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// show or download a single output file, |
|
52
|
|
|
// identified by result ID and file index |
|
53
|
|
|
// |
|
54
|
|
|
function get_file() { |
|
55
|
|
|
$result_id = get_int('result_id'); |
|
56
|
|
|
$index = get_int('index'); |
|
57
|
|
|
$result = BoincResult::lookup_id($result_id); |
|
58
|
|
|
if (!$result) error_page('no result'); |
|
59
|
|
|
$wu = BoincWorkunit::lookup_id($result->workunitid); |
|
60
|
|
|
if (!$wu) error_page('no workunit'); |
|
61
|
|
|
$log_names = get_outfile_log_names($result); |
|
62
|
|
|
if ($index >= count($log_names)) error_page('bad index'); |
|
63
|
|
|
$path = sprintf('../../%s', outfile_path($wu, $index, $log_names)); |
|
64
|
|
|
|
|
65
|
|
|
if (get_str('download', true)) { |
|
66
|
|
|
do_download($path); |
|
67
|
|
|
} else { |
|
68
|
|
|
echo "<pre>\n"; |
|
69
|
|
|
echo htmlspecialchars(file_get_contents($path)); |
|
70
|
|
|
echo "</pre>\n"; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// download a zip of the given directory |
|
75
|
|
|
// |
|
76
|
|
|
function get_batch() { |
|
77
|
|
|
$batch_id = get_int('batch_id'); |
|
78
|
|
|
$dir = "../../results/$batch_id"; |
|
79
|
|
|
if (!is_dir($dir)) die('no batch dir'); |
|
|
|
|
|
|
80
|
|
|
$name = "batch_$batch_id.zip"; |
|
81
|
|
|
$cmd = "cd $dir; rm -f $name; zip -q $name *"; |
|
82
|
|
|
system($cmd); |
|
83
|
|
|
do_download("$dir/$name"); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$action = get_str('action'); |
|
87
|
|
|
switch ($action) { |
|
88
|
|
|
case 'get_file': get_file(); break; |
|
|
|
|
|
|
89
|
|
|
case 'get_batch': get_batch(); break; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
?> |
|
93
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.