mirror of https://github.com/kepler155c/opus
package manager updates
This commit is contained in:
parent
b761b3429a
commit
4387264960
|
@ -1,18 +1,16 @@
|
||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local Ansi = require('ansi')
|
local Ansi = require('ansi')
|
||||||
local Packages = require('packages')
|
local Packages = require('packages')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local shell = _ENV.shell
|
|
||||||
local term = _G.term
|
local term = _G.term
|
||||||
|
|
||||||
UI:configure('PackageManager', ...)
|
UI:configure('PackageManager', ...)
|
||||||
|
|
||||||
local page = UI.Page {
|
local page = UI.Page {
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 2, ey = 7, x = 2, ex = -6,
|
y = 2, ey = 7, x = 2, ex = -12,
|
||||||
values = { },
|
values = { },
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = 'Package', key = 'name' },
|
{ heading = 'Package', key = 'name' },
|
||||||
|
@ -22,14 +20,14 @@ local page = UI.Page {
|
||||||
help = 'Select a package',
|
help = 'Select a package',
|
||||||
},
|
},
|
||||||
add = UI.Button {
|
add = UI.Button {
|
||||||
x = -4, y = 4,
|
x = -10, y = 4,
|
||||||
text = '+',
|
text = 'Install',
|
||||||
event = 'action',
|
event = 'action',
|
||||||
help = 'Install or update',
|
help = 'Install or update',
|
||||||
},
|
},
|
||||||
remove = UI.Button {
|
remove = UI.Button {
|
||||||
x = -4, y = 6,
|
x = -10, y = 6,
|
||||||
text = '-',
|
text = 'Remove ',
|
||||||
event = 'action',
|
event = 'action',
|
||||||
operation = 'uninstall',
|
operation = 'uninstall',
|
||||||
operationText = 'Remove',
|
operationText = 'Remove',
|
||||||
|
@ -46,8 +44,8 @@ local page = UI.Page {
|
||||||
event = 'hide-action',
|
event = 'hide-action',
|
||||||
},
|
},
|
||||||
button = UI.Button {
|
button = UI.Button {
|
||||||
ex = -4, y = 4, width = 7,
|
x = -10, y = 4,
|
||||||
text = 'Begin', event = 'begin',
|
text = ' Begin ', event = 'begin',
|
||||||
},
|
},
|
||||||
output = UI.Embedded {
|
output = UI.Embedded {
|
||||||
y = 6, ey = -2, x = 2, ex = -2,
|
y = 6, ey = -2, x = 2, ex = -2,
|
||||||
|
@ -75,16 +73,15 @@ function page:run(operation, name)
|
||||||
local oterm = term.redirect(self.action.output.win)
|
local oterm = term.redirect(self.action.output.win)
|
||||||
self.action.output:clear()
|
self.action.output:clear()
|
||||||
local cmd = string.format('package %s %s', operation, name)
|
local cmd = string.format('package %s %s', operation, name)
|
||||||
--for _ = 1, 3 do
|
|
||||||
-- print(cmd .. '\n')
|
|
||||||
-- os.sleep(1)
|
|
||||||
--end
|
|
||||||
term.setCursorPos(1, 1)
|
term.setCursorPos(1, 1)
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setTextColor(colors.yellow)
|
term.setTextColor(colors.yellow)
|
||||||
print(cmd .. '\n')
|
print(cmd .. '\n')
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
shell.run(cmd)
|
local s, m = Util.run(_ENV, '/sys/apps/package.lua', operation, name)
|
||||||
|
if not s and m then
|
||||||
|
_G.printError(m)
|
||||||
|
end
|
||||||
term.redirect(oterm)
|
term.redirect(oterm)
|
||||||
self.action.output:draw()
|
self.action.output:draw()
|
||||||
end
|
end
|
||||||
|
@ -92,6 +89,10 @@ end
|
||||||
function page:updateSelection(selected)
|
function page:updateSelection(selected)
|
||||||
self.add.operation = selected.installed and 'update' or 'install'
|
self.add.operation = selected.installed and 'update' or 'install'
|
||||||
self.add.operationText = selected.installed and 'Update' or 'Install'
|
self.add.operationText = selected.installed and 'Update' or 'Install'
|
||||||
|
self.add.text = selected.installed and 'Update' or 'Install'
|
||||||
|
self.remove.inactive = not selected.installed
|
||||||
|
self.add:draw()
|
||||||
|
self.remove:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
|
@ -113,7 +114,7 @@ function page:eventHandler(event)
|
||||||
self.operation = event.button.operation
|
self.operation = event.button.operation
|
||||||
self.action.button.text = event.button.operationText
|
self.action.button.text = event.button.operationText
|
||||||
self.action.titleBar.title = selected.manifest.title
|
self.action.titleBar.title = selected.manifest.title
|
||||||
self.action.button.text = 'Begin'
|
self.action.button.text = ' Begin '
|
||||||
self.action.button.event = 'begin'
|
self.action.button.event = 'begin'
|
||||||
self.action:show()
|
self.action:show()
|
||||||
end
|
end
|
||||||
|
@ -127,7 +128,7 @@ function page:eventHandler(event)
|
||||||
selected.installed = Packages:isInstalled(selected.name)
|
selected.installed = Packages:isInstalled(selected.name)
|
||||||
|
|
||||||
self:updateSelection(selected)
|
self:updateSelection(selected)
|
||||||
self.action.button.text = 'Done'
|
self.action.button.text = ' Done '
|
||||||
self.action.button.event = 'hide-action'
|
self.action.button.event = 'hide-action'
|
||||||
self.action.button:draw()
|
self.action.button:draw()
|
||||||
|
|
||||||
|
@ -153,6 +154,11 @@ for k in pairs(Packages:list()) do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
page.grid:update()
|
page.grid:update()
|
||||||
|
page.grid:emit({
|
||||||
|
type = 'grid_focus_row',
|
||||||
|
selected = page.grid:getSelected(),
|
||||||
|
element = page.grid,
|
||||||
|
})
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local Git = require('git')
|
local Git = require('git')
|
||||||
local Packages = require('packages')
|
local Packages = require('packages')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
@ -36,8 +34,21 @@ local function progress(max)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function install(name)
|
local function install(name, isUpdate)
|
||||||
local manifest = Packages:getManifest(name) or error('Invalid package')
|
local manifest = Packages:getManifest(name) or error('Invalid package')
|
||||||
|
|
||||||
|
if manifest.required then
|
||||||
|
for _, v in pairs(manifest.required) do
|
||||||
|
if isUpdate or not Packages:isInstalled(v) then
|
||||||
|
install(v, isUpdate)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print(string.format('%s: %s',
|
||||||
|
isUpdate and 'Updating' or 'Installing',
|
||||||
|
name))
|
||||||
|
|
||||||
local packageDir = fs.combine('packages', name)
|
local packageDir = fs.combine('packages', name)
|
||||||
local method = args[2] or 'local'
|
local method = args[2] or 'local'
|
||||||
if method == 'remote' then
|
if method == 'remote' then
|
||||||
|
@ -69,7 +80,8 @@ if action == 'install' then
|
||||||
error('Package is already installed')
|
error('Package is already installed')
|
||||||
end
|
end
|
||||||
install(name)
|
install(name)
|
||||||
print('installation complete')
|
print('installation complete\n')
|
||||||
|
_G.printError('Reboot is required')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,7 +90,7 @@ if action == 'update' then
|
||||||
if not Packages:isInstalled(name) then
|
if not Packages:isInstalled(name) then
|
||||||
error('Package is not installed')
|
error('Package is not installed')
|
||||||
end
|
end
|
||||||
install(name)
|
install(name, true)
|
||||||
print('update complete')
|
print('update complete')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue