diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2014-03-10 12:41:07 +0000 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2014-03-11 13:54:00 +0000 |
commit | 1b141c8359c690756b0f9612fd6ccfc7ca5e9f99 (patch) | |
tree | f243d8b2649353466be3a82c3ee38c551f387c58 | |
parent | 2a078069dcfd01c7bf573d53340c8264c3dc4263 (diff) | |
download | gitano-1b141c8359c690756b0f9612fd6ccfc7ca5e9f99.tar.gz |
Plugin support in Gitano
This patch adds support for Gitano to load plugins from a colon separated set
of paths. While colon separation is not the best mechanism, it is in common
use. We explicitly do not add any escaping rules such as :: -> : in order to
remain compatible with things like PATH processing.
Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | lib/gitano.lua | 4 | ||||
-rw-r--r-- | lib/gitano/plugins.lua | 63 |
3 files changed, 67 insertions, 2 deletions
@@ -43,7 +43,7 @@ MODS := gitano \ gitano.actions gitano.config gitano.lace gitano.log \ gitano.markdown gitano.repository gitano.supple \ gitano.command gitano.admincommand gitano.usercommand \ - gitano.repocommand gitano.copycommand gitano.auth + gitano.repocommand gitano.copycommand gitano.auth gitano.plugins SKEL_FILES := gitano-admin/rules/selfchecks.lace \ gitano-admin/rules/aschecks.lace \ diff --git a/lib/gitano.lua b/lib/gitano.lua index b57bd71..31e62d5 100644 --- a/lib/gitano.lua +++ b/lib/gitano.lua @@ -15,6 +15,7 @@ local lace = require 'gitano.lace' local markdown = require 'gitano.markdown' local supple = require 'gitano.supple' local auth = require 'gitano.auth' +local plugins = require 'gitano.plugins' return { util = util, @@ -26,5 +27,6 @@ return { lace = lace, markdown = markdown, supple = supple, - auth = auth + auth = auth, + plugins = plugins, } diff --git a/lib/gitano/plugins.lua b/lib/gitano/plugins.lua new file mode 100644 index 0000000..bdc6d1e --- /dev/null +++ b/lib/gitano/plugins.lua @@ -0,0 +1,63 @@ +-- gitano.plugins +-- +-- Plugin loading support for Gitano +-- +-- Copyright 2014 Daniel Silverstone <daniel.silverstone@codethink.co.uk> + +local util = require "gitano.util" +local log = require "gitano.log" + +local luxio = require "luxio" +local sio = require "luxio.simple" + +local gfind = string.gfind + +local plugin_name_pattern = "^(.+)%.lua$" + +local function find_plugins(path) + local ret = {} + for _, entry in ipairs(path) do + local dirp, err = sio.opendir(entry) + if not dirp then + log.warning(("Unable to scan plugin directory '%s': %s") + :format(entry, err)) + else + for filename, fileinfo in dirp:iterate() do + local plugin_name = filename:match(plugin_name_pattern) + if plugin_name and fileinfo.d_type == luxio.DT_REG then + if not ret[plugin_name] then + ret[plugin_name] = entry + ret[#ret + 1] = plugin_name + end + end + end + end + end + table.sort(ret) + return ret +end + +local function load_plugins(path) + local to_load = find_plugins(path) + for _, plugin_name in ipairs(to_load) do + local filepath = util.path_join(to_load[plugin_name], + plugin_name .. ".lua") + local chunk, err = loadfile(filepath) + if not chunk then + log.warning(("Failure loading plugin '%s' from '%s': %s") + :format(plugin_name, to_load[plugin_name], + err)) + else + local ok, err = pcall(chunk) + if not ok then + log.warning(("Failure running plugin '%s' from '%s': %s") + :format(plugin_name, to_load[plugin_name], + err)) + end + end + end +end + +return { + load_plugins = load_plugins, +} |