Replace deprecated awful.util.pread with io.popen

This commit is contained in:
Guillaume Dott 2017-01-23 15:28:02 +01:00
parent e975b5cfff
commit bea3f2784b
2 changed files with 9 additions and 7 deletions

11
mpc.lua
View File

@ -10,7 +10,8 @@ local os = {
}
local io = {
open = io.open,
close = io.close
close = io.close,
popen = io.popen
}
local table = {
insert = table.insert
@ -20,7 +21,7 @@ local tonumber = tonumber
local mpc = {}
function music_current_short()
local music = awful.util.pread('mpc -f "[%artist%]##[%track%]##[%title%]##[%time%]##" | head -2 | sed "s/^\\[\\(playing\\|paused\\)\\] \\+#[0-9]\\+\\/[0-9]\\+ \\+\\([0-9]\\+:[0-9]\\+\\)\\/.*$/\\1#\\2#/" | tr -d "\\n"')
local music = io.popen('mpc -f "[%artist%]##[%track%]##[%title%]##[%time%]##" | head -2 | sed "s/^\\[\\(playing\\|paused\\)\\] \\+#[0-9]\\+\\/[0-9]\\+ \\+\\([0-9]\\+:[0-9]\\+\\)\\/.*$/\\1#\\2#/" | tr -d "\\n"'):read("*a")
--print(music)
local len_max = 20
@ -43,7 +44,7 @@ function music_current_short()
return awful.util.escape(res)
end
function music_current_full()
local music = awful.util.pread("mpc -f \"[%artist%]\\n%album%\\n%track% - %title%\\n## %time%\" | head -4");
local music = io.popen("mpc -f \"[%artist%]\\n%album%\\n%track% - %title%\\n## %time%\" | head -4"):read("*a")
if(string.len(music) == 0) then
music = "Mpd Daemon is not runnig"
@ -55,12 +56,12 @@ function music_current_full()
end
function music_cover()
local cover = os.getenv("HOME") .. "/.album/default.png"
local music = awful.util.pread("mpc -f \"%artist%-%album%\"")
local music = io.popen("mpc -f \"%artist%-%album%\""):read("*a")
--local dir = awful.util.pread("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player \"org.gnome.Rhythmbox.Player.getPlayingUri\"")
--local dir_format = url_decode(dir:sub(8, dir:find("\/[^\/]+$")))
--print(dir_format)
local dir = "/home/gdott9/Music/" .. awful.util.pread("dirname \"`mpc -f '%file%' | head -1`\"")
local dir = "/home/gdott9/Music/" .. io.popen("dirname \"`mpc -f '%file%' | head -1`\""):read("*a")
if(string.len(music) > 0) then
music = string.gsub(string.sub(music, 1, string.len(music)-1), "[/?%*:|\"<>]", "_")

View File

@ -10,6 +10,7 @@ local os = {
execute = os.execute
}
local io = {
popen = io.popen,
open = io.open,
close = io.close
}
@ -48,7 +49,7 @@ function volume_widget.init(a_mode, a_channel)
down = "ossmix " .. channel .. " -- -2"
mute = "ossmix " .. channel .. " 0"
unmute = "ossmix " .. channel .. " "
value = function() return awful.util.pread("ossmix " .. channel):match("(%d+)") end
value = function() return io.popen("ossmix " .. channel):match("(%d+)"):read() end
initialized = true
elseif mode == "alsa" then
@ -57,7 +58,7 @@ function volume_widget.init(a_mode, a_channel)
mute = "amixer sset " .. channel .. " 0"
unmute = "amixer sset " .. channel .. " "
unmute2 = "%"
value = function() return awful.util.pread("amixer get " .. channel):match("(%d+)%%") end
value = function() return io.popen("amixer get " .. channel):read():match("(%d+)%%") end
initialized = true
end