From 8708e426711f6b323c79200d050a975439aed690 Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 20 Nov 2022 03:51:53 +0000 Subject: feedmaker: add metadata getter should be everything you need for a depctrl feed if i'm not mistaken. yes, this runs arbitrary code. this is, however, a non-issue, because it's *your* arbitrary code. you (hopefully) know what you wrote, and what it does. --- make-feed.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/make-feed.lua b/make-feed.lua index 328562a..a7567e6 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -44,6 +44,17 @@ local function join_tables(dst, src) return dst end +local function readfile(filename) + local f = io.open(filename) + local txt = f:read("*all") + f:close() + return txt +end + +local function get_iso8601_date(time) + return os.date("%Y-%m-%d", time) +end + local function get_files(path) local files = {} for file in lfs.dir(path) do @@ -58,9 +69,31 @@ local function get_files(path) return files end +local function get_metadata(file) + local meta = {name = nil, description = nil, version = nil, author = nil, namespace = nil, depctrl = nil, sha1 = nil, release = nil} + -- having all those nils in the table doesn't really do anything in terms of functionality, but it lets me see what i need to put in it + loadfile(file)() + -- script_name etc are now in our global scope + if config.ignoreCondition then return nil end + meta.name = script_name + meta.description = script_description + meta.version = script_version + meta.author = script_author + meta.namespace = script_namespace + meta.depctrl = __feedmaker_version + meta.sha1 = sha1.sha1(readfile(file)) + meta.release = get_iso8601_date(lfs.attributes(file, "modification")) + return meta +end + local function main() local files = get_files(args.macro_dir) print(inspect(files)) + local meta = {} + for _, file in ipairs(files) do + table.insert(meta, get_metadata(file)) + end + print(inspect(meta)) end main() -- cgit v1.2.3-70-g09d2