Passed
Pull Request — master (#6667)
by David
18:09 queued 07:13
created

make_vbox()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 5
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
// This file is part of BOINC.
3
// https://boinc.berkeley.edu
4
// Copyright (C) 2025 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19
// Convert miscellaneous host info from old format to JSON
20
// Should have to run this just once.
21
22
require_once('../inc/boinc_db.inc');
23
require_once('../inc/host.inc');
24
25
function make_gpu($type, $x) {
26
    $g = new StdClass();
27
    $g->type = $type;
28
    $g->model = $x[1];
29
    if (!empty($x[2])) {
30
        $g->count = intval($x[2]);
31
    }
32
    if (!empty($x[3])) {
33
        $g->ram_mb = intval($x[3]);
34
    }
35
    if (!empty($x[4])) {
36
        $g->driver_version = $x[4];
37
    }
38
    if (!empty($x[5])) {
39
        $g->opencl_version = $x[5];
40
    }
41
    return $g;
42
}
43
44
function make_vbox($x) {
45
    $v = new StdClass;
46
    $v->version = $x[1];
47
    if (count($x) >= 4) {
48
        $v->hw_accel = $x[2]?true:false;
49
        $v->hw_accel_enabled = $x[3]?true:false;
50
    }
51
    return $v;
52
}
53
54
function make_docker($x) {
55
    $d = new StdClass;
56
    $d->version = $x[1];
57
    $d->type = intval($x[2]);
58
    return $d;
59
}
60
61
function to_struct($p) {
62
    $s = new StdClass;
63
    $gpus = [];
64
    $config = [];
65
    foreach ($p as $x) {
66
        switch ($x[0]) {
67
        case 'BOINC':
68
            $s->client_version = $x[1];
69
            if (!empty($x[2])) {
70
                $s->client_brand = $x[2];
71
            }
72
            break;
73
        case 'CUDA':
74
            $g = make_gpu('nvidia', $x);
75
            if ($g) $gpus[] = $g;
76
            break;
77
        case 'CAL':
78
            $g = make_gpu('amd', $x);
79
            if ($g) $gpus[] = $g;
80
            break;
81
        case 'INTEL':
82
            $g = make_gpu('intel', $x);
83
            if ($g) $gpus[] = $g;
84
            break;
85
        case 'apple_gpu':
86
            $g = make_gpu('apple', $x);
87
            if ($g) $gpus[] = $g;
88
            break;
89
        case 'opencl_gpu':
90
            if (stristr($x[1], 'apple')) {
91
                break;
92
            }
93
            if (stristr($x[1], 'amd')) {
94
                break;
95
            }
96
            $g = make_gpu('opencl', $x);
97
            if ($g) $gpus[] = $g;
98
            break;
99
        case 'vbox':
100
            $s->vbox = make_vbox($x);
101
            break;
102
        case 'docker':
103
            $s->docker = make_docker($x);
104
            break;
105
        case 'dont_use_docker':
106
            $config['dont_use_docker'] = true;
107
            break;
108
        case 'dont_use_wsl':
109
            $config['dont_use_wsl'] = true;
110
            break;
111
        default:
0 ignored issues
show
Coding Style introduced by
DEFAULT keyword must be indented 4 spaces from SWITCH keyword
Loading history...
112
            echo "unrecognized: ".$x[0]."\n";
113
            continue;
114
        }
115
    }
116
    if ($gpus) $s->gpus = $gpus;
117
    if ($config) $s->config = $config;
118
    return $s;
119
}
120
121
function main() {
122
    $hosts = BoincHost::enum("serialnum<>''", '');
123
    foreach ($hosts as $h) {
124
        //echo "$h->serialnum\n";
125
        $p = parse_serialnum($h->serialnum);
126
        //print_r($p);
127
        $s = to_struct($p);
128
        //print_r($s);
129
        $s = json_encode($s, JSON_PRETTY_PRINT);
130
        $s = BoincDb::escape_string($s);
131
        $h->update("misc='$s'");
132
        echo "$h->id\n";
133
    }
134
}
135
136
main();
137
138
?>
139