diff options
author | garret <garret@airmail.cc> | 2022-11-20 03:51:53 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2022-11-20 04:01:30 +0000 |
commit | 8708e426711f6b323c79200d050a975439aed690 (patch) | |
tree | d61b78c09a8978a31ca076984710583ef24abafe /make-feed.lua | |
parent | d8a6eab68f5c637fa618768ae452ad1c23896ff4 (diff) | |
download | depctrl-feedmaker-8708e426711f6b323c79200d050a975439aed690.tar.gz depctrl-feedmaker-8708e426711f6b323c79200d050a975439aed690.tar.bz2 depctrl-feedmaker-8708e426711f6b323c79200d050a975439aed690.zip |
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.
Diffstat (limited to 'make-feed.lua')
-rwxr-xr-x | make-feed.lua | 33 |
1 files changed, 33 insertions, 0 deletions
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() |