trun

Script for parsing any output. Yes, it is all it does.
git clone git://gtms.dev/trun.git
Log | Files | Refs | README | LICENSE

commit 408ffe61c983da5aeaabbb089c03b09167856b1c
parent 68acdc6590a668a601fe47f4052297a8bb51fe4f
Author: tms <nemi@skaut.cz>
Date:   Thu, 29 Oct 2020 22:34:53 +0100

generalize code; handlers are in xdg_config_home/trun dir

Diffstat:
Mdart_run_track.lua | 66+++++++++++++++++-------------------------------------------------
1 file changed, 17 insertions(+), 49 deletions(-)

diff --git a/dart_run_track.lua b/dart_run_track.lua @@ -1,29 +1,25 @@ #!/usr/bin/env lua -local name = arg[1] or 'dart' +-- <run cmd> | run_track <handler> <name> +local handlerName = arg[1] +if not handlerName then error('No handler provided!') end +local name = arg[2] or 'trun' --- Hook defines 3 methods --- --- onStart: call once before start reading --- onUpdate: calls every time when stdin reads a line --- onEnd: calls once after stream end -local hook = require 'dart_run_track_hook' +local handlerPath = os.getenv('XDG_CONFIG_HOME') .. '/trun/?.lua' +package.path = package.path .. ';' .. handlerPath +local handler = require(handlerName) -- status dir -local status_dir = os.getenv('HOME') .. '/.cache/dart_run_track' +local status_dir = os.getenv('HOME') .. '/.cache/trun' if not io.open(status_dir) then os.execute('mkdir ' .. status_dir) end -- status file -local status_file = status_dir .. '/' .. name +local status_file = status_dir .. '/' .. name .. '.' .. handlerName local file = io.open(status_file, 'w') if not file then os.execute('touch ' .. status_file) file = io.open(status_file, 'w') end -io.output(file) - -local ds = {['running'] = 0, ['success'] = 1, ['severe'] = -1} -local status ----------------------------------------------------------------------------------------------------------------------- -- handling signals @@ -32,62 +28,34 @@ local signal = require 'posix.signal' local function cleanup() os.execute('rm ' .. status_file) - if hook.onEnd then hook.onEnd() end + if handler.onEnd then handler.onEnd() end end signal.signal(signal.SIGINT, function(signum) cleanup() os.exit(signum) end) ------------------------------------------------------------------------------------------------------------------------ - --- [INFO] Succeeded after 29.8s with 304 outputs (8 actions) -local function isSucceed(line) - return string.match(line, '%[INFO%] Succeeded') -end --- [SEVERE] build_web_compilers:entrypoint on web/main.dart: --- Dart2Js finished with: --- --- packages/dpgw_ui/src/commons/ui/hp/matcher/hp_matcher.dart:20:2: --- Error: Type 'vid' not found. --- vid update() { --- ^^^ --- Error: Compilation failed. --- ... --- [SEVERE] Failed after 11.4s --- local function error(line) --- end +----------------------------------------------------------------------------------------------------------------------- -local function getStatus(line, lineType) - if (lineType == 'SEVERE') then - return ds.severe - elseif lineType == 'INFO' then - if (isSucceed(line)) then return ds.success end - end - return ds.running -end +local status local function updateFile(status) file = io.open(status_file, 'w') file:write(status) file:close() - if hook.onUpdate then hook.onUpdate() end + if handler.onUpdate then handler.onUpdate() end end -if hook.onStart then hook.onStart() end +if handler.onStart then handler.onStart() end local lastStatus -local lineType for line in io.lines() do print(line) - lineType = line:match('^%[(.*)%]'); - if lineType then - lastStatus = status - status = getStatus(line, lineType) - if status ~= lastStatus then updateFile(status) end - end + lastStatus = status + status = handler.handle(line) + if status and status ~= lastStatus then updateFile(status) end end -- cleanup