refactoring to avoid 'cat'
This commit is contained in:
parent
a884b5a56d
commit
406bc5860b
@ -57,7 +57,7 @@ module.exports = function (callback) {
|
||||
battery_path = '/sys/class/power_supply/BAT0/';
|
||||
}
|
||||
if (battery_path) {
|
||||
exec('cat ' + battery_path + 'uevent', function (error, stdout) {
|
||||
fs.readFile(battery_path + 'uevent', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
@ -67,7 +67,7 @@ module.exports = function (callback) {
|
||||
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
||||
result.cyclecount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
|
||||
result.maxcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '='), 10) / 1000.0 / (result.voltage || 1));
|
||||
result.designedcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '='), 10) / 1000.0 / (result.voltage || 1))| result.maxcapacity;
|
||||
result.designedcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '='), 10) / 1000.0 / (result.voltage || 1)) | result.maxcapacity;
|
||||
result.currentcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 / (result.voltage || 1));
|
||||
if (!result.maxcapacity) {
|
||||
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10) / 1000.0;
|
||||
@ -100,6 +100,9 @@ module.exports = function (callback) {
|
||||
result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@ -780,7 +780,7 @@ function cpuTemperature(callback) {
|
||||
} else {
|
||||
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
|
||||
if (err === null) {
|
||||
exec('cat /sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
|
||||
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0) {
|
||||
@ -928,7 +928,7 @@ function cpuFlags(callback) {
|
||||
});
|
||||
}
|
||||
if (!result) {
|
||||
exec('cat /proc/cpuinfo', function (error, stdout) {
|
||||
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
result = util.getValue(lines, 'features', ':', true).toLowerCase();
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
@ -159,8 +160,7 @@ function fsOpenFiles(callback) {
|
||||
});
|
||||
}
|
||||
if (_linux) {
|
||||
let cmd = 'cat /proc/sys/fs/file-nr';
|
||||
exec(cmd, function (error, stdout) {
|
||||
fs.readFile('/proc/sys/fs/file-nr', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines[0]) {
|
||||
|
||||
@ -17,6 +17,7 @@ const os = require('os');
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
@ -143,7 +144,7 @@ function mem(callback) {
|
||||
};
|
||||
|
||||
if (_linux) {
|
||||
exec('export LC_ALL=C; cat /proc/meminfo 2>/dev/null ; unset LC_ALL', function (error, stdout) {
|
||||
fs.readFile('/proc/meminfo', function (error, stdout) {
|
||||
if (!error) {
|
||||
const lines = stdout.toString().split('\n');
|
||||
result.total = parseInt(util.getValue(lines, 'memtotal'), 10);
|
||||
|
||||
@ -88,7 +88,7 @@ function system(callback) {
|
||||
|
||||
if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') {
|
||||
// Check Raspberry Pi
|
||||
exec('cat /proc/cpuinfo', function (error, stdout) {
|
||||
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
result.model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user