You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const path = require("path");
|
|
const execBinary = require("../exec-binary");
|
|
const createPegParser = require("../text-parser-pegjs");
|
|
const itemsToObject = require("../items-to-object");
|
|
|
|
/* FIXME: Error handling, eg. device not found errors */
|
|
|
|
function outputParser(parserPath) {
|
|
return createPegParser({
|
|
grammarFile: path.join(__dirname, parserPath)
|
|
});
|
|
}
|
|
|
|
let attributesParser = outputParser("./parsers/commands/attributes.pegjs");
|
|
let infoParser = outputParser("./parsers/commands/info.pegjs");
|
|
let scanParser = outputParser("./parsers/commands/scan.pegjs");
|
|
|
|
module.exports = {
|
|
attributes: function ({ devicePath }) {
|
|
return Promise.try(() => {
|
|
return attributesParser;
|
|
}).then((parser) => {
|
|
return execBinary("smartctl", [devicePath])
|
|
.asRoot()
|
|
.withFlags({ attributes: true })
|
|
.requireOnStdout(parser)
|
|
.execute();
|
|
}).then((output) => {
|
|
// NOTE: Ignore the header, for now
|
|
return output.result.attributes;
|
|
});
|
|
},
|
|
info: function ({ devicePath }) {
|
|
return Promise.try(() => {
|
|
return infoParser;
|
|
}).then((parser) => {
|
|
return execBinary("smartctl", [devicePath])
|
|
.asRoot()
|
|
.withFlags({ info: true })
|
|
.requireOnStdout(parser)
|
|
.execute();
|
|
}).then((output) => {
|
|
// NOTE: Ignore the header, for now
|
|
return itemsToObject(output.result.fields);
|
|
});
|
|
},
|
|
scan: function () {
|
|
return Promise.try(() => {
|
|
return scanParser;
|
|
}).then((parser) => {
|
|
return execBinary("smartctl")
|
|
.asRoot()
|
|
.withFlags({ scan: true })
|
|
.requireOnStdout(parser)
|
|
.execute();
|
|
}).then((output) => {
|
|
// NOTE: Ignore the header, for now
|
|
return output.result.devices;
|
|
});
|
|
}
|
|
};
|