opus/sys/modules/opus/packages.lua

97 lines
2.0 KiB
Lua
Raw Normal View History

local Util = require('opus.util')
2018-10-21 00:35:48 +00:00
2018-11-21 17:10:20 +00:00
local fs = _G.fs
2018-11-03 22:13:41 +00:00
local textutils = _G.textutils
2018-10-21 00:35:48 +00:00
local PACKAGE_DIR = 'packages'
local Packages = { }
function Packages:installed()
2019-01-18 04:33:19 +00:00
local list = { }
2018-10-21 00:35:48 +00:00
if fs.exists(PACKAGE_DIR) then
for _, dir in pairs(fs.list(PACKAGE_DIR)) do
local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package')
2019-01-18 04:33:19 +00:00
list[dir] = Util.readTable(path)
2018-10-21 00:35:48 +00:00
end
end
2019-01-18 04:33:19 +00:00
return list
2018-10-21 00:35:48 +00:00
end
2019-10-31 04:49:30 +00:00
function Packages:installedSorted()
local list = { }
for k, v in pairs(self.installed()) do
v.name = k
v.deps = { }
table.insert(list, v)
for _, v2 in pairs(v.required or { }) do
v.deps[v2] = true
end
end
table.sort(list, function(a, b)
return not not (b.deps and b.deps[a.name])
end)
table.sort(list, function(a, b)
return not (a.deps and a.deps[b.name])
end)
return list
end
2018-10-21 00:35:48 +00:00
function Packages:list()
2019-07-03 14:44:30 +00:00
if not fs.exists('usr/config/packages') then
self:downloadList()
end
2019-01-18 04:33:19 +00:00
return Util.readTable('usr/config/packages') or { }
2018-10-21 00:35:48 +00:00
end
function Packages:isInstalled(package)
return self:installed()[package]
end
2019-01-09 11:59:19 +00:00
function Packages:downloadList()
local packages = {
2019-07-07 05:14:39 +00:00
[ 'develop-1.8' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/packages.list',
[ 'master-1.8' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/master-1.8/packages.list',
2019-01-09 11:59:19 +00:00
}
if packages[_G.OPUS_BRANCH] then
Util.download(packages[_G.OPUS_BRANCH], 'usr/config/packages')
end
end
function Packages:downloadManifest(package)
2018-11-03 22:13:41 +00:00
local list = self:list()
local url = list and list[package]
if url then
2018-11-21 17:10:20 +00:00
local c = Util.httpGet(url)
2018-11-03 22:13:41 +00:00
if c then
2018-11-21 17:10:20 +00:00
c = textutils.unserialize(c)
if c then
c.repository = c.repository:gsub('{{OPUS_BRANCH}}', _G.OPUS_BRANCH)
return c
end
2018-11-03 22:13:41 +00:00
end
end
end
function Packages:getManifest(package)
local fname = 'packages/' .. package .. '/.package'
if fs.exists(fname) then
local c = Util.readTable(fname)
if c and c.repository then
c.repository = c.repository:gsub('{{OPUS_BRANCH}}', _G.OPUS_BRANCH)
return c
end
end
return self:downloadManifest(package)
end
2018-10-21 00:35:48 +00:00
return Packages