mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Grab v2.4.7.3-alpha
This commit is contained in:
parent
9c2d59b081
commit
bf2a5232da
56
grab.lua
56
grab.lua
|
@ -9,7 +9,7 @@ local event=require('event')
|
||||||
local term=require('term')
|
local term=require('term')
|
||||||
local args,options=shell.parse(...)
|
local args,options=shell.parse(...)
|
||||||
|
|
||||||
local grab_version="Grab v2.4.6.4-alpha"
|
local grab_version="Grab v2.4.7.3-alpha"
|
||||||
local grab_version_info={
|
local grab_version_info={
|
||||||
version=grab_version
|
version=grab_version
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,11 @@ Notice:
|
||||||
The first returned value is true if content is downloaded successfully. Thus, the second value will be the downloaded content.
|
The first returned value is true if content is downloaded successfully. Thus, the second value will be the downloaded content.
|
||||||
If the first value is false, the downloading is failed. The second value will then be the error message.
|
If the first value is false, the downloading is failed. The second value will then be the error message.
|
||||||
If proxy functions throw an error, Grab will try the default downloader.
|
If proxy functions throw an error, Grab will try the default downloader.
|
||||||
|
Installer
|
||||||
|
A package can provide an installer for Grab. It will be loaded and executed after the package is ready.
|
||||||
|
Thus require(...) calls on depended libraries is ok.
|
||||||
|
From Grab v2.4.6, installer should return a function, which will be later called with a table filled with some information. (Currently, it contains version tag of Grab.)
|
||||||
|
If nothing is returned, Grab will give an warning and ignore it.
|
||||||
]===]
|
]===]
|
||||||
|
|
||||||
-- Install man document
|
-- Install man document
|
||||||
|
@ -905,7 +910,7 @@ if(args[1]=="install") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local f=io.open(fname,"wb") -- 'w' or 'wb' ?
|
local f=io.open(fname,"wb")
|
||||||
if(not f) then
|
if(not f) then
|
||||||
print("[Error] Failed to open file " .. fname .. " for writing.")
|
print("[Error] Failed to open file " .. fname .. " for writing.")
|
||||||
return
|
return
|
||||||
|
@ -923,7 +928,7 @@ if(args[1]=="install") then
|
||||||
for idx,this_name in ipairs(v) do
|
for idx,this_name in ipairs(v) do
|
||||||
local ok,fname=try_resolve_path(toDownload,this_name)
|
local ok,fname=try_resolve_path(toDownload,this_name)
|
||||||
if(ok) then
|
if(ok) then
|
||||||
local f=io.open(fname,"w") -- 'w' or 'wb' ?
|
local f=io.open(fname,"wb")
|
||||||
if(f) then
|
if(f) then
|
||||||
local ok,err=f:write(result)
|
local ok,err=f:write(result)
|
||||||
f:close()
|
f:close()
|
||||||
|
@ -960,16 +965,33 @@ if(args[1]=="install") then
|
||||||
)
|
)
|
||||||
if(not options["skip-install"]) then
|
if(not options["skip-install"]) then
|
||||||
print("Installing...")
|
print("Installing...")
|
||||||
for this_lib,this_value in pairs(to_install) do
|
local has_installed={}
|
||||||
local this_installer
|
local recursion_detect={}
|
||||||
if(type(this_value)=="string") then
|
local do_install_dfs=function(this_lib)
|
||||||
this_installer=this_value
|
if(recursion_detect[this_lib] or has_installed[this_lib]) then
|
||||||
elseif(db[this_lib].installer) then
|
return true
|
||||||
this_installer=db[this_lib].installer
|
end
|
||||||
|
recursion_detect[this_lib]=true
|
||||||
|
|
||||||
|
if(db[this_lib].requires) then
|
||||||
|
for req_lib in ipairs(db[this_lib].requires) do
|
||||||
|
if(not do_install_dfs(req_lib)) then -- Deeper Failure
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if(this_installer) then
|
local this_installer
|
||||||
local done=false
|
if(type(to_install[this_lib])=="string") then
|
||||||
|
this_installer=to_install[this_lib]
|
||||||
|
elseif(db[this_lib].installer) then
|
||||||
|
this_installer=db[this_lib].installer
|
||||||
|
else
|
||||||
|
-- No Installer: Mark as installed.
|
||||||
|
has_installed[this_lib]=true
|
||||||
|
recursion_detect[this_lib]=nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
print("Running installer for " .. this_lib .. "...")
|
print("Running installer for " .. this_lib .. "...")
|
||||||
local fn,err=loadfile(this_installer)
|
local fn,err=loadfile(this_installer)
|
||||||
|
@ -983,6 +1005,7 @@ if(args[1]=="install") then
|
||||||
if(not pcall(xerr,grab_version_info)) then
|
if(not pcall(xerr,grab_version_info)) then
|
||||||
print("[Installer Error]: " .. xerr)
|
print("[Installer Error]: " .. xerr)
|
||||||
else
|
else
|
||||||
|
has_installed[this_lib]=true
|
||||||
done=true
|
done=true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -991,15 +1014,20 @@ if(args[1]=="install") then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if(type(this_value)=="string") then
|
if(type(this_value)=="string") then -- This might be skipped?
|
||||||
filesystem.remove(this_installer)
|
filesystem.remove(this_installer)
|
||||||
end
|
end
|
||||||
|
|
||||||
if(not done) then -- Failed to install.
|
recursion_detect[this_lib]=nil
|
||||||
|
return done
|
||||||
|
end -- end of local function do_install_dfs(...)
|
||||||
|
|
||||||
|
for this_lib in pairs(to_install) do
|
||||||
|
if(not do_install_dfs(this_lib)) then
|
||||||
|
print("Failed to install some library. Installation aborted.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
print("Installation is skipped.")
|
print("Installation is skipped.")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user