mirror of
https://github.com/kepler155c/opus
synced 2025-10-18 17:27:39 +00:00
package management
This commit is contained in:
@@ -3,11 +3,15 @@ local Util = require('util')
|
||||
|
||||
local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1'
|
||||
local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s'
|
||||
|
||||
local git = { }
|
||||
|
||||
function git.list(repository)
|
||||
local os = _G.os
|
||||
|
||||
if not _G.GIT then
|
||||
_G.GIT = { }
|
||||
end
|
||||
|
||||
function git.list(repository, cache)
|
||||
local t = Util.split(repository, '(.-)/')
|
||||
|
||||
local user = t[1]
|
||||
@@ -15,6 +19,14 @@ function git.list(repository)
|
||||
local branch = t[3] or 'master'
|
||||
|
||||
local dataUrl = string.format(TREE_URL, user, repo, branch)
|
||||
if _G.GIT[dataUrl] then
|
||||
_G.GIT[dataUrl].count = _G.GIT[dataUrl].count + 1
|
||||
else
|
||||
_G.GIT[dataUrl] = {
|
||||
count = 1
|
||||
}
|
||||
end
|
||||
|
||||
local contents = Util.download(dataUrl)
|
||||
|
||||
if not contents then
|
||||
@@ -22,7 +34,7 @@ function git.list(repository)
|
||||
end
|
||||
|
||||
local data = json.decode(contents)
|
||||
|
||||
Util.writeTable('.git/' .. dataUrl, { day = os.day(), data = data })
|
||||
if data.message and data.message:find("API rate limit exceeded") then
|
||||
error("Out of API calls, try again later")
|
||||
end
|
||||
|
@@ -1,8 +1,7 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Util = require('util')
|
||||
|
||||
local fs = _G.fs
|
||||
local textutils = _G.textutils
|
||||
|
||||
local PACKAGE_DIR = 'packages'
|
||||
|
||||
@@ -22,11 +21,33 @@ function Packages:installed()
|
||||
end
|
||||
|
||||
function Packages:list()
|
||||
return Util.readTable('sys/packageList.lua') or { }
|
||||
if self.packageList then
|
||||
return self.packageList
|
||||
end
|
||||
self.packageList = Util.readTable('sys/packageList.lua') or { }
|
||||
|
||||
return self.packageList
|
||||
end
|
||||
|
||||
function Packages:isInstalled(package)
|
||||
return self:installed()[package]
|
||||
end
|
||||
|
||||
function Packages:getManifest(package)
|
||||
-- local fname = 'packages/' .. package .. '/.package'
|
||||
local fname = 'usr/milo/.package'
|
||||
if fs.exists(fname) then
|
||||
return Util.readTable(fname)
|
||||
end
|
||||
local list = self:list()
|
||||
local url = list and list[package]
|
||||
|
||||
if url then
|
||||
local c = Util.httpGet(url) -- will need to call load
|
||||
if c then
|
||||
return textutils.unserialize(c)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Packages
|
||||
|
@@ -430,7 +430,7 @@ end
|
||||
function Util.download(url, filename)
|
||||
local contents, msg = Util.httpGet(url)
|
||||
if not contents then
|
||||
error(string.format('Failed to download %s\n%s', url, msg))
|
||||
error(string.format('Failed to download %s\n%s', url, msg), 2)
|
||||
end
|
||||
|
||||
if filename then
|
||||
|
Reference in New Issue
Block a user