2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/plugins/storagestat.koplugin/main.lua

57 lines
1.5 KiB
Lua
Raw Normal View History

2017-01-08 09:38:24 +00:00
local Device = require("device")
local filter
-- TODO(Hzj_jie): Find the right filter for PocketBook
if Device:isKobo() or Device:isPocketBook() then
filter = "mmcblk"
elseif Device:isKindle() then
filter = "' /mnt/us$'"
2017-02-16 03:47:45 +00:00
elseif Device:isSDL() then
filter = "/dev/sd"
2017-01-08 09:38:24 +00:00
else
return { disabled = true, }
end
local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local _ = require("gettext")
local StorageStat = WidgetContainer:new{
name = "storagestat",
menuItem = {
2017-01-16 22:05:59 +00:00
text = _("Storage statistics"),
2017-01-08 09:38:24 +00:00
callback = function()
local std_out = io.popen(
"df -h | sed -r 's/ +/ /g' | grep " .. filter ..
2017-02-16 03:47:45 +00:00
" | cut -d ' ' -f 2,3,4,5,6 | " ..
"awk '{print $5\": \\n Available: \" $3\"/\" $1 \"\\n Used: \" $4}'"
2017-01-08 09:38:24 +00:00
)
local msg
if std_out then
msg = std_out:read("*all")
std_out:close()
end
if msg == nil or msg == "" then
msg = _("Failed to retrieve storage information.")
end
UIManager:show(InfoMessage:new{
text = msg,
})
end
}
}
function StorageStat:init()
self.ui.menu:registerToMainMenu(self)
end
function StorageStat:addToMainMenu(menu_items)
2017-03-04 13:51:11 +00:00
menu_items.storage_stat = self.menuItem
2017-01-08 09:38:24 +00:00
end
return StorageStat