bliss

KISS in Lua
git clone git://bvnf.space/bliss.git
Log | Files | Refs | README | LICENSE

commit 796cb9e5909755ba1ac68e38e0215f8165b4a89c
parent e817fed042ecdeffaf6a5d655cb2d410d6e42d7e
Author: aabacchus <ben@bvnf.space>
Date:   Tue, 13 Jun 2023 18:38:11 +0100

collect pkg functions

Diffstat:
Mbliss/init.lua | 2+-
Mbliss/list.lua | 17++++-------------
Abliss/pkg.lua | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Mbliss/search.lua | 16++++------------
4 files changed, 60 insertions(+), 26 deletions(-)

diff --git a/bliss/init.lua b/bliss/init.lua @@ -3,7 +3,7 @@ local cwd = (...):gsub('%.init$', '') local M = {} -- merge these into the toplevel bliss module -local names = {'utils', 'search', 'list'} +local names = {'utils', 'search', 'list', 'pkg'} for _, name in ipairs(names) do local t = require(cwd .. '.' .. name) for k, v in pairs(t) do diff --git a/bliss/list.lua b/bliss/list.lua @@ -1,16 +1,7 @@ local utils = require 'bliss.utils' +local pkg = require 'bliss.pkg' local dirent = require 'posix.dirent' -local function pkg_version(env, pkg) - local v = env.pkg_db .. '/' .. pkg .. "/version" - local f = io.open(v, 'r') - if not f then utils.die("'"..pkg.."' not found") end - local ver = f:read() - f:close() - if not ver then utils.die(pkg, "error reading version") end - return utils.split(ver, ' ') -end - local function list(env, arg) if #arg == 0 then for file in dirent.files(env.pkg_db) do @@ -20,9 +11,9 @@ local function list(env, arg) end table.sort(arg) end - for _,pkg in ipairs(arg) do - local ver = pkg_version(env, pkg) - io.write(string.format("%s %s-%s\n", pkg, ver[1], ver[2])) + for _,a in ipairs(arg) do + local ver = pkg.find_version(a, {env.pkg_db}) + io.write(string.format("%s %s-%s\n", a, ver[1], ver[2])) end end diff --git a/bliss/pkg.lua b/bliss/pkg.lua @@ -0,0 +1,51 @@ +local utils = require 'bliss.utils' +local search = require 'bliss.search' +local sys_stat = require 'posix.sys.stat' + +local function read_lines(file) + local t = {} + local f = io.open(file) + if not f then return {} end + for line in f:lines() do + table.insert(t, utils.split(line, ' ')) + end + f:close() + return t +end + +local function find(name, path) + for _, repo in ipairs(path) do + local g = repo .. '/' .. name + local sb = sys_stat.stat(g) + if sb and sys_stat.S_ISDIR(sb.st_mode) ~= 0 then + return g + end + end + utils.die("'"..name.."' not found") +end + +local function find_version(pkg, path) + local pkgpath = find(pkg, path) + local v = pkgpath .. "/version" + + local ver = read_lines(v) + if #ver == 0 then utils.die(pkg, "error reading version") end + + return ver[1] +end + +local function find_sources(pkg, path) + local pkgpath = find(pkg, path) + local p = pkgpath .. "/sources" + + local s = read_lines(p) + if #s == 0 then utils.log(pkg, "no sources found") end + return s +end + +local M = { + find = find, + find_version = find_version, + find_sources = find_sources, +} +return M diff --git a/bliss/search.lua b/bliss/search.lua @@ -12,33 +12,25 @@ local function search(env, arg) local res = {} for _, repo in ipairs(path) do local g = glob.glob(repo .. '/' .. a, 0) + for _, i in pairs(g or {}) do local sb = sys_stat.stat(i) + if sb and sys_stat.S_ISDIR(sb.st_mode) ~= 0 then table.insert(res, i) end end end + if #res == 0 then utils.die("'"..a.."' not found") end - for _, v in ipairs(res) do print(v) end - end -end -local function pkg_find(env, name) - for _, repo in ipairs(env.PATH) do - local g = repo .. '/' .. name - local sb = sys_stat.stat(g) - if sb and sys_stat.S_ISDIR(sb.st_mode) ~= 0 then - return g - end + for _, v in ipairs(res) do print(v) end end - utils.die("'"..name.."' not found") end local M = { search = search, - pkg_find = pkg_find, } return M