From 7c5ca9fdcafcec0e3781ed856eba42cd608f0e15 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 30 Jun 2017 20:17:24 +0200 Subject: es6 stuff --- lib/bridge/index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/bridge/index.js (limited to 'lib/bridge') diff --git a/lib/bridge/index.js b/lib/bridge/index.js new file mode 100644 index 0000000..e0ab441 --- /dev/null +++ b/lib/bridge/index.js @@ -0,0 +1,25 @@ +import { execFile } from 'child_process' + +export default class Bridge { + constructor() { + this.cpus = [] + this.getCPUs() + } + getCPUs() { + this.run(['python/devices.py']).then( (stdout, stderr) => { + this.cpus = JSON.parse(stdout) + console.log(this.cpus) + }).catch( (err) => { + console.error('error fetching cpus:', err) + }) + } + run(args) { + return new Promise( (resolve, reject) => { + console.log('>', args.join(' ')) + execFile(process.env.PYTHON_BINARY, args, (err, stdout, stderr) => { + if (err) return reject(err) + return resolve(stdout, stderr) + }) + }) + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2