summaryrefslogtreecommitdiff
path: root/pm.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-08-04 00:01:30 +0100
committerubq323 <ubq323@ubq323.website>2022-08-04 00:01:30 +0100
commitcfc654d9db45eeb6efc1745f855d7eb3341644b1 (patch)
tree9d7ff9d0b621e93f404190e7f6136023a7fd1e0d /pm.lua
parent9d7302c75fdbb2f04b274fa63b912570226f7536 (diff)
pm
Diffstat (limited to 'pm.lua')
-rw-r--r--pm.lua74
1 files changed, 52 insertions, 22 deletions
diff --git a/pm.lua b/pm.lua
index 1c497b1..62cfed9 100644
--- a/pm.lua
+++ b/pm.lua
@@ -6,44 +6,74 @@ local function perr(err,what)
if err then error(what..": "..err) end
end
+local _manifests = {}
local function manifest(pkgname)
+ if _manifests[pkgname] then return _manifests[pkgname] end
print("fetching manifest of '"..pkgname.."'...")
- local res,err = http.get(rbase..pkgname..".dat")
- perr(err,"http.get")
+
local files={}
local files_present=false
local deps={}
- for line in res.readAll():gmatch"[^\n]+" do
- local op,argstart = line:match "^(%w+)%s+()"
- if op then
- local argstr = line:sub(argstart)
- local args = {}
- for arg in argstr:gmatch"[^ ]+" do
- table.insert(args,arg)
- end
-
- if op == "dep" then
- for _,arg in ipairs(args) do deps[arg]=true end
- elseif op == "file" then
- files_present = true
- for _,arg in ipairs(args) do files[arg]=true end
+
+ local res,err,err_res = http.get(rbase..pkgname..".dat")
+ if err then
+ if err_res and (err_res.getResponseCode() == 404) then
+ print("no manifest for "..pkgname.." found, using defaults")
+ else
+ error("http.get: "..err)
+ end
+ else
+ for line in res.readAll():gmatch"[^\n]+" do
+ local op,argstart = line:match "^(%w+)%s+()"
+ if op then
+ local argstr = line:sub(argstart)
+ local args = {}
+ for arg in argstr:gmatch"[^ ]+" do
+ table.insert(args,arg)
+ end
+
+ if op == "dep" then
+ for _,arg in ipairs(args) do deps[arg]=true end
+ elseif op == "file" then
+ files_present = true
+ for _,arg in ipairs(args) do files[arg]=true end
+ end
end
end
end
- if not files_present then files[pkgname]=true end
- return {files=files,deps=deps}
+
+ if not files_present then files[pkgname..".lua"]=true end
+ local man = {files=files,deps=deps}
+ _manifests[pkgname] = man
+ return man
end
+local function recursive_depsof(pkgname)
+ local lookedat = {}
+ local deps = {}
+ local function F(pkgname)
+ print("F",pkgname)
+ if not lookedat[pkgname] then
+ lookedat[pkgname] = true
+ for k,_ in pairs(manifest(pkgname).deps) do
+ deps[k] = true
+ F(k)
+ end
+ end
+ end
+ F(pkgname)
+ return deps
+end
-local function dl(filename)
- local file,err=fs.open("/"..filename..".lua","w")
+local function dlfile(filename)
+ local file,err=fs.open("/"..filename,"w")
if err then error("fs.open "..err) end
- local res,err = http.get("https://g.gh0.pw/ccprogs/plain/"..filename..".lua")
+ local res,err = http.get("https://g.gh0.pw/ccprogs/plain/"..filename)
if err then error("http.get "..err) end
file.write(res.readAll())
file.flush()
file.close()
end
-return manifest
+return {manifest=manifest,rd=recursive_depsof}
--dl(arg[1])