aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/plugin_manager/init.lua18
-rw-r--r--plugins/plugin_manager/plugin_view.lua50
-rw-r--r--src/lpm.lua25
3 files changed, 64 insertions, 29 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua
index 9ed1c28..7f4e5eb 100644
--- a/plugins/plugin_manager/init.lua
+++ b/plugins/plugin_manager/init.lua
@@ -103,13 +103,13 @@ local function run(cmd, progress)
while i < #running_processes + 1 do
local v = running_processes[i]
local still_running = true
+ local progress_line
while true do
local chunk = v[1]:read_stdout(2048)
if config.plugins.plugin_manager.debug and chunk ~= nil then io.stdout:write(chunk) io.stdout:flush() end
if chunk and v[1]:running() and #chunk == 0 then break end
if chunk ~= nil and #chunk > 0 then
v[3] = v[3] .. chunk
- local progress_line
progress_line, v[3] = extract_progress(v[3])
if progress and progress_line then
progress_line = json.decode(progress_line)
@@ -119,10 +119,12 @@ local function run(cmd, progress)
else
still_running = false
if v[1]:returncode() == 0 then
+ progress_line, v[3] = extract_progress(v[3])
v[2]:resolve(v[3])
else
local err = v[1]:read_stderr(2048)
core.error("error running " .. join(" ", cmd) .. ": " .. (err or "?"))
+ progress_line, v[3] = extract_progress(v[3])
v[2]:reject(v[3])
end
break
@@ -211,7 +213,19 @@ end
function PluginManager:install(addon, options) return run_stateful_plugin_command(self, "install", { addon.id .. (addon.version and (":" .. addon.version) or "") }, options) end
function PluginManager:reinstall(addon, options) return run_stateful_plugin_command(self, "install", { addon.id .. (addon.version and (":" .. addon.version) or ""), "--reinstall" }, options) end
function PluginManager:uninstall(addon, options) return run_stateful_plugin_command(self, "uninstall", { addon.id }, options) end
-function PluginManager:unstub(addon, options) return run_stateful_plugin_command(self, "unstub", { addon.id }, options) end
+function PluginManager:unstub(addon, options)
+ local promise = Promise.new()
+ if addon.path and system.get_file_info(addon.path) then
+ promise:resolve(addon)
+ else
+ run({ "unstub", addon.id }, options.progress):done(function(result)
+ local unstubbed_addon = json.decode(result).addons[1]
+ for k,v in pairs(unstubbed_addon) do addon[k] = v end
+ promise:resolve(addon)
+ end)
+ end
+ return promise
+end
function PluginManager:get_addon(name_and_version)
diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua
index 31e3550..7b57272 100644
--- a/plugins/plugin_manager/plugin_view.lua
+++ b/plugins/plugin_manager/plugin_view.lua
@@ -204,7 +204,7 @@ end
function PluginView:install(plugin)
self.loading = true
- self.plugin_manager:install(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:install(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -212,7 +212,7 @@ end
function PluginView:uninstall(plugin)
self.loading = true
- self.plugin_manager:uninstall(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:uninstall(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -221,15 +221,14 @@ end
function PluginView:unstub(plugin)
self.loading = true
- self.plugin_manager:unstub(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:unstub(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
- self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
end
function PluginView:reinstall(plugin)
self.loading = true
- self.plugin_manager:reinstall(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:reinstall(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -328,28 +327,35 @@ command.add(function()
return core.active_view and core.active_view:is(PluginView) and plugin_view.hovered_plugin
end, {
["plugin-manager:view-source-hovered"] = function()
- local directory = plugin_view.hovered_plugin.type == "library" and "libraries" or "plugins"
- local opened = false
- for i, path in ipairs({ plugin_view.hovered_plugin.path, plugin_view.hovered_plugin.path .. PATHSEP .. "init.lua" }) do
- local stat = system.get_file_info(path)
- if stat and stat.type == "file" then
- core.root_view:open_doc(core.open_doc(path))
- opened = true
- end
- end
- if not opened then core.error("Can't find source for plugin.") end
- end,
- ["plugin-manager:view-readme-hovered"] = function()
- local directory = plugin_view.hovered_plugin.type == "library" and "libraries" or "plugins"
- local opened = false
- plugin_view.hovered_plugin:unstub(plugin_view.hovered_plugin):done(function(plugin)
- for i, path in ipairs({ plugin_view.hovered_plugin.path .. PATHSEP .. "README.md" }) do
+ plugin_view:unstub(plugin_view.hovered_plugin):done(function(plugin)
+ local opened = false
+ for i, path in ipairs({ plugin.path, plugin.path .. PATHSEP .. "init.lua" }) do
local stat = system.get_file_info(path)
if stat and stat.type == "file" then
core.root_view:open_doc(core.open_doc(path))
opened = true
end
end
+ if not opened then core.error("Can't find source for plugin.") end
+ end)
+ end,
+ ["plugin-manager:view-readme-hovered"] = function()
+ plugin_view:unstub(plugin_view.hovered_plugin):done(function(plugin)
+ local opened = false
+ local directories = { plugin.path }
+ if plugin.repo_path then
+ table.insert(directories, plugin.repo_path)
+ table.insert(directories, plugin.repo_path:gsub(PATHSEP .. "plugins" .. PATHSEP .. plugin.id .. "$", "")
+ end
+ for _, directory in ipairs(directories) do
+ for i, path in ipairs({ directory .. PATHSEP .. "README.md", directory .. PATHSEP .. "readme.md" }) do
+ local stat = system.get_file_info(path)
+ if stat and stat.type == "file" then
+ core.root_view:open_doc(core.open_doc(path))
+ opened = true
+ end
+ end
+ end
if not opened then core.error("Can't find README for plugin.") end
end)
end
@@ -372,7 +378,7 @@ keymap.add {
}
-PluginView.menu:register(nil, {
+PluginView.menu:register(function() return core.active_view:is(PluginView) end, {
{ text = "Install", command = "plugin-manager:install-hovered" },
{ text = "Uninstall", command = "plugin-manager:uninstall-hovered" },
{ text = "View Source", command = "plugin-manager:view-source-hovered" },
diff --git a/src/lpm.lua b/src/lpm.lua
index 6303354..18d34bc 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -373,6 +373,7 @@ function common.sort(t, f) table.sort(t, f) return t end
function common.write(path, contents) local f, err = io.open(path, "wb") if not f then error("can't write to " .. path .. ": " .. err) end f:write(contents) f:flush() f:close() end
function common.read(path) local f, err = io.open(path, "rb") if not f then error("can't read from " .. path .. ": " .. err) end return f:read("*all") end
function common.uniq(l) local t = {} local k = {} for i,v in ipairs(l) do if not k[v] then table.insert(t, v) k[v] = true end end return t end
+function common.delete(h, d) local t = {} for k,v in pairs(h) do if k ~= d then t[k] = v end end return t end
function common.split(splitter, str)
local o = 1
local res = {}
@@ -667,6 +668,7 @@ function Addon:unstub()
local remote_entry = common.grep(manifest['addons'] or manifest['plugins'], function(e) return e.id == self.id end)[1]
if not remote_entry then error("can't find " .. self.type .. " on " .. self.remote) end
local addon = Addon.new(repo, remote_entry)
+
-- merge in attribtues that are probably more accurate than the stub
if addon.version ~= self.version then log_warning(self.id .. " stub on " .. self.repository:url() .. " has differing version from remote (" .. self.version .. " vs " .. addon.version .. "); may lead to install being inconsistent") end
-- if addon.mod_version ~= self.mod_version then log_warning(self.id .. " stub on " .. self.repository:url() .. " has differing mod_version from remote (" .. self.mod_version .. " vs " .. addon.mod_version .. ")") end
@@ -1094,15 +1096,26 @@ function Repository:generate_manifest(repo_id)
if file:find("%.lua$") then
local filename = common.basename(file):gsub("%.lua$", "")
local name = filename
- if repo_id and name == "init" then name = repo_id end
+ if name == "init" then name = repo_id or common.basename(self.remote) end
if name ~= "init" then
local type = folder == "colors" and "color" or (folder == "libraries" and "library" or "plugin")
local addon = { description = nil, id = name:lower():gsub("[^a-z0-9%-_]", ""), name = name, mod_version = LATEST_MOD_VERSION, version = "0.1", path = (filename ~= "init" and (addon_dir .. PATHSEP .. file) or nil), type = type }
for line in io.lines(path .. PATHSEP .. addon_dir .. PATHSEP .. file) do
local _, _, mod_version = line:find("%-%-.*mod%-version:%s*(%w+)")
if mod_version then addon.mod_version = mod_version end
- local _, _, required_addon = line:find("require [\"']plugins.([%w_-]+)")
- if required_addon and not CORE_PLUGINS[required_addon] then if required_addon ~= addon.id then if not addon.dependencies then addon.dependencies = {} end addon.dependencies[required_addon] = ">=0.1" end end
+ local _, _, required_addon = line:find("require [\"']plugins%.([%w_-]+)")
+ if required_addon and not CORE_PLUGINS[required_addon] then
+ if required_addon ~= addon.id then
+ if not addon.dependencies then addon.dependencies = {} end
+ addon.dependencies[required_addon] = ">=0.1"
+ end
+ end
+ local _, _, name_override = line:find("config%.plugins%.([%w_-]+)%s*=%s*common%.merge")
+ if not repo_id and name_override then
+ addon.name = name_override
+ addon.id = name_override:lower():gsub("[^a-z0-9%-_]", "")
+ addon.dependencies = common.delete(addon.dependencies, addon.id)
+ end
end
if addon_map[addon.id] then
addon = common.merge(addon, addon_map[addon.id])
@@ -1423,7 +1436,8 @@ function Bottle:all_addons()
local_path = path,
mod_version = self.lite_xl.mod_version,
path = addon_type .. PATHSEP .. v,
- description = (hash[id] and hash[id][1].description or nil)
+ description = (hash[id] and hash[id][1].description or nil),
+ repo_path = (hash[id] and hash[id][1].local_path or nil)
}))
end
end
@@ -1788,6 +1802,7 @@ local function print_addon_info(type, addons, filters)
organization = addon.organization,
repository = addon.repository and addon.repository:url(),
path = addon:get_path(system_bottle),
+ repo_path = addon.repo_path,
url = url
}
if addon_matches_filter(hash, filters or {}) then
@@ -1955,7 +1970,7 @@ local function run_command(ARGS)
elseif (ARGS[2] == "plugin" or ARGS[2] == "color" or ARGS[2] == "library") and (#ARGS == 2 or ARGS[3] == "list") then return lpm_addon_list(ARGS[2], ARGS[4], ARGS)
elseif ARGS[2] == "upgrade" then return lpm_addon_upgrade(table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "install" then lpm_install(nil, table.unpack(common.slice(ARGS, 3)))
- elseif ARGS[2] == "unstub" then lpm_unstub(nil, table.unpack(common.slice(ARGS, 3)))
+ elseif ARGS[2] == "unstub" then return lpm_unstub(nil, table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "uninstall" then lpm_addon_uninstall(nil, table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "reinstall" then lpm_addon_reinstall(nil, table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "describe" then lpm_describe(nil, table.unpack(common.slice(ARGS, 3)))