pinokiod 3.6.29 → 3.6.30

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/util.js CHANGED
@@ -14,6 +14,9 @@ const groupReplacement = "$$$";
14
14
  const h = "[^\\S\\r\\n]"; // simulate `\h`
15
15
  const returnPattern = /\r/g;
16
16
  const returnReplacement = "\\r";
17
+ const {
18
+ glob
19
+ } = require('glob')
17
20
 
18
21
 
19
22
  // asar handling for go-get-folder-size
@@ -36,26 +39,20 @@ const du = async (folderpath) => {
36
39
  const is_port_available = async (port) => {
37
40
  return new Promise((resolve) => {
38
41
  const server = http.createServer();
39
- console.log("> Checking port availability", port)
40
42
  try {
41
43
  server.listen(port, (err) => {
42
44
  if (err) {
43
- console.log("> [1 port not available]", err)
44
45
  resolve(false); // Port is occupied
45
46
  } else {
46
- console.log("> [2 port available] test server started. closing test server now.")
47
47
  server.close(() => {
48
- console.log("> Test server closed.")
49
48
  resolve(true); // Port is free
50
49
  }); // Close the server immediately after testing
51
50
  }
52
51
  });
53
52
  server.on('error', (err) => {
54
- console.log("> [3 port not available]", err);
55
53
  resolve(false); // Port is occupied
56
54
  });
57
55
  } catch (e) {
58
- console.log("> [4 port not available]", err)
59
56
  resolve(false) // port not available
60
57
  }
61
58
  });
@@ -199,6 +196,30 @@ const escapeStringRegexp = (string) => {
199
196
  .replace(/-/g, '\\x2d');
200
197
  }
201
198
 
199
+ const find_python = async (root) => {
200
+ let python_pattern
201
+ if (os.platform() === "win32") {
202
+ python_pattern = "**/python.exe";
203
+ } else {
204
+ python_pattern = "**/python"; // Matches python, python3, python3.x
205
+ }
206
+ const pythonBinaries = await glob(python_pattern, { nodir: true, cwd: root });
207
+ return pythonBinaries
208
+ }
209
+ const find_venv = async (root) => {
210
+ let python_pattern
211
+ if (os.platform() === "win32") {
212
+ python_pattern = "**/python.exe";
213
+ } else {
214
+ python_pattern = "**/python"; // Matches python, python3, python3.x
215
+ }
216
+ const pythonBinaries = await glob(python_pattern, { nodir: true, cwd: root, absolute: true });
217
+ const venvs = pythonBinaries.map((p) => {
218
+ return path.resolve(p, "../..")
219
+ })
220
+ return venvs
221
+ }
222
+
202
223
  const update_env = async (filepath, changes) => {
203
224
  const env = await fs.promises.readFile(filepath, "utf8")
204
225
  let append = false;
@@ -236,5 +257,5 @@ const update_env = async (filepath, changes) => {
236
257
  await fs.promises.writeFile(filepath, newval)
237
258
  };
238
259
  module.exports = {
239
- parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_available
260
+ parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_available, find_python, find_venv
240
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.6.29",
3
+ "version": "3.6.30",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/script/index.js CHANGED
@@ -4,6 +4,16 @@ const os = require('os')
4
4
  const platform = os.platform()
5
5
  const Server = require('../server')
6
6
  class Store {
7
+ constructor() {
8
+ let o
9
+ try {
10
+ let str = fs.readFileSync(path.resolve(__dirname, "pinokio.json"), "utf8")
11
+ o = JSON.parse(str)
12
+ } catch(e) {
13
+ o = {}
14
+ }
15
+ this.store = o
16
+ }
7
17
  set(key, val) {
8
18
  let o
9
19
  try {
@@ -13,6 +23,7 @@ class Store {
13
23
  o = {}
14
24
  }
15
25
  o[key] = val
26
+ this.store = o
16
27
  fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
17
28
  }
18
29
  get(key) {
@@ -31,6 +42,7 @@ class Store {
31
42
  console.log("before delete", o)
32
43
  delete o[key]
33
44
  console.log("after delete", o)
45
+ this.store = o
34
46
  fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
35
47
  } catch (e) {
36
48
  }