diff options
Diffstat (limited to 'apt-panopticommon.lua')
| -rw-r--r-- | apt-panopticommon.lua | 54 |
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 |
| 425 | end | 425 | end |
| 426 | 426 | ||
| 427 | APT.execute = function (s, logit) | ||
| 428 | if nil == logit then logit = true end | ||
| 429 | if logit then D(" executing - <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 | ||
| 445 | end | ||
| 446 | |||
| 447 | APT.fork = function(s) | ||
| 448 | D(" forking - <code>" .. s .. "</code>") | ||
| 449 | os.execute(s .. " &") | ||
| 450 | end | ||
| 451 | |||
| 452 | |||
| 453 | APT.exe = function(c) | 427 | APT.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 - <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 - <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 - <code>" .. self.cmd .. "</code>") end | 490 | if true == self.log then D(" forking - <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 |
| 508 | end | 495 | end |
| 509 | 496 | ||
| 510 | |||
| 511 | APT.checkExes = function (exe) | 497 | APT.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 | ||
| 651 | APT.now = 0 | 637 | APT.now = 0 |
| 652 | local status | 638 | local status |
| 653 | status, APT.now = APT.execute('TZ="GMT" ls -l --time-style="+%s" results/stamp | cut -d " " -f 6-6') | 639 | APT.now = APT.exe('TZ="GMT" ls -l --time-style="+%s" results/stamp | cut -d " " -f 6-6'):Do().result |
| 654 | APT.now = tonumber(APT.now) | 640 | APT.now = tonumber(APT.now) |
| 655 | local start = 'now-1month' | 641 | local start = 'now-1month' |
| 656 | local step = '10min' | 642 | local step = '10min' |
