pinokiod 1.1.17 → 1.1.18

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 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(this)
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,32 @@ 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
- this.gpu = this.template.gpu
231
- this.gpus = this.template.gpus
231
+
232
+ let sysinfo = new Sysinfo()
233
+ await sysinfo.init()
234
+ let info = sysinfo.info
235
+
236
+ await this.template.init({
237
+ kernel: this,
238
+ system,
239
+ platform: this.platform,
240
+ arch: this.arch,
241
+ ...info
242
+ })
243
+ if (this.sysinfo_interval) {
244
+ clearInterval(this.sysinfo_interval)
245
+ }
246
+ this.sysinfo_interval = setInterval(async () => {
247
+ await sysinfo.refresh()
248
+ let info = sysinfo.info
249
+ this.template.update(info)
250
+ }, 10000) // update every 10 seconds
251
+
252
+ // await this.template.init()
253
+
254
+ this.gpu = info.gpu
255
+ this.gpus = info.gpus
232
256
 
233
257
  // let PuppeteerPath = this.bin.path("puppet", "node_modules", "puppeteer")
234
258
  // this.puppet = (await this.loader.load(PuppeteerPath)).resolved
@@ -240,6 +264,35 @@ class Kernel {
240
264
  console.log("### ERROR", e)
241
265
  }
242
266
  }
267
+ async sysinfo() {
268
+ let g = await system.graphics()
269
+ let gpus
270
+ if (g && g.controllers && g.controllers.length > 0) {
271
+ gpus = g.controllers.map((x) => { return x.vendor.toLowerCase() })
272
+ } else {
273
+ gpus = []
274
+ }
275
+
276
+ let is_nvidia = gpus.find(gpu => /nvidia/i.test(gpu))
277
+ let is_amd = gpus.find(gpu => /(amd|advanced micro devices)/i.test(gpu))
278
+ let is_apple = gpus.find(gpu => /apple/i.test(gpu))
279
+
280
+ let gpu
281
+ if (is_nvidia) {
282
+ gpu = "nvidia"
283
+ } else if (is_amd) {
284
+ gpu = "amd"
285
+ } else if (is_apple) {
286
+ gpu = "apple"
287
+ } else if (gpus.length > 0) {
288
+ gpu = gpus[0]
289
+ } else {
290
+ gpu = "none"
291
+ }
292
+
293
+ return { gpus, gpu }
294
+
295
+ }
243
296
  async exec(params, ondata) {
244
297
  // params.path = this.path()
245
298
  // 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
@@ -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.17",
3
+ "version": "1.1.18",
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",