-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.lua
49 lines (39 loc) · 943 Bytes
/
db.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local common = require 'core.common'
local json = require 'plugins.miq.json'
local util = require 'plugins.miq.util'
local manifests = {} -- hexified keys for repo urls (excluding the tag)
local data = {
plugins = {},
repos = {} -- keys are hexified
}
local M = {}
function M.init()
if util.fileExists(USERDIR .. '/.miq-store') then
data = dofile(USERDIR .. '/.miq-store') or data
end
end
function M.write()
local f = io.open(USERDIR .. '/.miq-store', 'w+')
if not f then return end -- TODO?
f:write('return ' .. common.serialize(data))
f:close()
end
function M.addPlugin(spec)
data.plugins[spec.plugin] = spec
M.write()
end
function M.getPlugin(id)
local plug = data.plugins[id]
if plug then
return plug
end
end
function M.addRepo(repo, manifest)
if not data.repos then data.repos = {} end
data.repos[repo] = true
manifests[repo] = json.decode(manifest)
end
function M.manifests()
return manifests
end
return M