pinokiod 1.1.17 → 1.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/index.js +66 -5
- package/kernel/sysinfo.js +95 -0
- package/kernel/template.js +0 -9
- package/package.json +2 -1
- package/server/index.js +2 -1
package/kernel/index.js
CHANGED
|
@@ -5,12 +5,14 @@ const path = require('path')
|
|
|
5
5
|
const fastq = require('fastq')
|
|
6
6
|
const fetch = require('cross-fetch');
|
|
7
7
|
const system = require('systeminformation');
|
|
8
|
+
const Sysinfo = require('./sysinfo')
|
|
8
9
|
const portfinder = require('portfinder');
|
|
9
10
|
const Loader = require("./loader")
|
|
10
11
|
const Bin = require('./bin')
|
|
11
12
|
const Api = require("./api")
|
|
12
13
|
const Python = require("./python")
|
|
13
|
-
const Template = require('./template')
|
|
14
|
+
//const Template = require('./template')
|
|
15
|
+
const Template = require('jimini')
|
|
14
16
|
const Shells = require("./shells")
|
|
15
17
|
const Key = require("./key")
|
|
16
18
|
const Config = require("./pinokio.json")
|
|
@@ -198,7 +200,7 @@ class Kernel {
|
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
202
|
this.procs = {}
|
|
201
|
-
this.template = new Template(
|
|
203
|
+
this.template = new Template()
|
|
202
204
|
try {
|
|
203
205
|
if (this.homedir) {
|
|
204
206
|
await fs.promises.mkdir(this.homedir, { recursive: true }).catch((e) => {})
|
|
@@ -225,10 +227,40 @@ class Kernel {
|
|
|
225
227
|
// let contents = await fs.promises.readdir(this.homedir)
|
|
226
228
|
await this.bin.init()
|
|
227
229
|
await this.api.init()
|
|
228
|
-
await this.template.init()
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
|
|
232
|
+
let sysinfo = new Sysinfo()
|
|
233
|
+
await sysinfo.init()
|
|
234
|
+
let info = sysinfo.info
|
|
235
|
+
await fs.promises.writeFile(this.path("logs/system.json"), JSON.stringify({
|
|
236
|
+
platform: this.platform,
|
|
237
|
+
arch: this.arch,
|
|
238
|
+
home: this.homedir,
|
|
239
|
+
...info
|
|
240
|
+
}, null, 2))
|
|
241
|
+
this.sysinfo = info
|
|
242
|
+
|
|
243
|
+
await this.template.init({
|
|
244
|
+
kernel: this,
|
|
245
|
+
system,
|
|
246
|
+
platform: this.platform,
|
|
247
|
+
arch: this.arch,
|
|
248
|
+
...info
|
|
249
|
+
})
|
|
250
|
+
if (this.sysinfo_interval) {
|
|
251
|
+
clearInterval(this.sysinfo_interval)
|
|
252
|
+
}
|
|
253
|
+
this.sysinfo_interval = setInterval(async () => {
|
|
254
|
+
await sysinfo.refresh()
|
|
255
|
+
let info = sysinfo.info
|
|
256
|
+
this.template.update(info)
|
|
257
|
+
this.sysinfo = info
|
|
258
|
+
}, 10000) // update every 10 seconds
|
|
259
|
+
|
|
260
|
+
// await this.template.init()
|
|
261
|
+
|
|
262
|
+
this.gpu = info.gpu
|
|
263
|
+
this.gpus = info.gpus
|
|
232
264
|
|
|
233
265
|
// let PuppeteerPath = this.bin.path("puppet", "node_modules", "puppeteer")
|
|
234
266
|
// this.puppet = (await this.loader.load(PuppeteerPath)).resolved
|
|
@@ -240,6 +272,35 @@ class Kernel {
|
|
|
240
272
|
console.log("### ERROR", e)
|
|
241
273
|
}
|
|
242
274
|
}
|
|
275
|
+
async sysinfo() {
|
|
276
|
+
let g = await system.graphics()
|
|
277
|
+
let gpus
|
|
278
|
+
if (g && g.controllers && g.controllers.length > 0) {
|
|
279
|
+
gpus = g.controllers.map((x) => { return x.vendor.toLowerCase() })
|
|
280
|
+
} else {
|
|
281
|
+
gpus = []
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let is_nvidia = gpus.find(gpu => /nvidia/i.test(gpu))
|
|
285
|
+
let is_amd = gpus.find(gpu => /(amd|advanced micro devices)/i.test(gpu))
|
|
286
|
+
let is_apple = gpus.find(gpu => /apple/i.test(gpu))
|
|
287
|
+
|
|
288
|
+
let gpu
|
|
289
|
+
if (is_nvidia) {
|
|
290
|
+
gpu = "nvidia"
|
|
291
|
+
} else if (is_amd) {
|
|
292
|
+
gpu = "amd"
|
|
293
|
+
} else if (is_apple) {
|
|
294
|
+
gpu = "apple"
|
|
295
|
+
} else if (gpus.length > 0) {
|
|
296
|
+
gpu = gpus[0]
|
|
297
|
+
} else {
|
|
298
|
+
gpu = "none"
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return { gpus, gpu }
|
|
302
|
+
|
|
303
|
+
}
|
|
243
304
|
async exec(params, ondata) {
|
|
244
305
|
// params.path = this.path()
|
|
245
306
|
// if (this.client) {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const system = require('systeminformation')
|
|
2
|
+
class Sysinfo {
|
|
3
|
+
async init() {
|
|
4
|
+
this.info = {}
|
|
5
|
+
await this.static()
|
|
6
|
+
await this.refresh()
|
|
7
|
+
}
|
|
8
|
+
async static() {
|
|
9
|
+
await this.gpus()
|
|
10
|
+
await this.system()
|
|
11
|
+
await this.cpu()
|
|
12
|
+
await this.os()
|
|
13
|
+
await this.audio()
|
|
14
|
+
// await this.disk()
|
|
15
|
+
}
|
|
16
|
+
async refresh() {
|
|
17
|
+
await this.time()
|
|
18
|
+
await this.memory()
|
|
19
|
+
await this.battery()
|
|
20
|
+
await this.proc()
|
|
21
|
+
await this.bluetooth()
|
|
22
|
+
// await this.net()
|
|
23
|
+
}
|
|
24
|
+
async gpus() {
|
|
25
|
+
let g = await system.graphics()
|
|
26
|
+
let gpus
|
|
27
|
+
if (g && g.controllers && g.controllers.length > 0) {
|
|
28
|
+
gpus = g.controllers.map((x) => { return x.vendor.toLowerCase() })
|
|
29
|
+
} else {
|
|
30
|
+
gpus = []
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let is_nvidia = gpus.find(gpu => /nvidia/i.test(gpu))
|
|
34
|
+
let is_amd = gpus.find(gpu => /(amd|advanced micro devices)/i.test(gpu))
|
|
35
|
+
let is_apple = gpus.find(gpu => /apple/i.test(gpu))
|
|
36
|
+
|
|
37
|
+
let gpu
|
|
38
|
+
if (is_nvidia) {
|
|
39
|
+
gpu = "nvidia"
|
|
40
|
+
} else if (is_amd) {
|
|
41
|
+
gpu = "amd"
|
|
42
|
+
} else if (is_apple) {
|
|
43
|
+
gpu = "apple"
|
|
44
|
+
} else if (gpus.length > 0) {
|
|
45
|
+
gpu = gpus[0]
|
|
46
|
+
} else {
|
|
47
|
+
gpu = "none"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.info.graphics = g
|
|
51
|
+
this.info.gpus = gpus
|
|
52
|
+
this.info.gpu = gpu
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
async time() {
|
|
56
|
+
this.info.time = await system.time()
|
|
57
|
+
}
|
|
58
|
+
async system() {
|
|
59
|
+
this.info.system = await system.system()
|
|
60
|
+
}
|
|
61
|
+
async cpu() {
|
|
62
|
+
this.info.cpu = await system.cpu()
|
|
63
|
+
}
|
|
64
|
+
async memory() {
|
|
65
|
+
this.info.mem = await system.mem()
|
|
66
|
+
}
|
|
67
|
+
async battery() {
|
|
68
|
+
this.info.battery = await system.battery()
|
|
69
|
+
}
|
|
70
|
+
async os() {
|
|
71
|
+
this.info.osInfo = await system.osInfo()
|
|
72
|
+
this.info.shell = await system.shell()
|
|
73
|
+
}
|
|
74
|
+
async proc() {
|
|
75
|
+
this.info.load = await system.currentLoad()
|
|
76
|
+
}
|
|
77
|
+
async disk() {
|
|
78
|
+
this.info.diskLayout = await system.diskLayout()
|
|
79
|
+
this.info.blockDevices = await system.blockDevices()
|
|
80
|
+
this.info.fsSize = await system.fsSize()
|
|
81
|
+
this.info.usb = await system.usb()
|
|
82
|
+
}
|
|
83
|
+
async audio() {
|
|
84
|
+
this.info.audio = await system.audio()
|
|
85
|
+
}
|
|
86
|
+
async net() {
|
|
87
|
+
this.info.networkConnections = await system.networkConnections()
|
|
88
|
+
this.info.gateway = await system.networkGatewayDefault()
|
|
89
|
+
this.info.interface = await system.networkInterfaces("default")
|
|
90
|
+
}
|
|
91
|
+
async bluetooth() {
|
|
92
|
+
this.info.bluetooth = await system.bluetoothDevices()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
module.exports = Sysinfo
|
package/kernel/template.js
CHANGED
|
@@ -19,10 +19,6 @@ class Template {
|
|
|
19
19
|
}
|
|
20
20
|
this.gpus = gpus
|
|
21
21
|
|
|
22
|
-
console.log("this.gpus", this.gpus)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
22
|
let is_nvidia = gpus.find(gpu => /nvidia/i.test(gpu))
|
|
27
23
|
let is_amd = gpus.find(gpu => /(amd|advanced micro devices)/i.test(gpu))
|
|
28
24
|
let is_apple = gpus.find(gpu => /apple/i.test(gpu))
|
|
@@ -39,8 +35,6 @@ class Template {
|
|
|
39
35
|
this.gpu = "none"
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
console.log({ gpu: this.gpu, gpus: this.gpus })
|
|
43
|
-
|
|
44
38
|
// if (gpus.find((gpu) => { return gpu.includes("nvidia") }) {
|
|
45
39
|
// this.gpu = "nvidia"
|
|
46
40
|
// } else if (gpus.includes("amd") || gpus.includes("advanced micro devices")){
|
|
@@ -119,7 +113,6 @@ class Template {
|
|
|
119
113
|
// CASE 1. String type => can be a regular string or a template string
|
|
120
114
|
if (typeof template === "string") {
|
|
121
115
|
|
|
122
|
-
|
|
123
116
|
if (/^\{\{\{(.+)\}\}\}$/g.test(template)) {
|
|
124
117
|
// CASE 1.0. {{{ }}} raw expression => don't parse
|
|
125
118
|
return template
|
|
@@ -214,9 +207,7 @@ class Template {
|
|
|
214
207
|
raw_get(o, vars) {
|
|
215
208
|
let fun = new Function("uri", "cwd", "key", "local", "global", "self", "input", "current", "next", "event", "_", "os", "path", "system", "pip", "platform", "arch", "gpu", "gpus", "kernel", `return ${o}`)
|
|
216
209
|
try {
|
|
217
|
-
console.log("fun", fun.toString())
|
|
218
210
|
let response = fun(vars.uri, vars.cwd, vars.key, vars.local, vars.global, vars.self, vars.input, vars.current, vars.next, vars.event, _, this.os, path, system, vars.pip, this.platform, this.arch, this.gpu, this.gpus, this.kernel)
|
|
219
|
-
console.log("response", response)
|
|
220
211
|
if (typeof response === "undefined") {
|
|
221
212
|
return `{{${o}}}`
|
|
222
213
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinokiod",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.19",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"http-proxy": "^1.18.1",
|
|
34
34
|
"http-terminator": "^3.2.0",
|
|
35
35
|
"isomorphic-git": "^1.23.0",
|
|
36
|
+
"jimini": "^0.0.2",
|
|
36
37
|
"jsonpath-plus": "^7.2.0",
|
|
37
38
|
"key-store": "^1.2.0",
|
|
38
39
|
"lodash": "^4.17.21",
|
package/server/index.js
CHANGED