aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apt-panopticommon.lua
diff options
context:
space:
mode:
authoronefang2019-12-28 22:45:36 +1000
committeronefang2019-12-28 22:45:36 +1000
commitcafd4c5d4ae2de4266026d44f9340fa3de2f2b40 (patch)
tree85d972bac4592596b38b7d63e94e557cf954fce1 /apt-panopticommon.lua
parentTweak the dumpTable() arguments a little. (diff)
downloadapt-panopticon-cafd4c5d4ae2de4266026d44f9340fa3de2f2b40.zip
apt-panopticon-cafd4c5d4ae2de4266026d44f9340fa3de2f2b40.tar.gz
apt-panopticon-cafd4c5d4ae2de4266026d44f9340fa3de2f2b40.tar.bz2
apt-panopticon-cafd4c5d4ae2de4266026d44f9340fa3de2f2b40.tar.xz
Finish the executable refactor, by using it and removing the original.
Diffstat (limited to 'apt-panopticommon.lua')
-rw-r--r--apt-panopticommon.lua54
1 files changed, 20 insertions, 34 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index 53bd674..d9293f6 100644
--- a/apt-panopticommon.lua
+++ b/apt-panopticommon.lua
@@ -424,43 +424,24 @@ APT.testing = function(t, host)
424 return false 424 return false
425end 425end
426 426
427APT.execute = function (s, logit)
428 if nil == logit then logit = true end
429 if logit then D(" executing - &nbsp; <code>" .. s .. "</code>") end
430 --[[ Damn os.execute()
431 Lua 5.1 says it returns "a status code, which is system-dependent"
432 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
433 I'm getting 7168 or 0. No idea what the fuck that is.
434 local ok, rslt, status = os.execute(s)
435 ]]
436 local f = io.popen(s .. ' ; echo "$?"', 'r')
437 local status = ""
438 local result = ""
439 -- The last line will be the command's returned status, collect everything else in result.
440 for l in f:lines() do
441 result = result .. status .. "\n"
442 status = l
443 end
444 return status, result
445end
446
447APT.fork = function(s)
448 D(" forking - &nbsp; <code>" .. s .. "</code>")
449 os.execute(s .. " &")
450end
451
452
453APT.exe = function(c) 427APT.exe = function(c)
454 local exe = {status = 0, result = ''} 428 local exe = {status = 0, result = '', log = true, cmd = c .. ' '}
455 exe.cmd = c .. ' '
456 exe.log = false
457 429
458 function exe:log() 430 function exe:log()
459 self.log = true 431 self.log = true
460 return self 432 return self
461 end 433 end
462 function exe:Nice(c) 434 function exe:Nice(c)
463 self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' ' 435 if nil == c then
436 self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd
437 else
438 self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' '
439 end
440 return self
441 end
442 function exe:also(c)
443 if nil == c then c = '' else c = ' ' .. c end
444 self.cmd = self.cmd .. ';' .. c .. ' '
464 return self 445 return self
465 end 446 end
466 function exe:And(c) 447 function exe:And(c)
@@ -482,7 +463,12 @@ APT.exe = function(c)
482 return self 463 return self
483 end 464 end
484 function exe:Do() 465 function exe:Do()
485 if self.log then D(" executing - &nbsp; <code>" .. self.cmd .. "</code>") end 466 --[[ "The condition expression of a control structure can return any
467 value. Both false and nil are considered false. All values different
468 from nil and false are considered true (in particular, the number 0
469 and the empty string are also true)."
470 says the docs, I beg to differ.]]
471 if true == self.log then D(" executing - &nbsp; <code>" .. self.cmd .. "</code>") end
486 --[[ Damn os.execute() 472 --[[ Damn os.execute()
487 Lua 5.1 says it returns "a status code, which is system-dependent" 473 Lua 5.1 says it returns "a status code, which is system-dependent"
488 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code. 474 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
@@ -491,6 +477,7 @@ APT.exe = function(c)
491 ]] 477 ]]
492 local f = io.popen(self.cmd .. ' ; echo "$?"', 'r') 478 local f = io.popen(self.cmd .. ' ; echo "$?"', 'r')
493 -- The last line will be the command's returned status, collect everything else in result. 479 -- The last line will be the command's returned status, collect everything else in result.
480 self.status = '' -- Otherwise the result starts with 0.
494 for l in f:lines() do 481 for l in f:lines() do
495 self.result = self.result .. self.status .. "\n" 482 self.result = self.result .. self.status .. "\n"
496 self.status = l 483 self.status = l
@@ -500,14 +487,13 @@ APT.exe = function(c)
500 end 487 end
501 function exe:fork() 488 function exe:fork()
502 self.cmd = '{ ' .. self.cmd .. '; } &' 489 self.cmd = '{ ' .. self.cmd .. '; } &'
503 if self.log then D(" forking - &nbsp; <code>" .. self.cmd .. "</code>") end 490 if true == self.log then D(" forking - &nbsp; <code>" .. self.cmd .. "</code>") end
504 os.execute(self.cmd) 491 os.execute(self.cmd)
505 return self 492 return self
506 end 493 end
507 return exe 494 return exe
508end 495end
509 496
510
511APT.checkExes = function (exe) 497APT.checkExes = function (exe)
512 local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l") 498 local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l")
513 D(count .. " " .. exe .. " commands still running.") 499 D(count .. " " .. exe .. " commands still running.")
@@ -650,7 +636,7 @@ end
650 636
651APT.now = 0 637APT.now = 0
652local status 638local status
653status, APT.now = APT.execute('TZ="GMT" ls -l --time-style="+%s" results/stamp | cut -d " " -f 6-6') 639APT.now = APT.exe('TZ="GMT" ls -l --time-style="+%s" results/stamp | cut -d " " -f 6-6'):Do().result
654APT.now = tonumber(APT.now) 640APT.now = tonumber(APT.now)
655local start = 'now-1month' 641local start = 'now-1month'
656local step = '10min' 642local step = '10min'