From d0c90692ab3438b332f6da1e485617f9de9a7412 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Tue, 22 Oct 2024 17:03:41 +1000 Subject: Rearrange those logging globals and a few other things in _. --- .aataaj_JACK.lua | 7 ------ _.lua | 77 +++++++++++++++++++++++++------------------------------- aataaj.lua | 7 ------ test_.lua | 15 +++++------ 4 files changed, 40 insertions(+), 66 deletions(-) diff --git a/.aataaj_JACK.lua b/.aataaj_JACK.lua index 91888d2..d659d50 100755 --- a/.aataaj_JACK.lua +++ b/.aataaj_JACK.lua @@ -3,12 +3,5 @@ -- An example users .aataaj_JACK.lua script that just starts qsynth. local _ = require '_' -local D = _.D -local I = _.I -local T = _.T -local W = _.W -local E = _.E -local C = _.C -local __ = _._ if _.runnable'qsynth' then __'qsynth':forkOnce() end diff --git a/_.lua b/_.lua index 42c3b4a..19b73b4 100755 --- a/_.lua +++ b/_.lua @@ -3,21 +3,41 @@ -- Most of this _ stuff was copied from apt-panopticon. local _ = {} - _.version = '0.0 crap' -_.D = function(s) print('DEBUG ' .. s) end -_.I = function(s) print('INFO ' .. s) end -_.T = function(s) print('TIMEOUT ' .. s) end -_.W = function(s) print('WARNING ' .. s) end -_.E = function(s) print('ERROR ' .. s) end -_.C = function(s) print('CRITICAL ' .. s) end -local D = _.D -local I = _.I -local T = _.T -local W = _.W -local E = _.E -local C = _.C + +D = function(s) print('DEBUG ' .. s) end +I = function(s) print('INFO ' .. s) end +T = function(s) print('TIMEOUT ' .. s) end +W = function(s) print('WARNING ' .. s) end +E = function(s) print('ERROR ' .. s) end +C = function(s) print('CRITICAL ' .. s) end + + +_.runnable = function(c) + return ( 0 == __('which ' .. c):Do().status ) +end + +_.running = function(c) + return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) ) +end + +_.exists = function(f) + local h, e = io.open(f, "r") + 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 + while 0 ~= tonumber(__("pgrep -u $USER -xc " .. l):Do().lines[1]) do + local s = 'TERM' + if c > 1 then s = 'KILL'; __("sleep " .. c):Do() end + __("pkill -" .. s .. " -u $USER -x " .. l):log():Do() + c = c + 1 + end + end +end _.readCmd = function(cmd) @@ -33,8 +53,7 @@ _.readCmd = function(cmd) return result end - -_._ = function(c) +__ = function(c) local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c} local n = 0 @@ -165,33 +184,5 @@ _._ = function(c) return exe end -local __ = _._ - -_.runnable = function(c) - return ( 0 == __('which ' .. c):Do().status ) -end - -_.running = function(c) - return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) ) -end - -_.exists = function(f) - local h, e = io.open(f, "r") - 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 - while 0 ~= tonumber(__("pgrep -u $USER -xc " .. l):Do().lines[1]) do - local s = 'TERM' - if c > 1 then s = 'KILL'; __("sleep " .. c):Do() end - __("pkill -" .. s .. " -u $USER -x " .. l):log():Do() - c = c + 1 - end - end -end - - return _ diff --git a/aataaj.lua b/aataaj.lua index 83dd827..655c7ef 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -15,13 +15,6 @@ ]] local _ = require '_' -local D = _.D -local I = _.I -local T = _.T -local W = _.W -local E = _.E -local C = _.C -local __ = _._ diff --git a/test_.lua b/test_.lua index 629c151..c9884ea 100755 --- a/test_.lua +++ b/test_.lua @@ -2,13 +2,6 @@ local _ = require '_' -local D = _.D -local I = _.I -local T = _.T -local W = _.W -local E = _.E -local C = _.C -local __ = _._ D('Starting from the top.') @@ -114,5 +107,9 @@ print(__'exit 42':log():show():Do().status) print(__'return 42':log():show():Do().status) print(__'command NoSuchCommand':log():show():Do().status) -__'qpdfview':forkOnce() -__'qpdfview':forkOnce() +--__'qpdfview':forkOnce() +--__'qpdfview':forkOnce() + + +D('debug?') +I('info?') \ No newline at end of file -- cgit v1.1