|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
$buda_root = "../../buda_apps"; |
|
4
|
|
|
|
|
5
|
|
|
function get_buda_apps() { |
|
6
|
|
|
global $buda_root; |
|
7
|
|
|
$apps = []; |
|
8
|
|
|
$x = scandir($buda_root); |
|
9
|
|
|
foreach ($x as $app) { |
|
10
|
|
|
if ($app[0] == '.') continue; |
|
11
|
|
|
if (!is_dir("$buda_root/$app")) continue; |
|
12
|
|
|
$apps[] = $app; |
|
13
|
|
|
} |
|
14
|
|
|
return $apps; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
// return list of variant dir names |
|
18
|
|
|
// |
|
19
|
|
|
function get_buda_variants($app_name) { |
|
20
|
|
|
global $buda_root; |
|
21
|
|
|
$x = []; |
|
22
|
|
|
$app_dir = "$buda_root/$app_name"; |
|
23
|
|
|
$dirs = scandir($app_dir); |
|
24
|
|
|
foreach ($dirs as $dir) { |
|
25
|
|
|
if ($dir[0] == '.') continue; |
|
26
|
|
|
if (!is_dir("$app_dir/$dir")) continue; |
|
27
|
|
|
if (!file_exists("$app_dir/$dir/variant.json")) continue; |
|
28
|
|
|
$x[] = $dir; |
|
29
|
|
|
} |
|
30
|
|
|
return $x; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function get_buda_app_desc($app) { |
|
34
|
|
|
global $buda_root; |
|
35
|
|
|
$path = "$buda_root/$app/desc.json"; |
|
36
|
|
|
return json_decode(file_get_contents($path)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function get_buda_var_desc($app, $var) { |
|
40
|
|
|
global $buda_root; |
|
41
|
|
|
$path = "$buda_root/$app/$var/variant.json"; |
|
42
|
|
|
return json_decode(file_get_contents($path)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function variant_name($desc) { |
|
46
|
|
|
if ($desc->plan_class) { |
|
47
|
|
|
return "$desc->cpu_type ($desc->plan_class)"; |
|
48
|
|
|
} else { |
|
49
|
|
|
return "$desc->cpu_type (CPU)"; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// can user submit job to BUDA app? |
|
54
|
|
|
// |
|
55
|
|
|
function user_can_submit($user, $app_desc) { |
|
56
|
|
|
if ($app_desc->user_id == $user->id) { |
|
57
|
|
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
if (!empty($app_desc->submitters) |
|
60
|
|
|
&& in_array($user->id, $app_desc->submitters) |
|
61
|
|
|
) { |
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// can user edit app or variants? |
|
68
|
|
|
// |
|
69
|
|
|
function user_can_manage($user, $app_desc) { |
|
70
|
|
|
if ($app_desc->user_id == $user->id) { |
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
?> |
|
77
|
|
|
|