From e4fcdb2458635ca3c034fcd2df129f53d9e154e5 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Thu, 24 Oct 2024 13:28:18 +1000 Subject: Some more tidying up. --- _.lua | 71 ++++++++++++++++++-------------------------------------------- aataaj.lua | 59 --------------------------------------------------- test_.lua | 38 +++++++++------------------------ 3 files changed, 30 insertions(+), 138 deletions(-) diff --git a/_.lua b/_.lua index f5ab5b9..33b4183 100755 --- a/_.lua +++ b/_.lua @@ -45,7 +45,7 @@ _.parseArgs = function(options, args) if nil == o then local h = '' for k, v in pairs(options) do - h = h .. k .. '|' + h = h .. k .. ' | ' end print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') os.exit(0) @@ -62,9 +62,10 @@ end _.exists = function(f) local h, e = io.open(f, "r") - if nil == h then return false else h:close(); return true end + if nil == h then return false else h:close(); return true end end + _.killEmAll = function(all) for i,l in ipairs(all) do local c = 0 @@ -91,6 +92,7 @@ _.readCmd = function(cmd) return result end + __ = function(c) local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c, isScript = false, script = ''} local n = 0 @@ -130,15 +132,6 @@ __ = function(c) exe.cmd = exe.cmd .. ' } ' if 1 == n then exe.cmd = c end - function exe:log() - self.logging = true - return self - end - - function exe:show() - self.showing = true - return self - end function exe:Nice(c) if nil == c then @@ -160,38 +153,15 @@ __ = function(c) return self end - function exe:also(c) -- Should be called "then" but that's a reserved word. - if nil == c then c = '' else c = ' ' .. c end - self.cmd = self.cmd .. '; ' .. c .. ' ' - return self - end - - function exe:And(c) - if nil == c then c = '' else c = ' ' .. c end - self.cmd = self.cmd .. ' && ' .. c .. ' ' - return self - end - - function exe:Or(c) - if nil == c then c = '' end - self.cmd = self.cmd .. ' || ' .. c .. ' ' - return self - end - - function exe:noErr() - self.cmd = self.cmd .. ' 2>/dev/null ' - return self - end - - function exe:noOut() - self.cmd = self.cmd .. ' 1>/dev/null ' - return self - end - - function exe:wait(w) - self.cmd = self.cmd .. ' && touch ' .. w .. ' ' - return self - end + function exe:log() self.logging = true return self end + function exe:show() self.showing = true return self end + -- Should be called "then" but that's a reserved word. + function exe:also(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. '; ' .. c .. ' ' return self end + function exe:And(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' && ' .. c .. ' ' return self end + function exe:Or(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' || ' .. c .. ' ' return self end + function exe:noErr() self.cmd = self.cmd .. ' 2>/dev/null ' return self end + function exe:noOut() self.cmd = self.cmd .. ' 1>/dev/null ' return self end + function exe:wait(w) self.cmd = self.cmd .. ' && touch ' .. w .. ' ' return self end function exe:Do() --[[ "The condition expression of a control structure can return any @@ -207,17 +177,16 @@ __ = function(c) local ok, rslt, status = os.execute(s) ]] self.lines = _.readCmd(self.cmd .. '; echo "$?"', 'r') - -- The last line will be the command's returned status, collect everything else in lines. + -- The last line will be the command's returned status, fish that out and collect everything else in lines. self.status = tonumber(self.lines[#self.lines]) self.lines[#self.lines] = nil - if true == self.showing then for i, l in ipairs(self.lines) do D(l) end end - if (137 == self.status) or (124 == self.status) then - T("timeout killed " .. self.status .. ' ' .. self.command) - elseif (nil == self.status) then - D("STATUS |" .. "NIL" .. '| ' .. self.command) - elseif (0 ~= self.status) then - D("STATUS |" .. self.status .. '| ' .. self.command) + if true == self.showing then for i, l in ipairs(self.lines) do I(l) end end + + if (nil == self.status) then D("STATUS |" .. "NIL" .. '| ' .. self.command) + elseif (137 == self.status) or (124 == self.status) then T("timeout killed " .. self.status .. ' ' .. self.command) + elseif (0 ~= self.status) then D("STATUS |" .. self.status .. '| ' .. self.command) end + return self end diff --git a/aataaj.lua b/aataaj.lua index e7bb492..06077c2 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -17,7 +17,6 @@ local _ = require '_' - local Help = [[ This is part of the AllAudioToALSAandJACK project, aataaj for short, pronounced like "attach". @@ -149,64 +148,6 @@ _.parseArgs(options, args) - - - ---[=[ -local args = {...} -if 0 ~= #args then --- for i,a in pairs(args) do --- print('Argument ' .. i .. ' = ' .. a) --- end - - if 'start' == args[1] then - elseif 'stop' == args[1] then - elseif 'STOP' == args[1] then - _.killEmAll{'qsynth'} - __[[ - a2j_control --stop - sleep 2 - a2j_control --exit - sleep 2 -]]:Do() - _.killEmAll{'alsa_in', 'alsa_out', 'zita-a2j', 'zita-j2a', 'aseqjoy', 'jack-plumbing'} - __[[ - sleep 2 - jack_control stop - sleep 2 - jack_control exit - sleep 2 -]]:Do() - _.killEmAll{'jmcore', 'qjackctl'} - -- Catia is python, and no easy way to kill it. - -- Also it keeps jackdbus alive, no matter how hard you kill it. - __"pkill -TERM -u $USER -f catia":Do() - __"sleep 2":Do() - _.killEmAll{'jackdbus', 'a2jmidid'} - return(0) - elseif 'JACK' == args[1] then - elseif 'restart' == args[1] then args[1] = 'start' - elseif 'force-reload' == args[1] then args[1] = 'start' - elseif 'status' == args[1] then - return(0) - elseif 'help' == args[1] then - print(Help) - return(0) - elseif '--help' == args[1] then - print(Help) - return(0) - else - print("Usage: aataaj.lua {start|stop|restart|force-reload|status|JACK|STOP}") - return(1) - end -else - print("Usage: aataaj.lua {help|start|stop|restart|force-reload|status|JACK|STOP}") - return(1) -end -]=] - - - -- CHANGE these to suit. local asoundrcPath = '/var/lib/aataaj' local asoundrc = 'asoundrc' diff --git a/test_.lua b/test_.lua index 497b896..e559238 100755 --- a/test_.lua +++ b/test_.lua @@ -13,27 +13,13 @@ This is part of the blah blah blah... local options = { - start = - { - help = 'Command to start the scanning process, for Sys V init.', - }, + start = {help = 'Command to start the scanning process, for Sys V init.',}, restart = {start}, ['force-reload'] = {start}, - status = - { - help = 'Command to check the status of the scanning process, for Sys V init.', - }, - stop = - { - help = 'Command to stop the scanning process, for Sys V init.', - }, - JACK = - { - help = 'Command to start the JACK stuff, for users.', - }, - STOP = - { - help = 'Command to stop the JACK stuff, for users.', + status = {help = 'Command to check the status of the scanning process, for Sys V init.',}, + stop = {help = 'Command to stop the scanning process, for Sys V init.',}, + JACK = {help = 'Command to start the JACK stuff, for users.',}, + STOP = {help = 'Command to stop the JACK stuff, for users.', func = function(a, args, i) --[=[ _.killEmAll{'qsynth'} @@ -60,9 +46,7 @@ local options = ]=] end }, - help = - { - help = 'Print help.', + help = {help = 'Print help.', func = function(a, args, i) print(Help) os.exit(0) @@ -96,17 +80,15 @@ for i,l in ipairs(__'free -h':log():Do().lines) do end print('') -__'uname -a':log():also'free -h':show():Do() -print('') - for i,l in ipairs(__'uname -a\nfree -h':log():Do().lines) do print(l) end print('') -for i,l in ipairs(__{'uname -a', 'free -h'}:log():Do().lines) do - print(l) -end +__'uname -a':log():also'free -h':show():Do() +print('') + +__{'uname -a', 'free -h'}:log():show():Do() print('') -- cgit v1.1