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 af8362e632553fb6d535a4c5ed88df4e2a41c651
Author: tms <nemi@skaut.cz>
Date:   Thu, 22 Oct 2020 22:48:11 +0200

init

Diffstat:
Adart_run_status.lua | 26++++++++++++++++++++++++++
Adart_run_track.lua | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adart_run_track_hook.lua | 1+
3 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/dart_run_status.lua b/dart_run_status.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua + +local status_dir = os.getenv('HOME') .. '/.cache/dart_run_track' +if not io.open(status_dir) then return '' end + +local ds = {[0] = 'ffa500', [1] = '00ff00', [-1] = 'ff0000'} + +local files = {} +local list = io.popen('ls ' .. status_dir) +for f in list:lines() do table.insert(files, f) end + +local result = {} +for _, f in pairs(files) do + local status_file = status_dir .. '/' .. f + local file = io.open(status_file, 'r') + + if not file then + table.insert(result, '') + else + local status = file:read() + table.insert(result, '%{u#' .. ds[tonumber(status)] .. '} ' .. f .. ' %{u-}') + file:close() + end +end + +print(table.concat(result, '')) diff --git a/dart_run_track.lua b/dart_run_track.lua @@ -0,0 +1,68 @@ +#!/usr/bin/env lua + +local name = arg[1] or 'dart' +local hookFile = loadfile(os.getenv('HOME') .. '/.local/src/dart_run_track/dart_run_track_hook.lua') + +-- status dir +local status_dir = os.getenv('HOME') .. '/.cache/dart_run_track' +print(status_dir) +if not io.open(status_dir) then os.execute('mkdir ' .. status_dir) end + +-- status file +local status_file = status_dir .. '/' .. name +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 + +-- [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 function updateFile(status) + file = io.open(status_file, 'w') + file:write(status) + file:close() + if hookFile then hookFile() end +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 +end diff --git a/dart_run_track_hook.lua b/dart_run_track_hook.lua @@ -0,0 +1 @@ +os.execute('polybar-msg hook dartruntrack 1')