diff --git a/utils/system/info.lua b/utils/system/info.lua new file mode 100644 index 0000000..c9cd70c --- /dev/null +++ b/utils/system/info.lua @@ -0,0 +1,38 @@ +require("yaci") +require("strict") +local pp = require("pp") +local glue = require("glue") + +CSystemInfo = newclass("CSystemInfo") + +function CSystemInfo:print(...) + if self.is_debug then + local t = glue.pack(...) + for i, v in ipairs(t) do + t[i] = pp.format(v) + end + print(glue.unpack(t)) + end +end + +function CSystemInfo:init(is_debug) + self.is_debug = false + + if type(is_debug) == "boolean" then + self.is_debug = is_debug + end + self:print("intialize CSystemInfo object") +end + +function CSystemInfo:exec_cmd(cmd, raw) + self:print("cmd to exec: " .. tostring(cmd)) + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + self:print("cmd output: " .. tostring(s)) + if raw or raw == nil then return s end + s = string.gsub(s, '^%s+', '') + s = string.gsub(s, '%s+$', '') + s = string.gsub(s, '[\n\r]+', ' ') + return s +end diff --git a/utils/system/init.lua b/utils/system/init.lua new file mode 100644 index 0000000..257c9d4 --- /dev/null +++ b/utils/system/init.lua @@ -0,0 +1 @@ +require("system.info")