aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apt-panopticommon.lua
diff options
context:
space:
mode:
authoronefang2019-12-28 03:49:40 +1000
committeronefang2019-12-28 03:49:40 +1000
commit74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49 (patch)
tree31ada1778f66215d31cd21e6b1267e75fdfbe924 /apt-panopticommon.lua
parentOops, forgot to uncomment code after testing. (diff)
downloadapt-panopticon-74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49.zip
apt-panopticon-74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49.tar.gz
apt-panopticon-74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49.tar.bz2
apt-panopticon-74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49.tar.xz
Refactor the executers into an actual class type thingy.
Diffstat (limited to 'apt-panopticommon.lua')
-rw-r--r--apt-panopticommon.lua59
1 files changed, 59 insertions, 0 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index c9194fa..a19f1e3 100644
--- a/apt-panopticommon.lua
+++ b/apt-panopticommon.lua
@@ -450,6 +450,65 @@ APT.fork = function(s)
450 os.execute(s .. " &") 450 os.execute(s .. " &")
451end 451end
452 452
453
454APT.exe = function(c)
455 local exe = {status = 0, result = ''}
456 exe.cmd = c .. ' '
457 exe.log = false
458
459 function exe:log()
460 self.log = true
461 return self
462 end
463 function exe:Nice(c)
464 self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' '
465 return self
466 end
467 function exe:And(c)
468 if nil == c then c = '' else c = ' ' .. c end
469 self.cmd = self.cmd .. '&&' .. c .. ' '
470 return self
471 end
472 function exe:Or(c)
473 if nil == c then c = '' end
474 self.cmd = self.cmd .. '|| ' .. c .. ' '
475 return self
476 end
477 function exe:noErr()
478 self.cmd = self.cmd .. '2>/dev/null '
479 return self
480 end
481 function exe:wait(w)
482 self.cmd = self.cmd .. '&& touch ' .. w .. ' '
483 return self
484 end
485 function exe:Do()
486 if self.log then D(" executing - &nbsp; <code>" .. self.cmd .. "</code>") end
487 --[[ Damn os.execute()
488 Lua 5.1 says it returns "a status code, which is system-dependent"
489 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
490 I'm getting 7168 or 0. No idea what the fuck that is.
491 local ok, rslt, status = os.execute(s)
492 ]]
493 local f = io.popen(self.cmd .. ' ; echo "$?"', 'r')
494 -- The last line will be the command's returned status, collect everything else in result.
495 for l in f:lines() do
496 self.result = self.result .. self.status .. "\n"
497 self.status = l
498 end
499 self.status = tonumber(self.status)
500 return self
501 end
502 function exe:fork()
503 self.cmd = '{ ' .. self.cmd .. '; } &'
504 if self.log then D(" forking - &nbsp; <code>" .. self.cmd .. "</code>") end
505 os.execute(self.cmd)
506 return self
507 end
508 return exe
509end
510
511
453APT.checkExes = function (exe) 512APT.checkExes = function (exe)
454 local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l") 513 local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l")
455 D(count .. " " .. exe .. " commands still running.") 514 D(count .. " " .. exe .. " commands still running.")